My Opera is closing 1st of March

Covert Tomato

Spending CPU cycles associating random words

Translation using plural forms

,

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
{%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. sad

  1. Except if many hardcoded stuffs are in your code.

Debugging Unite apps: take 2Yusef: new version

Write a comment

New comments have been disabled for this post.