Topic: Pluralization and Singularization in Translations

Topic type:

How do add your own singularizers and pluralizers to Kete.

To help translation, Kete has a singular and plural system. In english, most words become plurals by adding 's' to the end, and become singular by removing that 's'. However, this obviously doesn't apply for all languages. If your language has some type singular or plural distinction, you can add your own. Similarly, if your language has issues with pluralization, you can change Kete to not add or remove anything from the words.

To do all of these, simply edit config/initializers/all_extensions.rb, and adjust the PluralizeValues and SingularizeValues ruby hases.

The format is:

:locale_code => { :prefix => '', :suffix => '' }

The locale code should match the code used in the translation file (should be on the first or second line of the translation in config/locales/). The prefix adds something to the beginning of the string. The suffix adds something to the end of the string.

Leaving both the :prefix and :suffix blank turns the pluralization/singularization off. You can specify only one, or both as needed.

While English uses a more advanced pluralize built into Ruby on Rails, if it were to use the basic system Kete has, it would look like this:

PluralizeValues = {
  :en => { :suffix => 's' }  #<-   no prefix, add s for the suffix
SingularizeValues = {
  :en => {}   #<-  no prefix or suffix, which means add nothing for a singular value

Discuss This Topic

There are 2 comments in this discussion.

Read and join this discussion

join this discussion

Creative Commons Attribution-Share Alike 3.0 New Zealand License
Pluralization and Singularization in Translations by Kieran P is licensed under a Creative Commons Attribution-Share Alike 3.0 New Zealand License