aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-29 00:52:20 +0100
committerGitHub <noreply@github.com>2021-12-29 00:52:20 +0100
commitefdc25e4516bc5341e305acf42935407f465a0fb (patch)
tree5b0eeb6c16d8d419e9dc680136918938cee3aff6 /src/lang.js
parent3d5ccdad4b95e4453ac1857324b2a89497870f09 (diff)
parent4add9f34f5d9cded91db553aa7a72c6898f7d98b (diff)
downloadViper-efdc25e4516bc5341e305acf42935407f465a0fb.tar.gz
Viper-efdc25e4516bc5341e305acf42935407f465a0fb.zip
Merge pull request #7 from 0neGal/localization
Localization support
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lang.js b/src/lang.js
new file mode 100644
index 0000000..266fb8b
--- /dev/null
+++ b/src/lang.js
@@ -0,0 +1,24 @@
+const fs = require("fs");
+
+var lang = "en";
+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 {
+ return string
+ }
+}