From 9d8047d5e5ddd355c21c42488c1fb56169666c42 Mon Sep 17 00:00:00 2001 From: w0wnero minerz Date: Tue, 8 Feb 2022 17:14:21 +0000 Subject: [PATCH] Added translation.js in js directory --- js/translations/traduction.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 js/translations/traduction.js diff --git a/js/translations/traduction.js b/js/translations/traduction.js new file mode 100644 index 0000000..d22b329 --- /dev/null +++ b/js/translations/traduction.js @@ -0,0 +1,23 @@ +async function translate(lang) { + if (lang == 'en-US') { return }; + var ids = []; + ids = Array.from(document.querySelectorAll('[id]')); + var ids_arr = Array.prototype.map.call(ids, function (element, i) { + return element.id; + }); + for (i = 0; i < ids_arr.length; i++) { + fetchData(ids_arr[i], lang); + } +}; + +async function fetchData(id, lang) { + var response = await fetch(`js/translations/${lang}.json`); + response = await response.json(); + getTranslation(response, id); +}; + +async function getTranslation(data, keys) { + document.getElementById(keys).textContent = JSON.stringify(data[keys]).replace(/["]+/g, ''); +}; + +// console errors are stupid, my code works fine (its late @ night :/) \ No newline at end of file