feat(frontend): add next-intl bilingual i18n for core paths

Wire next-intl without locale routes, add zh-CN/en catalogs, language
switcher, and migrate layout/auth/settings UI copy. Document i18n rules
in AGENTS.md and keep static export builds working.
This commit is contained in:
ryan
2026-07-24 16:25:41 +08:00
parent 9c1369186f
commit 1625cfb2fb
23 changed files with 1638 additions and 355 deletions
+35
View File
@@ -0,0 +1,35 @@
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 onlyEn = [...enKeys].filter((k) => !enKeys.has(k) === false && !zhKeys.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)`);