-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.ts
64 lines (56 loc) · 1.76 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import english from "./locales/english.json";
import polish from "./locales/polish.json";
import spanish from "./locales/spanish.json";
import indonesian from "./locales/indonesian.json";
import schinese from "./locales/schinese.json";
import german from "./locales/german.json";
import russian from "./locales/russian.json";
import italian from "./locales/italian.json";
import swedish from "./locales/swedish.json";
import vietnamese from "./locales/vietnamese.json";
import { Logger } from "../Logger";
interface LocalizationData {
[key: string]: string;
}
const handler: ProxyHandler<any> = {
get: function(target, property: keyof any) {
if (property in target) {
return target[property];
}
else {
try {
// fallback to english if the target string wasn't found
return (english as any)?.[property]
}
catch (exception) {
return "unknown translation key"
}
}
}
};
export let locale: LocalizationData = new Proxy(english, handler);
const localizationFiles: { [key: string]: LocalizationData } = {
english,
polish,
spanish,
indonesian,
schinese,
german,
russian,
italian,
vietnamese,
swedish
// Add other languages here
};
const GetLocalization = async () => {
const language = await SteamClient.Settings.GetCurrentLanguage()
Logger.Log(`loading locales ${language} ${localizationFiles?.[language]}`)
if (localizationFiles.hasOwnProperty(language)) {
locale = new Proxy(localizationFiles[language], handler);
}
else {
Logger.Warn(`Localization for language ${language} not found, defaulting to English.`)
}
};
// setup locales on startup
GetLocalization();