Files
Academic-Affairs-System/web/scripts/check-i18n.mjs
T

23 lines
844 B
JavaScript

import enUS from '../src/i18n/messages/en-US.ts'
import zhCN from '../src/i18n/messages/zh-CN.ts'
function flatten(value, prefix = '') {
return Object.entries(value).flatMap(([key, child]) => {
const path = prefix ? `${prefix}.${key}` : key
return child && typeof child === 'object' ? flatten(child, path) : [path]
})
}
const reference = new Set(flatten(zhCN))
const candidate = new Set(flatten(enUS))
const missing = [...reference].filter((key) => !candidate.has(key))
const extra = [...candidate].filter((key) => !reference.has(key))
if (missing.length || extra.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')}`)
process.exitCode = 1
} else {
console.log(`i18n catalogs match (${reference.size} keys).`)
}