You can do seperate js file with strings only, e.g.:
var MultilanguageStrings = {
'savingConfirmation': {
'en': 'Do you want to save changes?',
'pl': 'Czy chcesz zapisać zmiany?'
},
'fatalError': {
'en': 'Fatal error occured.',
'pl': 'Wystąpił krytyczny błąd.'
},
'get': function (key, lang) {
if (this[key] === undefined)
return 'Error. There is no such message.';
if (lang == 'en' && this[key]['en'] === undefined)
return 'Error. There is no such message.';
if (this[key][lang] === undefined)
return this.get(key, 'en');
return this[key][lang];
}
};
And than make dynamically generated js file with information which language is set:
var currentLanguage = 'en';
You can also get this information by different way (e.g. AJAX) but solution above has this advantage, that your code is already loaded and currentLanguage
is set.
Then in your code put:
...
if (confirm(MultilanguageStrings.get('savingConfirmation', currentLanguage))) {
...
You may want to wrap everything into 1 global variable, that would be more neat.
Also remember not to overwrite method MultilanguageStrings.get
.