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 subversion :
svn co http://svn.recurser.com/misc/jquery/i18n/
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).
No Responses to “jQuery i18n Translation Plugin”
Leave a Reply