修复remote-only模式下语言包归一化的历史bug:当页面leaf顶层存在与命名空间同名的字符串键时,会覆盖整个namespace导致子key失效。通过对齐normalizePageLangPack的两层合并逻辑来修复: 1. 先将页面语言包按路径段转为命名空间结构再合并 2. 额外平铺leaf的基本类型键到根节点以兼容短key调用
25 lines
751 B
JavaScript
25 lines
751 B
JavaScript
// Node script: load all lang files via require and dump as JSON for Python to consume.
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const langDir = path.resolve(process.cwd(), 'lang', process.argv[2]);
|
|
function walk(dir) {
|
|
const out = {};
|
|
if (!fs.existsSync(dir)) return out;
|
|
for (const f of fs.readdirSync(dir)) {
|
|
const full = path.join(dir, f);
|
|
const stat = fs.statSync(full);
|
|
if (stat.isDirectory()) {
|
|
Object.assign(out, walk(full));
|
|
} else if (f.endsWith('.js')) {
|
|
try {
|
|
const m = require(full);
|
|
if (m && m.lang && typeof m.lang === 'object') {
|
|
out[full] = m.lang;
|
|
}
|
|
} catch (e) {}
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
console.log(JSON.stringify(walk(langDir), null, 2));
|