BT

InfoQ Homepage News Globalization for JavaScript

Globalization for JavaScript

Bookmarks

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
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.

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

Community comments

  • Dojo has "Globalization"

    by Mario Georgiev /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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

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

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.