2013-03-28 Update : This plugin is now hosted on GitHub

2010-09-29 Update : This plugin has been moved from subversion to git, and now has a dedicated project page . Subversion updates will be discontinued, so please update your links to point to the latest version!

2010/08/01 Update : Thanks to everyone that pointed out the scope issue and lack of this - it should be fixed now.

I’ve recently had to do some translation on the client-side using JavaScript, and wrote this plugin to do it (based heavily on javascript i18n that almost doesn’t suck by Marcus).

Download jquery.i18n.js

To try it out, download the sample files , or check them out using git :

git co git://github.com/recurser/jquery-i18n.git

The index.html file should be fairly self-explanatory… before you do any translation you have to initialise the plugin with a ‘dictionary’ (basically a property list mapping keys to their translations).

var my_dictionary = {
    "some text"  : "a translation",
    "some more text"  : "another translation"
}
$.i18n.setDictionary(my_dictionary);

Once you’ve initialised it with a dictionary, you can translate strings using the $.i18n._() function, for example :

$('div#example').text($.i18n._('some text'));

If you want a solution that’s a bit more global, Keith Wood has written a localisation plugin that looks very nice (i haven’t actually tried it).