Depending on your application, your internationalization needs will be different. However, common concerns include these issues:
- date, time, number, and currency formatting
- text localization
- pluralization and complex messages
- sorting and collation
More demanding use-cases may even require these:
- phone number formatting
- alternative calendars
Finally, considering that EcmaScript now includes an internationalization API that is already supported in Chrome and Firefox, I think the following is important:
In my opinion, using a single library that supports all of the above is preferable to using multiple libraries. However, one solution doesn’t always work for every situation and a single solution doesn’t even seem to exist. You may have to use two or more different libraries to get all the functionality you need. For example, libraries that provide general number formatting support typically don’t provide phone number support.
EcmaScript Intl Library
- number formatting
- date/time formatting
The new Intl library is extremely important because it means that you get some internationalization support without loading an external library. Additionally, implementations support the CLDR data, which is the best-practice for format patterns.
If you need to use a separate library, you should favor those that provide a polyfill for this API when possible. This will make future transitions smoother.
The Intl.js library is a polyfill for the EcmaScript Intl library. It provides the number and date/time formatting APIs. However, it does not provide the collation API. Because it uses CLDR data, you can feel comfortable that the actual formats created by this library will be the same as–or very similar to–the EcmaScript Intl library. However, because collation isn’t available, you obviously have to look elsewhere if that is needed. If you don’t need collation, this may be a good option for basic data formatting.
TheJQuery Globalize library now provides CLDR support. It also provides the number, date, and time formatting. However, it gives you a couple additional features above Intl.js that make it worth considering:
- message translation API
Message translation is a localization API for common message strings. The library defines a file format for translatable message strings and gives you API for retrieving those strings after translation.
Pluralization is a feature that lets you accommodate the differences in word choice that are needed when word forms depend on their count. For example, the pluralization library let’s you conveniently handle word choice for 0, 1, or n number of mouse or mice. Both Polish and Russian, for example, have several plural forms for 2, 3, 4, 5, or even more instances of a particular noun.
The Format.js library was recently released by Yahoo. It builds upon the Intl.js library and adds support for the following:
- support for template libraries like Handlebars, React, and Dust
- cache support for Intl format objects
- ICU message syntax for pluralization, gender, and other types of message variability
- relative time (5 min ago, 2 hours ago, etc)
The set of APIs is modular. If you only need the relative time support, you can load just that library instead of other items.
If you are already using Dojo, Dojo’s own internationalization libraries are an obvious choice. With support for string resource bundles, date and time formatting, and number and currency formatting, Dojo’s library has a lot to offer. This library’s additional benefit is its support for the CLDR patterns.
Phone Number Library