aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
diff options
context:
space:
mode:
author0neGal <mail@0negal.com>2022-10-23 03:26:54 +0200
committer0neGal <mail@0negal.com>2022-10-23 03:29:23 +0200
commit0862c82996f11822fa851eeebc247d12f88dcd7d (patch)
tree2084b900a35eeccce2d0a027df3b49dc8d1e29d1 /src/lang.js
parentefb5761268d1ced56cc633347a5143343aa957c6 (diff)
parent096c54e746def93eb6ee1b2a8d91e1e62555d610 (diff)
downloadViper-0862c82996f11822fa851eeebc247d12f88dcd7d.tar.gz
Viper-0862c82996f11822fa851eeebc247d12f88dcd7d.zip
Merge branch 'main' into linux-launch
Diffstat (limited to 'src/lang.js')
-rw-r--r--src/lang.js24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/lang.js b/src/lang.js
index 041ef35..f2fab3a 100644
--- a/src/lang.js
+++ b/src/lang.js
@@ -5,13 +5,24 @@ let lang = "";
var langObj = {};
-function _loadTranslation() {
+function _loadTranslation(forcedlang) {
if (fs.existsSync("viper.json")) {
- opts = JSON.parse(fs.readFileSync("viper.json", "utf8"));
+ // Validate viper.json
+ let opts = {
+ lang: "en",
+ autolang: true,
+ }
+
+ try {
+ opts = JSON.parse(fs.readFileSync("viper.json", "utf8"));
+ }catch (e) {}
+
lang = opts.lang;
if (! lang) {lang = "en"}
+ if (forcedlang) {lang = forcedlang}
+
if (opts.autolang == false) {
lang = opts.forcedlang;
if (! lang) {lang = "en"}
@@ -32,9 +43,14 @@ function _loadTranslation() {
}
-module.exports = (string) => {
- if (lang === "")
+module.exports = (string, forcedlang) => {
+ if (lang === "") {
_loadTranslation();
+ }
+
+ if (forcedlang) {
+ _loadTranslation(forcedlang);
+ }
if (langObj[string]) {
return langObj[string];