-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18nConvert.ts
31 lines (27 loc) · 1.07 KB
/
i18nConvert.ts
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
import { existsSync, readdirSync, renameSync, unlinkSync } from 'node:fs';
import { join } from 'node:path';
// convert i18n/lang/translations.json to i18n/lang.json
function convert(rootDir: string): void {
if (existsSync(join(rootDir, 'i18n'))) {
rootDir = join(rootDir, 'i18n');
} else if (existsSync(join(rootDir, 'lib', 'i18n'))) {
rootDir = join(rootDir, 'lib', 'i18n');
} else if (existsSync(join(rootDir, 'admin', 'i18n'))) {
rootDir = join(rootDir, 'admin', 'i18n');
} else if (rootDir.endsWith('i18n')) {
// already the correct directory
}
const langs = readdirSync(rootDir);
for (const lang of langs) {
if ((lang.match(/^[a-z]{2}$/) || lang === 'zh-cn') && existsSync(join(rootDir, lang, 'translations.json'))) {
renameSync(join(rootDir, lang, 'translations.json'), join(rootDir, `${lang}.json`));
unlinkSync(join(rootDir, lang));
}
}
}
if (process.argv.length < 3) {
console.warn('Usage: node i18nConvert <path>');
convert('.');
} else {
convert(process.argv[2]);
}