中英文切换

This commit is contained in:
mmc
2026-08-14 09:02:52 +08:00
parent a8af55a856
commit 62b03bba03
94 changed files with 19723 additions and 2766 deletions

45
tmp_scan_cjk.cjs Normal file
View File

@@ -0,0 +1,45 @@
const fs = require('fs');
const path = require('path');
const dir = 'src';
const exts = ['.tsx', '.ts', '.jsx', '.js'];
function walk(d) {
let r = [];
for (const f of fs.readdirSync(d)) {
const p = path.join(d, f);
if (fs.statSync(p).isDirectory()) {
if (p.includes('locales')) continue;
r = r.concat(walk(p));
} else if (exts.some((e) => f.endsWith(e))) {
r.push(p);
}
}
return r;
}
// strip comments (line + block) and template strings, then find remaining Chinese
function stripCommentsAndStrings(code) {
// Remove block comments
code = code.replace(/\/\*[\s\S]*?\*\//g, '');
// Remove line comments (careful with URLs, but ok)
code = code.replace(/^\s*\/\/.*$/gm, '');
return code;
}
let total = 0;
for (const f of walk(dir)) {
const code = fs.readFileSync(f, 'utf8');
const cleaned = stripCommentsAndStrings(code);
const lines = cleaned.split('\n');
lines.forEach((line, i) => {
if (/[\u4e00-\u9fa5]/.test(line)) {
total++;
const trimmed = line.trim();
if (trimmed.length > 0 && !trimmed.startsWith('//')) {
console.log(f + ':' + (i + 1) + ': ' + line.trim().slice(0, 120));
}
}
});
}
console.log('TOTAL non-comment lines with Chinese:', total);