aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2023-01-12 19:33:49 +0100
committer0neGal <mail@0negal.com>2023-01-12 19:34:39 +0100
commit2889b310c18acc5fbc926d63659a624e4675fe57 (patch)
tree265bef0435d71d7c0bbc79f05962d7f6e7bf5e95 /src/lang.js
parenta67040498d238c3d7b1b947f7be02034f3b71d52 (diff)
downloadViper-2889b310c18acc5fbc926d63659a624e4675fe57.tar.gz
Viper-2889b310c18acc5fbc926d63659a624e4675fe57.zip
added: src/modules/json.js
This module makes it easier to read JSON files, simply returning false on errors, and attempting to repair the JSON automatically.
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/lang.js b/src/lang.js
index f2fab3a..85488d8 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -1,6 +1,8 @@
const fs = require("fs");
-const enLang = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
+const json = require("./modules/json");
+
+const enLang = json(__dirname + "/lang/en.json");
let lang = "";
var langObj = {};
@@ -14,7 +16,7 @@ function _loadTranslation(forcedlang) {
}
try {
- opts = JSON.parse(fs.readFileSync("viper.json", "utf8"));
+ opts = json("viper.json");
}catch (e) {}
lang = opts.lang;
@@ -39,7 +41,7 @@ function _loadTranslation(forcedlang) {
lang = "en";
}
- langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
+ langObj = json(__dirname + `/lang/${lang}.json`);
}