Ben Ward

A quick example of internationalising phrases

.

Internationalising phrases is harder than it looks, since it’s not just an exercise in swapping words and inserting variables. A common issue is the plural: The presence of an ‘s’ on a key word, based on the value of a piece of data you’re describing.

I’ve been looking for more complicated examples, though. Various foreign languages will change phrase in more complex ways as numbers increase, and a good translation system needs to be able to handle this range-based substitution.

I just stumbled on a still-simple three-phrase translation in English (in a Last.FM tooltip), so am noting it down whilst I remember it. I need to spend some time collecting better examples though; suggestions and other references are very welcome.

‘You’ve played this song n times’

‘1 times’ will render without the ‘s’, but is also clumsy. The better phrase would be ‘You’ve played this song once.’ First dedicated translation variant.

‘2 times’ adds the common ‘s’ plural, but is still an inelegant phrase. So, that should be ‘You’ve played this song twice.’ Second dedicated variant.

Now, unless our site is recording the number of times you’ve worn a top hat and monocle, it’s unlikely to use the word ‘thrice’. So ‘3 times’ is the first instance of a generic, swappable phrase that will scale up with all remaining numbers in English.

Of course there’s the zero-case too; ‘0 times’ works, but ‘You’ve not played this song’ is better.

Generally when writing views, we find it tolerable to do a data.count === 1 check when needed. But here you need three branches in English. A different language, however, with different plural rules, might not. Or might employ a colloquial phrasing at 10, or 5. Plurals need to be handled within the translation function itself.


Update: 2011-04-10: If reading this made you think, then you should probably now read Localizing Your Perl Programs by Sean M. Burke and Jordan Lachler, which documents specific scenarios around Russian, Chinese and Arabic and English. It was written in 1999, and documents the limitations of gettext(), which is still the base of most web software translations I’ve ever worked with. They explain how maketext works in comparison. That came in via Paul Mison.

You can file issues or provide corrections: View Source on Github. Contributor credits.