mirror of
https://git.wownero.com/wownero/wownero.org-website.git
synced 2024-08-15 01:03:33 +00:00
Fix translation DDoS issue
This DDoS issue happened if the language didn't exist or the browser cache was disabled
This commit is contained in:
parent
06bf37f859
commit
cca8029096
1 changed files with 6 additions and 14 deletions
|
@ -1,23 +1,15 @@
|
||||||
async function translate(lang) {
|
async function translate(lang) {
|
||||||
if (lang == 'en-US') { return };
|
if (lang == 'en-US') return;
|
||||||
|
if (lang == "it" || lang == "it-CH") lang = "it-IT";
|
||||||
var ids = [];
|
var ids = [];
|
||||||
ids = Array.from(document.querySelectorAll('[id]'));
|
ids = Array.from(document.querySelectorAll('[id]'));
|
||||||
var ids_arr = Array.prototype.map.call(ids, function (element, i) {
|
var ids_arr = Array.prototype.map.call(ids, (element, i)=>{return element.id});
|
||||||
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`);
|
var response = await fetch(`js/translations/${lang}.json`);
|
||||||
response = await response.json();
|
response = await response.json();
|
||||||
getTranslation(response, id);
|
|
||||||
|
for (i = 0; i < ids_arr.length; i++) getTranslation(response, ids_arr[i]);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getTranslation(data, keys) {
|
async function getTranslation(data, keys) {
|
||||||
document.getElementById(keys).textContent = JSON.stringify(data[keys]).replace(/["]+/g, '');
|
document.getElementById(keys).textContent = JSON.stringify(data[keys]).replace(/["]+/g, '');
|
||||||
};
|
};
|
||||||
|
|
||||||
// console errors are stupid, my code works fine (its late @ night :/)
|
|
Loading…
Reference in a new issue