Shared publicly  - 
You've probably done something like this before:

if ( X === 1 ) {
return "There is one result";
else {
return "There are " + X + " results";
What about if you're translating to a language that has more than 2 cases to pluralize (e.g. specific case for 1, specific case for 2, specific case for 2+)?

This is a great discussion that sheds some light on this and even more complex localization problems and suggests a potential solution.
Kirill Maximov (KIR)'s profile photoHugo Josefson's profile photoWeb Developers Sandbox's profile photoAnbarasan Gangadaran's profile photo
The examples in the article are bad. In Java, MessageFormat has the ability to deal with these things. The syntax is like this: "There {0,choice,0#are 0 results|1#is one result|1<are {0,number} results}". As you can see. All you need to do is to feed the format string into MessageFormat.format(), and the translators can do the rest. No need to have any specific if-statements.

The way it's done in the article doesn't work anyway, since while both French and English differentiate between singular and anything else, other languages have much more complicated rules.

Now, MessageFormat is not perfect either. It can't handle the Russian rules for example, where you use a different form where the form is chosen based on the last digit of the number. In this case, it's fairly easy to deal with though by passing in the last digit as an extra parameter. Languages that don't need it will just not have to use that argument.
Add a comment...