Files
web-Iot/tmp_finalcheck.cjs
2026-08-14 09:02:52 +08:00

24 lines
1.6 KiB
JavaScript

const fs = require('fs');
function load(p){let s=fs.readFileSync(p,'utf8');s=s.replace(/const\s+\w+\s*=\s*\{/,'var obj = {');s=s.replace(/export\s+default\s+\w+;?/,'');s=s.replace(/\bconst\b/g,'var');return new Function(s+'\nreturn obj;')();}
const zh=load('src/locales/zh/index.ts'); const en=load('src/locales/en/index.ts');
function flat(o,p,r){p=p||'';r=r||{};for(const k of Object.keys(o)){const key=p?p+'.'+k:k;if(o[k]&&typeof o[k]==='object'&&!Array.isArray(o[k]))flat(o[k],key,r);else r[key]=o[k];}return r;}
const zf=flat(zh), ef=flat(en);
console.log('zh flat keys:',Object.keys(zf).length,' en flat keys:',Object.keys(ef).length);
for(const k of ['common.completed','home.underMaintenance','roles.abnormal']) console.log(' en has '+k+':',k in ef,' (zh:',k in zf,')');
// duplicate base-key detection per namespace (text scan)
function dupScan(file){
const text=fs.readFileSync(file,'utf8');
const re=/^\t([A-Za-z]+):\s*\{/gm; let m; const dups=[];
while((m=re.exec(text))){
const ns=m[1]; const start=m.index+m[0].length;
// find matching closing brace
let depth=1,i=start; while(i<text.length&&depth>0){const c=text[i];if(c==='{')depth++;else if(c==='}')depth--;i++;}
const block=text.slice(start,i-1);
const keys={}; let dm; const kr=/^\s*([A-Za-z0-9_'"][A-Za-z0-9_'"]*):/gm;
while((dm=kr.exec(block))){const key=dm[1].replace(/'/g,''); if(key in keys) dups.push(ns+'.'+key); keys[key]=1;}
}
return dups;
}
const dz=dupScan('src/locales/zh/index.ts'); const de=dupScan('src/locales/en/index.ts');
console.log('zh duplicate base keys:',dz.length, dz.slice(0,10)); console.log('en duplicate base keys:',de.length, de.slice(0,10));