aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2021-12-28 18:03:06 +0100
committer0neGal <mail@0negal.com>2021-12-28 18:03:06 +0100
commitc7d3e7480395fa7e5cb0104c8c8efd87ecb6a1a4 (patch)
treea0c716fd71655f66fa971360a6c483afa92dcbda /src/lang.js
parentfccb5815decce6257b8f04cb842a40d6d02110e7 (diff)
downloadViper-c7d3e7480395fa7e5cb0104c8c8efd87ecb6a1a4.tar.gz
Viper-c7d3e7480395fa7e5cb0104c8c8efd87ecb6a1a4.zip
attempt at making localization
This may or may not be how we actually do localization in the future, however for now this seems doable. I will obviously need to look at how we detect the language, as I think instead of relying on names like "en-US" just have "en", so we don't have to symlink various editions of English to the same file. But for now this is a draft, and the important part of this is rather how the underlying localization works.
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lang.js b/src/lang.js
new file mode 100644
index 0000000..4e4e481
--- /dev/null
+++ b/src/lang.js
@@ -0,0 +1,19 @@
+const fs = require("fs");
+
+var lang = "en-US";
+if (fs.existsSync("viper.json")) {
+ lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
+ if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
+ lang = "en-US";
+ }
+}
+
+var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
+
+module.exports = (string) => {
+ if (langObj[string]) {
+ return langObj[string];
+ } else {
+ return string
+ }
+}