Globalization for JavaScript

by Jonathan Allen on Oct 14, 2010 |

Considering that the whole purpose of JavaScript is to help provide interactive content on an international stage, one would expect to see globalization features either built into the language or widely available in libraries. But surprisingly, until the recent announcement from jQuery and Microsoft there wasn’t anything available.

Well that last statement isn’t entirely true. IBM does have a patent on JavaScript globalization using web services. But one probably doesn’t want to make a round-trip to the server just to determine if “10/1/2010” refers to January 10th or October 1st, so it is doubtful that this patent will ever be enforced.

jQuery’s Globalization library, developed in conjunction with Microsoft, provides full client-side globalization. With approximately 350 cultures in the list, it is bound to cover the formatting and parsing needs of most international web sites.

The actual features in jQuery’s Globalization are quite modest. After setting the jQuery.culture field to the desired language or language/country pair, you get access to parsing and formatting functions for dates, integers, and floating-point numbers.

The other feature you get out of the box is jQuery.localize. This is used to create resource dictionaries based on key/culture pairs. The values you store can in any form you wish, not just strings like most resource dictionaries. When retrieving the values, the engine looks for the best match on culture. For example, you can store localized strings for French (“fr”) and then provide country specific overrides for Canada (“fr-CA”). If at runtime it will look for a culture-country match first, and then check for just matching on culture.

By default jQuery only brings in the neutral English culture. Additional cultures are in separate JavaScript files that need to be reference individually. By inspecting the user’s culture ahead of time instead of bringing them all down one can significantly cut down on load and parsing costs.

jQuery Globalization is available on GitHub.

Rate this Article


Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Dojo has "Globalization" by Mario Georgiev

Dojo Toolkit has the CLDR built-in and you have the formating data for every country.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
General Feedback
Marketing and all content copyright © 2006-2016 C4Media Inc. hosted at Contegix, the best ISP we've ever worked with.
Privacy policy

We notice you're using an ad blocker

We understand why you use ad blockers. However to keep InfoQ free we need your support. InfoQ will not provide your data to third parties without individual opt-in consent. We only work with advertisers relevant to our readers. Please consider whitelisting us.