Translation using plural forms
Sunday, February 7, 2010 2:01:09 AM
Using the translation plugin of Yusef, and the appropriate {%trans%} and {%endtrans%} tags along with some JSON, localizing an application is a breeze.1 The only problem is with pluralisation. So if you follow the documentation, you should get something like this
This won't work unless you fix the translation thing. The first problem lies within the underscore function: when variables are fetched, they are retrieved as string. However, when testing for plural, the following line does the wrong thing:
Since the "!==" comparison is used, the test fails. Instead, we can rely on javascript conversion and use != 1
On a side note, there seem to be no support for localizing Date related strings. Even the so nice humanReadable addon of the datelibrary has no support for anything else than English.
{%trans with
"{{myData1}}" as counter and
"{{myData2}}" as other and
"{{moreData}}" as etc %}
There is {counter} foot
{%plural%}
There are {counter} feet
{%endtrans%}
This won't work unless you fix the translation thing. The first problem lies within the underscore function: when variables are fetched, they are retrieved as string. However, when testing for plural, the following line does the wrong thing:
if (variables && variables.counter && variables.counter !== 1)
{ /* plural stuffs */ }
else
{ /* singular */
Since the "!==" comparison is used, the test fails. Instead, we can rely on javascript conversion and use != 1
On a side note, there seem to be no support for localizing Date related strings. Even the so nice humanReadable addon of the datelibrary has no support for anything else than English.
- Except if many hardcoded stuffs are in your code.





