aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-29 23:33:30 +0100
committer0neGal <mail@0negal.com>2021-12-29 23:33:30 +0100
commit9d4515fd408c38ad081c010e052b2960f5fe3dfe (patch)
treeffd6528723e7fb4e5e6f99027683794226f22a2d /src/lang.js
parentdcbdadbe3568beca429b0df5caf96156ee43f474 (diff)
parent74cb566e5ea97f62121fbd7b2cc170b94d36f0bb (diff)
downloadViper-9d4515fd408c38ad081c010e052b2960f5fe3dfe.tar.gz
Viper-9d4515fd408c38ad081c010e052b2960f5fe3dfe.zip
Merge branch 'feat/version-indicator' of https://github.com/Alystrasz/viper into feat/icon
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lang.js b/src/lang.js
new file mode 100644
index 0000000..d404e8e
--- /dev/null
+++ b/src/lang.js
@@ -0,0 +1,29 @@
+const fs = require("fs");
+
+var lang = "en";
+var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
+if (fs.existsSync("viper.json")) {
+ lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
+ if (! lang) {lang = "en"}
+ if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
+ if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) {
+ lang = lang.replace(/-.*$/, "");
+ } else {
+ lang = "en";
+ }
+ }
+}
+
+var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
+
+module.exports = (string) => {
+ if (langObj[string]) {
+ return langObj[string];
+ } else {
+ if (langDef[string]) {
+ return langDef[string];
+ } else {
+ return string;
+ }
+ }
+}