aboutsummaryrefslogtreecommitdiff
path: root/src/lang.js
blob: d404e8e9d8ccca25dd34ee75cb0b8ad2ed7dd9a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fs = require("fs");

var lang = "en";
var langDef = JSON.parse(fs.readFileSync(__dirname + `/lang/en.json`, "utf8"));
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 {
		if (langDef[string]) {
			return langDef[string];
		} else {
			return string;
		}
	}
}