-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyLang.ts
33 lines (30 loc) · 866 Bytes
/
EasyLang.ts
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
30
31
32
33
import json from 'PATH_NAME' assert {type: 'json'};
export class EasyLang {
private static json: object;
public static init(lang: string) {
this.json = json;
}
//Get Phrase for the given key and language
public get(key: string, lang?: string): string {
//Check if key exists
if (EasyLang.json[key] == undefined) {
//Return null
return null;
} else {
//Check if language exists
if (EasyLang.json[key][lang] == undefined) {
//Check if default language exists
if (EasyLang.json[key][EasyLang.json["default"]] == undefined) {
//Return null
return null;
} else {
//Return default language
return EasyLang.json[key][EasyLang.json["default"]];
}
} else {
//Return language
return EasyLang.json[key][lang];
}
}
}
}