mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-28 05:46:36 +08:00
5a8722ff07
接入无 URL 前缀的 zh-CN/en,顶栏与外观设置可切换语言;选择写入 cookie 后刷新生效。
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { readFileSync } from 'node:fs';
|
|
import { resolve, dirname } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
|
|
function flatten(obj, prefix = '') {
|
|
const keys = new Set();
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
const path = prefix ? `${prefix}.${key}` : key;
|
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
for (const child of flatten(value, path)) keys.add(child);
|
|
} else {
|
|
keys.add(path);
|
|
}
|
|
}
|
|
return keys;
|
|
}
|
|
|
|
const zh = JSON.parse(
|
|
readFileSync(resolve(root, 'messages/zh-CN.json'), 'utf8'),
|
|
);
|
|
const en = JSON.parse(readFileSync(resolve(root, 'messages/en.json'), 'utf8'));
|
|
const zhKeys = flatten(zh);
|
|
const enKeys = flatten(en);
|
|
const onlyZh = [...zhKeys].filter((k) => !enKeys.has(k)).sort();
|
|
const onlyEnFixed = [...enKeys].filter((k) => !zhKeys.has(k)).sort();
|
|
|
|
if (onlyZh.length || onlyEnFixed.length) {
|
|
console.error('i18n key mismatch');
|
|
if (onlyZh.length) console.error('only in zh-CN:', onlyZh);
|
|
if (onlyEnFixed.length) console.error('only in en:', onlyEnFixed);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`i18n keys OK (${zhKeys.size} keys)`);
|