views:

91

answers:

3

I'm wondering how to deal internationalization in javascript. I Googled but I'm not getting convincing answers for:

  • Does Javascript have native support for Internationalization?
  • What is i18n in javascript?
  • How to deal with calendar, currency, date, etc?

I've already read http://stackoverflow.com/questions/934175/internationalization-inside-javascript

A: 

Some of it is native, the rest is available through libraries.

For example Datejs is a good international date library.

For the rest, it's just about language translation, and JavaScript is natively Unicode compatible (as well as all major browsers).

Luca Matteis
+1  A: 

Microsoft has recently released a jquery globalization plugin. The details are here

Adeel
+1  A: 

Localisation in JavaScript/ECMAScript is poor, IMO. This is due to phrases in the spec that look like this:

Number.prototype.toLocaleString()
Produces a string value that represents the value of the Number formatted according to the conventions of the host environment’s current locale. This function is implementation-dependent, and it is permissible, but not encouraged, for it to return the same thing as toString.

This resulted in Chrome, Opera and Safari returning the same thing as .toString(). Firefox and IE will return locale formatted strings, and IE even includes a thousands separator (perfect for currency strings).

Every localisation method defined in the spec is defined as "implementation-dependent", which results in a lot of inconsistencies.

Even determining the locale is a problem, since there's no specification for obtaining the current language. Each browser implements a method to obtain a language string, but this could be based on the user's operating system language or just the language of the browser:

// navigator.userLanguage for IE, navigator.language for others
var lang = navigator.language || navigator.userLanguage;

In short, you have to put in a lot of the work yourself, or use a framework/library, because you cannot rely on the browser to do it for you.

Various libraries and plugins for localisation:

Feel free to add/edit.

Andy E