coderifous / jquery-localize

a jQuery plugin that makes it easy to internationalize your web site.
465 stars 142 forks source link

Use localize at any js file. #84

Open dovvas opened 8 years ago

dovvas commented 8 years ago

I made some fixes and since it took me some time, would like to share for everyone to know. On the jquery.localize.js simple declare a global variable the top of the file "var globallanguage;" at the line somewhere around 183 where "lang" is declared simple after that, add the "globallanguage=lang;"

Then you may go at any file you want and simple add the below code...

$("[data-localize]").localize("folder/where/your/json/file/is/", { language: globallanguage, //taking from localize.jquery callback: function(data, defaultCallback) {message = data.alert.incidentalert.MESSAGE; defaultCallback(data); }}); alert(message);

Now at the file with this code, you may use translated strings according to the language you have choosed.