From ef06b6366e21a17faeaf679c76b9ac2a7baaaf26 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Wed, 15 Mar 2023 10:40:49 +0100 Subject: [PATCH] Add steno and update language --- .vscode/settings.json | 1 + js/language.js | 45 ++++++++++++++++---------------------- lib/jquery.localize-dev.js | 16 ++++++++++---- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index d009129..b71d5fe 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,4 +8,5 @@ "url": "/./.vscode/spells-schemas.json" } ], + "stenography.apiKey": "caac2b35-1682-4741-a409-d687f69d9767", } \ No newline at end of file diff --git a/js/language.js b/js/language.js index 8625540..1f37a19 100644 --- a/js/language.js +++ b/js/language.js @@ -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; +} \ No newline at end of file diff --git a/lib/jquery.localize-dev.js b/lib/jquery.localize-dev.js index 354a147..2b44ce4 100644 --- a/lib/jquery.localize-dev.js +++ b/lib/jquery.localize-dev.js @@ -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); @@ -239,4 +247,4 @@ http://keith-wood.name/localisation.html }; $.fn.localize = $.localize; return ($.localize.data = {}); -})(jQuery); +})(jQuery); \ No newline at end of file