-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslator.ts
More file actions
72 lines (71 loc) · 3.43 KB
/
Translator.ts
File metadata and controls
72 lines (71 loc) · 3.43 KB
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
65
66
67
68
69
70
71
72
import Options from "./Options";
declare const translator: {lang: string};
export default class Translator{
public static allowlangs: string[] = [
"en", "aa", "ab", "af", "am", "ar", "as", "ay", "az", "ba", "be", "bg", "bh", "bi", "bn", "bo", "br",
"ca", "co", "cs", "cy", "da", "de", "dz", "el", "eo", "es", "et", "eu", "fa", "fi", "fj", "fo", "fr",
"fy", "ga", "gd", "gl", "gn", "gu", "ha", "hi", "hr", "hu", "hy", "ia", "ie", "ik", "in", "is", "it",
"iw", "ja", "ji", "jw", "ka", "kk", "kl", "km", "kn", "ko", "ks", "ku", "ky", "la", "ln", "lo", "lt",
"lv", "mg", "mi", "mk", "ml", "mn", "mo", "mr", "ms", "mt", "my", "na", "ne", "nl", "no", "oc", "om",
"pa", "pl", "ps", "pt", "qu", "rm", "rn", "ro", "ru", "rw", "sa", "sd", "sg", "sh", "si", "sk", "sl",
"sm", "sn", "so", "sq", "sr", "ss", "st", "su", "sv", "sw", "ta", "te", "tg", "th", "ti", "tk", "tl",
"tn", "to", "tr", "ts", "tt", "tw", "uk", "ur", "uz", "vi", "vo", "wo", "xh", "yo", "zh", "zu",
];
public static countries: string[] = [
"AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS",
"BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "BN", "BG",
"BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD",
"CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE",
"ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL",
"GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "HN", "HK", "HU", "IS", "IN", "ID",
"IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KR", "KW", "KG", "LA",
"LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MK", "MG", "MW", "MY", "MV", "ML", "MT", "MH",
"MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP",
"NL", "AN", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG",
"PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "BL", "SH", "KN", "LC", "MF",
"PM", "VC", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "GS",
"ES", "LK", "SD", "SR", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO",
"TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "US", "UM", "UY", "UZ", "VU", "VE", "VN",
"VG", "VI", "WF", "EH", "YE", "ZM", "ZW",
];
public static is_shortCode(code: string): boolean{
for (const lang of this.allowlangs) {
if (code === lang){
return true;
}
}
return false;
}
public static is_validCode(code: string): boolean{
const matches = code.match(/^([a-z]{2})_([A-Z]{2})$/);
if (matches){
if (this.is_shortCode(matches[1])){
for (const country of this.countries){
if (matches[2] === country){
return true;
}
}
}
}
return false;
}
public static getDefaultLang(): string{
return Options.get("packages.base.translator.defaultlang");
}
public static getDefaultShortLang(): string{
return this.getDefaultLang().substr(0, 2);
}
public static getAvailableLangs(): string[]{
return [this.getCodeLang()];
}
public static getCodeLang(): string{
if (this.lang === undefined){
this.lang = translator.lang;
}
return this.lang;
}
public static getShortCodeLang(): string{
return this.getCodeLang().substr(0, 2);
}
private static lang: string;
}