BT

Your opinion matters! Please fill in the InfoQ Survey!

Globalization for JavaScript

| by Jonathan Allen Follow 188 Followers on Oct 14, 2010. Estimated reading time: 1 minute |

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

Adoption Stage
Style

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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT