33 lines
652 B
JavaScript
33 lines
652 B
JavaScript
|
import Translations;
|
||
|
|
||
|
var language = chooseLanguage();
|
||
|
|
||
|
return {
|
||
|
get: get
|
||
|
};
|
||
|
|
||
|
function chooseLanguage() {
|
||
|
var userPreference = navigator.language || navigator.userLanguage;
|
||
|
if(userPreference != undefined) {
|
||
|
if(Translations[userPreference] != undefined) {
|
||
|
return userPreference;
|
||
|
}
|
||
|
var lang = userPreference.replace(/-.*/, '');
|
||
|
for(var key in Translations) {
|
||
|
if(key.replace(/-.*/, '') == lang) {
|
||
|
return key;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if(Translations['en-US'] != undefined) {
|
||
|
return 'en-US';
|
||
|
}
|
||
|
for(var key in Translations) {
|
||
|
return key;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function get(textId) {
|
||
|
return Translations[language][textId] || ('TRANSLATE "'+textId+'" !!');
|
||
|
}
|