feat: localize common labels across academic workflows

This commit is contained in:
biss committed 2026-11-01 21:07:16 +08:00
1 parent cbcd41182c
commit 5183158189
17 files changed
+248 -238

No files matched your search

+9 -1
View File
@@ -35,6 +35,13 @@ for (const name of ['TeachingMonitoringView.vue', 'AcademicPlanningView.vue', 'P
if (/\p{Script=Han}/u.test(template)) hardcoded.push(name)
}
const viewsDirectory = new URL('../src/views/', import.meta.url)
const missingBatchReferences = []
for (const name of readdirSync(viewsDirectory).filter((file) => file.endsWith('.vue'))) {
const source = readFileSync(new URL(name, viewsDirectory), 'utf8')
for (const match of source.matchAll(/t\(['"](batchBusiness\.[^'"]+)['"]/g)) {
if (!reference.has(match[1])) missingBatchReferences.push(`${name}: ${match[1]}`)
}
}
const fixedLocaleViews = readdirSync(viewsDirectory).filter((name) => name.endsWith('.vue') &&
/(?:toLocale(?:Date|Time)?String|DateTimeFormat|NumberFormat|Collator)\(['"]zh-CN['"]/.test(readFileSync(new URL(name, viewsDirectory), 'utf8')))
@@ -48,12 +55,13 @@ const english = new Map(values(enUS))
const placeholders = (value) => [...new Set([...String(value).matchAll(/\{(\w+)\}/g)].map((match) => match[1]))].sort().join(',')
const mismatched = values(zhCN).filter(([key, value]) => candidate.has(key) && placeholders(value) !== placeholders(english.get(key))).map(([key]) => key)
if (missing.length || extra.length || hardcoded.length || mismatched.length || fixedLocaleViews.length) {
if (missing.length || extra.length || hardcoded.length || mismatched.length || fixedLocaleViews.length || missingBatchReferences.length) {
if (missing.length) console.error(`en-US missing keys:\n${missing.join('\n')}`)
if (extra.length) console.error(`en-US extra keys:\n${extra.join('\n')}`)
if (hardcoded.length) console.error(`Hardcoded Chinese in completed views:\n${hardcoded.join('\n')}`)
if (mismatched.length) console.error(`Interpolation parameters differ:\n${mismatched.join('\n')}`)
if (fixedLocaleViews.length) console.error(`Fixed Chinese display formats:\n${fixedLocaleViews.join('\n')}`)
if (missingBatchReferences.length) console.error(`Missing batch translations:\n${missingBatchReferences.join('\n')}`)
process.exitCode = 1
} else {
console.log(`i18n catalogs match (${reference.size} keys).`)