-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalizedManifest.ts
More file actions
36 lines (32 loc) · 1.13 KB
/
localizedManifest.ts
File metadata and controls
36 lines (32 loc) · 1.13 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
import { glob } from 'node:fs/promises';
import path from 'node:path';
import zhCNManifest from './src/locales/zh-CN/manifest';
const manifestsGlob = glob(path.join(import.meta.dirname, './src/locales/*/manifest.*'), {});
const excludedManifest = zhCNManifest;
const manifests = [];
for await (const manifestPath of manifestsGlob) {
const manifest = (await import(manifestPath)).default;
if (manifest !== excludedManifest) {
manifests.push((await import(manifestPath)).default);
}
}
function makeLocalizedManifest(...manifests: Record<string, unknown>[]): Record<string, unknown> {
const localizedManifest: Record<string, Record<string, unknown>> = {};
for (const manifest of manifests) {
for (const key in manifest) {
if (key === 'lang') {
continue;
}
const languageMap = localizedManifest[`${key}_localized`] ?? {};
if (manifest[key] !== undefined) {
languageMap[manifest.lang as string] = manifest[key];
}
localizedManifest[`${key}_localized`] = languageMap;
}
}
return localizedManifest;
}
export default {
...zhCNManifest,
...makeLocalizedManifest(...manifests),
};