fateforge-tool/js/language.js

41 lines
1 KiB
JavaScript
Raw Normal View History

2023-03-04 21:33:26 +00:00
// In a browser where the language is set to French
2023-03-15 09:40:49 +00:00
localize();
var currentLang;
2023-03-04 21:33:26 +00:00
// You can also override the language detection, and pass in a language code
//$("[data-localize]").localize("main", { language: "fr" });
function changeLangFR() {
2023-03-15 09:40:49 +00:00
localize("fr");
2023-03-04 21:33:26 +00:00
}
2023-03-06 00:43:27 +00:00
// This code defines a function that sets the language to English.
2023-03-04 21:33:26 +00:00
function changeLangEN() {
2023-03-15 09:40:49 +00:00
localize("en");
}
function refreshBooks() {
2023-03-13 15:11:51 +00:00
$("[data-localize]").localize("books", {
2023-03-18 00:09:48 +00:00
pathPrefix: "data",
language: currentLang,
2023-03-04 21:33:26 +00:00
});
}
2023-03-13 15:11:51 +00:00
function refreshLoc() {
2023-03-15 09:40:49 +00:00
localize(currentLang);
2023-03-13 15:11:51 +00:00
}
// Function to fill a data-localize attribute and update DOM
2023-03-18 00:09:48 +00:00
function setLocalizeDataAttr(id, dataValue) {
const all = $('[id="' + id + '"]');
all.each(function() {
console.log(this.id)
$(this).data("localize", dataValue).attr("data-localize", dataValue);
});
2023-03-06 13:13:04 +00:00
}
2023-03-15 09:40:49 +00:00
function localize(lang) {
2023-03-17 01:14:29 +00:00
$("[data-localize]")
.localize("main", { pathPrefix: "lang", language: lang })
2023-03-18 00:09:48 +00:00
.localize("books", { pathPrefix: "data", language: lang });
2023-03-17 01:14:29 +00:00
currentLang=lang;
2023-03-15 09:40:49 +00:00
}