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
Hi,
Right now there isn't a phrase specific way to define a pluralized version of the phrase (simply rules for the language at large), but we may be to build something that could do it in the future.
It's an interesting idea and I know that Rails has some included pluralization rule exception handling for English. If I remember correctly the way it works is that you register your exception to the pluralization or singularization rules and those take precedence to the standard rule.
We would have to do a couple things to make this work:
- add the ability to specify in the /translate interface a new plural version of an existing key (e.g. when you translate base.member, you would have an "add plural" widget available)
- the same for "add singular"
- put coding in place to look up that key into the pluralization and singularization functionality
Tags: Arabic, Pluralization, Singularization, Translations
KwareTech
said Arabic Pluralization and Singularization in Translations
Thank you Kieran for bringing this topic "Pluralization and Singularization in Translations" to the attention.
We done the change to disable Pluralization as follows: PluralizeValues = { :ar => {} }
What we wish to have now is to define two separate translations for a phrase, one for its singular form and another for
its pluralized form. This way, when we need to use the pluralized version of a phrase we use "{{t.base.member.pluralize}}
To demo this, let's say we have the "member" phrase. The following shows its two translation forms:
Key:base.member عضو
{{t.base.member.pluralize}} اعضاء |* the pluralized version of base.member key
I understand the above is not really a key, but it will be nice to have a base key for the pluralized version of a phrase if required. Anyway, withh current Arabic Kete, the use of "base.member.pluralize" key brings the singular form which is "base.member" عضو.
Is there a way to fix this, or we will have to type the total pluralized form manually every time we need it in a sentence?
Thanks, Massoud.
Tags: Arabic, Pluralization, Singularization, Translations