|
@@ -16,14 +16,12 @@
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
|
|
|
|
-
|
|
|
|
var applocale = {
|
|
var applocale = {
|
|
- lang: localStorage.getItem('global_language') == null || localStorage.getItem('global_language') == "default" ? navigator.language : localStorage.getItem('global_language'),
|
|
|
|
- lang: navigator.language.toLowerCase(),
|
|
|
|
|
|
+ lang: (localStorage.getItem('global_language') == null || localStorage.getItem('global_language') == "default" ? navigator.language : localStorage.getItem('global_language')).toLowerCase(),
|
|
localeFile: "",
|
|
localeFile: "",
|
|
localData: {},
|
|
localData: {},
|
|
init: function(localeFile, callback = undefined) {
|
|
init: function(localeFile, callback = undefined) {
|
|
- applocale.localeFile = localeFile;
|
|
|
|
|
|
+ this.localeFile = localeFile;
|
|
$.ajax({
|
|
$.ajax({
|
|
dataType: "json",
|
|
dataType: "json",
|
|
url: localeFile,
|
|
url: localeFile,
|
|
@@ -32,7 +30,7 @@ var applocale = {
|
|
if (callback != undefined) {
|
|
if (callback != undefined) {
|
|
callback(data);
|
|
callback(data);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (data.keys[applocale.lang] != undefined && data.keys[applocale.lang].fwtitle != undefined && ao_module_virtualDesktop) {
|
|
if (data.keys[applocale.lang] != undefined && data.keys[applocale.lang].fwtitle != undefined && ao_module_virtualDesktop) {
|
|
//Update the floatwindow title as well
|
|
//Update the floatwindow title as well
|
|
ao_module_setWindowTitle(data.keys[applocale.lang].fwtitle);
|
|
ao_module_setWindowTitle(data.keys[applocale.lang].fwtitle);
|
|
@@ -44,24 +42,26 @@ var applocale = {
|
|
"font-family":data.keys[applocale.lang].fontFamily
|
|
"font-family":data.keys[applocale.lang].fontFamily
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
translate: function(targetLang = "") {
|
|
translate: function(targetLang = "") {
|
|
- var targetLang = targetLang || applocale.lang;
|
|
|
|
|
|
+ var targetLang = targetLang || this.lang;
|
|
//Check if the given locale exists
|
|
//Check if the given locale exists
|
|
- if (applocale.localData.keys[targetLang] == undefined) {
|
|
|
|
|
|
+ if (this.localData == undefined || this.localData.keys === undefined || this.localData.keys[targetLang] == undefined) {
|
|
console.log("[Applocale] This language is not supported. Using default")
|
|
console.log("[Applocale] This language is not supported. Using default")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
//Update the page content to fit the localization
|
|
//Update the page content to fit the localization
|
|
- let hasTitleLocale = (applocale.localData.keys[targetLang].titles !== undefined);
|
|
|
|
- let hasStringLocale = (applocale.localData.keys[targetLang].strings !== undefined);
|
|
|
|
- let hasPlaceHolderLocale = (applocale.localData.keys[targetLang].placeholder !== undefined);
|
|
|
|
|
|
+ let hasTitleLocale = (this.localData.keys[targetLang].titles !== undefined);
|
|
|
|
+ let hasStringLocale = (this.localData.keys[targetLang].strings !== undefined);
|
|
|
|
+ let hasPlaceHolderLocale = (this.localData.keys[targetLang].placeholder !== undefined);
|
|
|
|
+ let localizedDataset = this.localData.keys[targetLang];
|
|
$("*").each(function() {
|
|
$("*").each(function() {
|
|
if ($(this).attr("title") != undefined && hasTitleLocale) {
|
|
if ($(this).attr("title") != undefined && hasTitleLocale) {
|
|
- let targetString = applocale.localData.keys[targetLang].titles[$(this).attr("title")];
|
|
|
|
|
|
+ let targetString = localizedDataset.titles[$(this).attr("title")];
|
|
if (targetString != undefined) {
|
|
if (targetString != undefined) {
|
|
$(this).attr("title", targetString);
|
|
$(this).attr("title", targetString);
|
|
}
|
|
}
|
|
@@ -69,14 +69,14 @@ var applocale = {
|
|
}
|
|
}
|
|
|
|
|
|
if ($(this).attr("locale") != undefined && hasStringLocale) {
|
|
if ($(this).attr("locale") != undefined && hasStringLocale) {
|
|
- let targetString = applocale.localData.keys[targetLang].strings[$(this).attr("locale")];
|
|
|
|
|
|
+ let targetString = localizedDataset.strings[$(this).attr("locale")];
|
|
if (targetString != undefined) {
|
|
if (targetString != undefined) {
|
|
$(this).html(targetString);
|
|
$(this).html(targetString);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if ($(this).attr("placeholder") != undefined && hasPlaceHolderLocale) {
|
|
if ($(this).attr("placeholder") != undefined && hasPlaceHolderLocale) {
|
|
- let targetString = applocale.localData.keys[targetLang].placeholder[$(this).attr("placeholder")];
|
|
|
|
|
|
+ let targetString = localizedDataset.placeholder[$(this).attr("placeholder")];
|
|
if (targetString != undefined) {
|
|
if (targetString != undefined) {
|
|
$(this).attr("placeholder", targetString);
|
|
$(this).attr("placeholder", targetString);
|
|
}
|
|
}
|
|
@@ -84,11 +84,11 @@ var applocale = {
|
|
})
|
|
})
|
|
},
|
|
},
|
|
getString: function(key, original, type = "strings") {
|
|
getString: function(key, original, type = "strings") {
|
|
- var targetLang = applocale.lang;
|
|
|
|
- if (applocale.localData.keys[targetLang] == undefined) {
|
|
|
|
|
|
+ var targetLang = this.lang;
|
|
|
|
+ if (this.localData.keys[targetLang] == undefined) {
|
|
return original;
|
|
return original;
|
|
}
|
|
}
|
|
- let targetString = applocale.localData.keys[targetLang].strings[key];
|
|
|
|
|
|
+ let targetString = this.localData.keys[targetLang].strings[key];
|
|
if (targetString != undefined) {
|
|
if (targetString != undefined) {
|
|
return targetString
|
|
return targetString
|
|
} else {
|
|
} else {
|