diff options
author | 0neGal <mail@0negal.com> | 2023-09-16 01:28:38 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2023-09-16 01:28:38 +0200 |
commit | a91f0d2eac46510c109a4faebf520f68a3456aab (patch) | |
tree | 66fffa7ea3d8fd1ce097424602d2c428cb4ce8be /src/lang.js | |
parent | ba64cef4fd5738e5744814bf67dddbd3865132f1 (diff) | |
download | Viper-a91f0d2eac46510c109a4faebf520f68a3456aab.tar.gz Viper-a91f0d2eac46510c109a4faebf520f68a3456aab.zip |
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.
Diffstat (limited to 'src/lang.js')
-rw-r--r-- | src/lang.js | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/lang.js b/src/lang.js index 85488d8..b3cc251 100644 --- a/src/lang.js +++ b/src/lang.js @@ -6,6 +6,30 @@ const enLang = json(__dirname + "/lang/en.json"); let lang = ""; var langObj = {}; +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; +} function _loadTranslation(forcedlang) { if (fs.existsSync("viper.json")) { @@ -41,7 +65,7 @@ function _loadTranslation(forcedlang) { lang = "en"; } - langObj = json(__dirname + `/lang/${lang}.json`); + langObj = flatten_obj(json(__dirname + `/lang/${lang}.json`) || {}); } |