aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-01-19 23:51:26 +0100
committerGitHub <noreply@github.com>2022-01-19 23:51:26 +0100
commit057b60f4843798441ad441370381b87299d5ad7f (patch)
treeef0ac85051f0abb8b0febfc507ad5c71a5e7e3e8 /src/lang.js
parent962265ffbe3aa0a9c2084d370c914c0265ee6bd9 (diff)
parentae7de46f4748c800097f0f3c700e6525d7d7cc4f (diff)
downloadViper-057b60f4843798441ad441370381b87299d5ad7f.tar.gz
Viper-057b60f4843798441ad441370381b87299d5ad7f.zip
Merge branch 'main' into enabledmods
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/lang.js b/src/lang.js
index d404e8e..b3cbb43 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -1,15 +1,23 @@
const fs = require("fs");
-var lang = "en";
+var lang = "en"; // Default language
+
+// Loads fallback/default language strings
var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
+
+// If settins are set it'll try to set the language to that instead of
+// the default, however if it can't find it, it'll still fallback to the
+// default language. This might happen as the default language is
+// retrieved from the renderer's navigator.language, which may have
+// languages we don't support yet.
if (fs.existsSync("viper.json")) {
lang = JSON.parse(fs.readFileSync("viper.json", "utf8")).lang;
- if (! lang) {lang = "en"}
+ if (! lang) {lang = "en"} // Uses fallback, if language isn't set
if (! fs.existsSync(__dirname + `/lang/${lang}.json`)) {
if (fs.existsSync(__dirname + `/lang/${lang.replace(/-.*$/, "")}.json`)) {
lang = lang.replace(/-.*$/, "");
} else {
- lang = "en";
+ lang = "en"; // Uses fallback if language doesn't exist
}
}
}
@@ -17,12 +25,14 @@ if (fs.existsSync("viper.json")) {
var langObj = JSON.parse(fs.readFileSync(__dirname + `/lang/${lang}.json`, "utf8"));
module.exports = (string) => {
- if (langObj[string]) {
+ if (langObj[string]) { // Returns string from language
return langObj[string];
- } else {
- if (langDef[string]) {
+ } else { // If string doesn't exist
+ if (langDef[string]) { // Retrieves from default lang instead
return langDef[string];
} else {
+ // If it's not in the default lang either, it returns the
+ // string, this is absolute fallback.
return string;
}
}