46 lines
3.6 KiB
JavaScript
46 lines
3.6 KiB
JavaScript
import { readdirSync, readFileSync } from 'node:fs'
|
|
import { parse } from '@vue/compiler-sfc'
|
|
import ts from 'typescript'
|
|
|
|
const views = new URL('../src/views/', import.meta.url)
|
|
const hasHan = /\p{Script=Han}/u
|
|
const rows = []
|
|
|
|
for (const name of readdirSync(views).filter((file) => file.endsWith('.vue')).sort()) {
|
|
const source = readFileSync(new URL(name, views), 'utf8')
|
|
const { descriptor, errors } = parse(source, { filename: name })
|
|
if (errors.length) throw new Error(`${name}: ${errors.join(', ')}`)
|
|
const template = (descriptor.template?.content ?? '').replace(/<!--[\s\S]*?-->/g, '')
|
|
const templateLines = template.split(/\r?\n/).filter((line) => hasHan.test(line)).length
|
|
const scriptLines = new Set()
|
|
for (const block of [descriptor.script, descriptor.scriptSetup].filter(Boolean)) {
|
|
const file = ts.createSourceFile(name + '.ts', block.content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS)
|
|
function visit(node) {
|
|
if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node) ||
|
|
ts.isTemplateHead(node) || ts.isTemplateMiddle(node) || ts.isTemplateTail(node)) && hasHan.test(node.text)) {
|
|
const start = file.getLineAndCharacterOfPosition(node.getStart(file)).line
|
|
const end = file.getLineAndCharacterOfPosition(node.getEnd()).line
|
|
for (let line = start; line <= end; line++) scriptLines.add(`${block.loc.start.line}:${line}`)
|
|
}
|
|
ts.forEachChild(node, visit)
|
|
}
|
|
visit(file)
|
|
}
|
|
const status = templateLines ? '模板待核对' : scriptLines.size ? '模板未检出,脚本待核对' : '未检出中文,待验收'
|
|
rows.push({ name, templateLines, scriptLines: scriptLines.size, status })
|
|
}
|
|
|
|
const count = (status) => rows.filter((row) => row.status === status).length
|
|
console.log('# 前端页面 i18n 进度\n')
|
|
console.log('此表按 `web/src/views` 下的 Vue 页面文件整理,是静态扫描快照,不代表完整翻译或验收。')
|
|
console.log('使用 `cd web && node scripts/i18n-progress.mjs` 可重新生成表格;更新此文件时同时核对实际界面和相关接口。\n')
|
|
console.log('此前检出中文的 22 个页面的保留项和核对结论见 [页面中文字符串核对记录](i18n-page-review)。\n')
|
|
console.log(`共 ${rows.length} 个页面:模板仍检出中文 ${count('模板待核对')} 个;模板未检出、脚本字符串仍需核对 ${count('模板未检出,脚本待核对')} 个;模板与脚本字符串均未检出 ${count('未检出中文,待验收')} 个。\n`)
|
|
console.log('- “模板中文行”统计去除 HTML 注释后,包含汉字的模板行数;一行可能包含多个文案,也可能是业务数据或条件表达式。')
|
|
console.log('- “脚本中文字符串行”统计 TypeScript 字符串和模板字符串中包含汉字的行数,不包括普通注释;其中可能是可编辑默认值、协议兼容映射或其他非界面文本。')
|
|
console.log('- 零并不证明页面已完成:共享组件、服务端返回的标签和错误、图表、导出内容、日期格式及真实语言切换仍需单独检查。')
|
|
console.log('- 按页面逐个核对并翻译;若该页面实际显示的固定文案由后端生成,再定位对应接口和消费者,兼顾兼容性后修改。用户数据、持久化值和协议标识不得直接翻译。\n')
|
|
console.log('| 页面文件 | 状态 | 模板中文行 | 脚本中文字符串行 |')
|
|
console.log('| --- | --- | ---: | ---: |')
|
|
for (const row of rows) console.log(`| [${row.name}](https://git.biss.click/biss/Academic-Affairs-System/src/branch/master/web/src/views/${row.name}) | ${row.status} | ${row.templateLines} | ${row.scriptLines} |`)
|