Wednesday, February 8

i10n and Plural Forms

Have you know that some languages have more than two plural forms?
I never notice this fact and was blind to it but the creators of gettext l10n system were not.

What I thought was the general rule?

Most English speaking people are used to the fact that ordinal things are either single or plural but even in English when you count centuries you say 1st, 2nd, 3rd, 4th, 5th and so on. So even in English you sometime need to have special cases when converting pure numeric values to human readable text.

I was surprised to see that Arabic has 6 plural forms and the rules of when to use each were not plain at all.

What does this means technically?

When using gettext functions, that's include C but also PHP, Python and other languages you have the l10n function _n which accept the single form and the plural form.
Because each language can have very different rules for plurals each po file has a field name Plural-Forms that define an expression such as nplurals=2; plural=(n > 1);

This expression is built from two parts: nplurals is the number of plural forms supported by the language. plural is C like expression with input n and output of the index of the plural l10n message to use.

Checkout a list of such expressions for languages.

Conclusion

Next time you do l10n remember to use plurals and not just add S when n > 1 :)