feat: establish i18n foundation
This commit is contained in:
1 parent
3e7d6e43d6
commit
c7499f05e3
20 files changed
+520
-28
No files matched your search
@@ -0,0 +1,22 @@
|
||||
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).`)
|
||||
}
|
||||
Reference in new issue
Block a user