Add fallback to English

This commit is contained in:
smartfrigde 2022-06-17 09:37:18 +02:00
parent a216475618
commit 9efce82462

View file

@ -119,12 +119,17 @@ export async function setLang(language: string) {
var language: string; var language: string;
export async function getLang(object: string) { export async function getLang(object: string) {
if (language == undefined) { if (language == undefined) {
const userDataPath = app.getPath("userData"); try {
const storagePath = path.join(userDataPath, "/storage/"); const userDataPath = app.getPath("userData");
const langConfigFile = storagePath + "lang.json"; const storagePath = path.join(userDataPath, "/storage/");
let rawdata = fs.readFileSync(langConfigFile, "utf-8"); const langConfigFile = storagePath + "lang.json";
let parsed = JSON.parse(rawdata); let rawdata = fs.readFileSync(langConfigFile, "utf-8");
language = parsed["lang"]; let parsed = JSON.parse(rawdata);
language = parsed["lang"];
} catch (e) {
console.log("Language config file doesn't exist. Fallback to English.")
language = "en-US"
}
} }
if (language.length == 2) { if (language.length == 2) {
language = language + "-" + language.toUpperCase(); language = language + "-" + language.toUpperCase();