Add steno and update language

This commit is contained in:
Lucas 2023-03-15 10:40:49 +01:00
parent 73126741cd
commit ef06b6366e
3 changed files with 32 additions and 30 deletions

View file

@ -8,4 +8,5 @@
"url": "/./.vscode/spells-schemas.json"
}
],
"stenography.apiKey": "caac2b35-1682-4741-a409-d687f69d9767",
}

View file

@ -1,35 +1,16 @@
// In a browser where the language is set to French
$("[data-localize]")
.localize("main", { pathPrefix: "lang" })
.localize("books", { pathPrefix: "lang" });
localize();
var currentLang;
// You can also override the language detection, and pass in a language code
//$("[data-localize]").localize("main", { language: "fr" });
function changeLangFR() {
$("[data-localize]")
.localize("main", {
pathPrefix: "lang",
language: "fr",
})
.localize("books", {
pathPrefix: "lang",
language: "fr",
});
currentLang = "fr";
localize("fr");
}
// This code defines a function that sets the language to English.
function changeLangEN() {
$("[data-localize]")
.localize("main", {
pathPrefix: "lang",
language: "en",
})
.localize("books", {
pathPrefix: "lang",
language: "en",
});
currentLang = "en";
localize("en");
}
function refreshBooks() {
@ -40,9 +21,7 @@ function refreshBooks() {
}
function refreshLoc() {
$("[data-localize]")
.localize("main", { pathPrefix: "lang", language: currentLang })
.localize("books", { pathPrefix: "lang", language: currentLang });
localize(currentLang);
}
// Function to fill a data-localize attribute and update DOM
@ -51,3 +30,17 @@ function setLocalizeDataAttr(className, dataValue) {
.data("localize", dataValue)
.attr("data-localize", dataValue);
}
function localize(lang) {
var overrideLang = "language:" + (lang ? lang : "");
$("[data-localize]")
.localize("main", {
pathPrefix: "lang",
overrideLang,
})
.localize("books", {
pathPrefix: "lang",
overrideLang,
});
currentLang = lang;
}

View file

@ -105,10 +105,10 @@ http://keith-wood.name/localisation.html
success: successFunc,
error: errorFunc,
statusCode: {
404: function() {
404: function () {
console.log("Le fichier " + file + " n'existe pas.");
}
}
},
},
};
if (window.location.protocol === "file:") {
ajaxOptions.error = function (xhr) {
@ -137,6 +137,14 @@ http://keith-wood.name/localisation.html
}
});
};
/*
This code is iterating over the elements in the DOM and calling a function to localize
them The first argument of this function is an element which we can use to determine
what type of element it is If it\'s an input or textarea then we call a different
function that will handle those two types of elements If it\'s an image then we call
another function that handles images If it\'s an optgroup then we call another one
for optgroups
*/
localizeElement = function (elem, key, value) {
if (elem.is("input")) {
localizeInputElement(elem, key, value);