MCPcopy
hub / github.com/CopyTranslator/CopyTranslator / constructor

Method constructor

src/main/l10n.ts:29–51  ·  view source on GitHub ↗
(localeDirs: string[])

Source from the content-addressed store, hash-verified

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") {

Callers

nothing calls this directly

Calls 4

keysMethod · 0.80
pushMethod · 0.80
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected