diff options
Diffstat (limited to 'src/lang.js')
-rw-r--r-- | src/lang.js | 24 |
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 + } +} |