From a91f0d2eac46510c109a4faebf520f68a3456aab Mon Sep 17 00:00:00 2001 From: 0neGal Date: Sat, 16 Sep 2023 01:28:38 +0200 Subject: lang files can now use objects! The `lang()` function doesn't change whatsoever, as the lang files are flattened and are therefore identical to the before this commit. I also cleaned up the files, and all the lang files should now all look far more similar in order. --- scripts/langs.js | 30 +++- src/app/index.html | 6 +- src/app/js/settings.js | 10 +- src/lang.js | 26 ++- src/lang/de.json | 464 ++++++++++++++++++++++++++++++------------------- src/lang/en.json | 464 ++++++++++++++++++++++++++++++------------------- src/lang/es.json | 464 ++++++++++++++++++++++++++++++------------------- src/lang/fr.json | 463 +++++++++++++++++++++++++++++------------------- 8 files changed, 1196 insertions(+), 731 deletions(-) diff --git a/scripts/langs.js b/scripts/langs.js index e870a3c..a91b243 100644 --- a/scripts/langs.js +++ b/scripts/langs.js @@ -1,9 +1,35 @@ const fs = require("fs"); let problems = false; -let lang = require("../src/lang/en.json"); let maintainers = require("../src/lang/maintainers.json"); +function flatten_obj(data) { + var obj = {}; + + for (let i in data) { + if (! data.hasOwnProperty(i)) { + continue; + } + + if (typeof data[i] == "object" && data[i] !== null) { + var flattened = flatten_obj(data[i]); + for (var ii in flattened) { + if (! flattened.hasOwnProperty(ii)) { + continue; + } + + obj[i + "." + ii] = flattened[ii]; + } + } else { + obj[i] = data[i]; + } + } + + return obj; +} + +let lang = flatten_obj(require("../src/lang/en.json")); + langs = fs.readdirSync("src/lang") langs.forEach((localefile) => { if (localefile == "maintainers.json") {return} @@ -12,7 +38,7 @@ langs.forEach((localefile) => { let langmaintainers = maintainers.list[localefile.replace(/\..*$/, "")]; let locale = false; try { - locale = require("../src/lang/" + localefile) + locale = flatten_obj(require("../src/lang/" + localefile)); }catch(err) { console.log(`\x1b[101m!! ${localefile} is not formatted right !!\x1b[0m`); return diff --git a/src/app/index.html b/src/app/index.html index 8fbcb8a..c61960f 100644 --- a/src/app/index.html +++ b/src/app/index.html @@ -200,12 +200,12 @@