MCPcopy Create free account
hub / github.com/darkreader/darkreader / mergeLocale

Function mergeLocale

tasks/bundle-locales.js:41–70  ·  view source on GitHub ↗

@type {(localesDir: string, code: string) => Promise }

(localesDir, code)

Source from the content-addressed store, hash-verified

39
40/** @type {(localesDir: string, code: string) => Promise<string>} */
41async function mergeLocale(localesDir, code) {
42 /** @type {LocaleMessages} */
43 let result = {};
44
45 /** @type {(dir: string) => Promise<void>} */
46 const walk = async (dir) => {
47 const dirFiles = [];
48 const dirDirs = [];
49 const paths = await fs.readdir(dir);
50 for (const path of paths) {
51 const stat = await fs.stat(`${dir}/${path}`);
52 if (stat.isDirectory()) {
53 dirDirs.push(path);
54 } else {
55 dirFiles.push(path);
56 }
57 }
58 const localeFiles = dirFiles.filter((f) => f.split('.').at(-2) === code);
59 for (const localeFile of localeFiles) {
60 const messages = await localeFileToJson(`${dir}/${localeFile}`);
61 result = {...result, ...messages};
62 }
63 for (const folder of dirDirs) {
64 await walk(`${dir}/${folder}`);
65 }
66 };
67
68 await walk(localesDir);
69 return JSON.stringify(result, null, 4);
70}
71
72async function bundleLocales(srcLocalesDir, {platforms, debug}) {
73 const absoluteSrcLocalesDir = absolutePath(srcLocalesDir);

Callers 2

bundleLocalesFunction · 0.85
onChangeFunction · 0.85

Calls 1

walkFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…