| 27 | store: any; |
| 28 | |
| 29 | constructor(localeDirs: string[]) { |
| 30 | localeDirs.forEach((localeDir: string) => { |
| 31 | readdirSync(localeDir).forEach((fileName: string) => { |
| 32 | const filePath = join(localeDir, fileName); |
| 33 | try { |
| 34 | const locale: Locale = JSON.parse(readFileSync(filePath) as any); |
| 35 | for (const key of en.keys()) { |
| 36 | if (!locale[key]) { |
| 37 | locale[key] = en.get(key) as string; |
| 38 | } |
| 39 | } |
| 40 | const lang = fileName.replace(".json", "") as Language; |
| 41 | this.resources.set(lang, locale); |
| 42 | this.locales.push({ |
| 43 | lang, |
| 44 | localeName: locale["localeName"], |
| 45 | }); |
| 46 | } catch (e) { |
| 47 | console.log(`load ${filePath} fail`); |
| 48 | } |
| 49 | }); |
| 50 | }); |
| 51 | } |
| 52 | |
| 53 | getT(key: Language = "en"): Locale { |
| 54 | if (key === "auto") { |