aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2024-02-18 23:03:07 +0100
committer0neGal <mail@0negal.com>2024-02-18 23:15:50 +0100
commitccde19d82a1a8fd3c5ea20efa31a0e18393e14fe (patch)
tree8b3fcebd1583d1c15c72f41d20bbdea5a111168d /src/lang.js
parent4385ad45b0c4cb9a46f387ed3b54bd363f3de2ef (diff)
downloadViper-ccde19d82a1a8fd3c5ea20efa31a0e18393e14fe.tar.gz
Viper-ccde19d82a1a8fd3c5ea20efa31a0e18393e14fe.zip
added a lot more functionality to scripts/langs.js
It's not capable of formatting language files, and now has a prompt interface for editing and adding missing localization strings. This removes the need for manually editing localization files beyond `en.json`, it'll still be edited manually. But maintainers will no longer have to open any localization files. I also updated the documentation for contributing to localizations.
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js28
1 files changed, 2 insertions, 26 deletions
diff --git a/src/lang.js b/src/lang.js
index b3cc251..7397839 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -1,36 +1,12 @@
const fs = require("fs");
+const flat = require("flattenizer");
const json = require("./modules/json");
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")) {
// Validate viper.json
@@ -65,7 +41,7 @@ function _loadTranslation(forcedlang) {
lang = "en";
}
- langObj = flatten_obj(json(__dirname + `/lang/${lang}.json`) || {});
+ langObj = flat.flatten(json(__dirname + `/lang/${lang}.json`) || {});
}