feat(site): integrate multilingual content management / 集成多语言内容管理
完善官网、管理后台与后端的多语言内容编辑和发布流程,调整站点页面及相关接口,并同步数据库脚本。 新增容器部署配置,改用环境变量注入数据库凭据;补充仓库忽略规则,并停止跟踪本地环境文件和 Maven 构建产物。
This commit is contained in:
1 parent
4ee6e9ae83
commit
85083ab962
1056 files changed
+15449
-132933
No files matched your search
@@ -0,0 +1,81 @@
|
||||
import fs from 'node:fs/promises'
|
||||
import path from 'node:path'
|
||||
import process from 'node:process'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
function isPlainObject(v) {
|
||||
return v != null && typeof v === 'object' && !Array.isArray(v)
|
||||
}
|
||||
|
||||
function flattenKeys(obj, prefix = '') {
|
||||
const out = new Set()
|
||||
if (!isPlainObject(obj)) return out
|
||||
for (const k of Object.keys(obj)) {
|
||||
const next = prefix ? `${prefix}.${k}` : k
|
||||
const v = obj[k]
|
||||
if (isPlainObject(v)) {
|
||||
for (const sub of flattenKeys(v, next)) out.add(sub)
|
||||
} else {
|
||||
out.add(next)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function diff(a, b) {
|
||||
// items in a but not in b
|
||||
const out = []
|
||||
for (const x of a) if (!b.has(x)) out.push(x)
|
||||
out.sort()
|
||||
return out
|
||||
}
|
||||
|
||||
async function readJson(p) {
|
||||
const raw = await fs.readFile(p, 'utf8')
|
||||
return JSON.parse(raw)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const root = path.resolve(__dirname, '../src/locales')
|
||||
const files = {
|
||||
zh: path.join(root, 'zh.json'),
|
||||
en: path.join(root, 'en.json'),
|
||||
ja: path.join(root, 'ja.json')
|
||||
}
|
||||
|
||||
const [zh, en, ja] = await Promise.all([readJson(files.zh), readJson(files.en), readJson(files.ja)])
|
||||
|
||||
const keysZh = flattenKeys(zh)
|
||||
const keysEn = flattenKeys(en)
|
||||
const keysJa = flattenKeys(ja)
|
||||
|
||||
const missingEn = diff(keysZh, keysEn)
|
||||
const missingJa = diff(keysZh, keysJa)
|
||||
const extraEn = diff(keysEn, keysZh)
|
||||
const extraJa = diff(keysJa, keysZh)
|
||||
|
||||
const problems = []
|
||||
if (missingEn.length) problems.push({ title: 'en 缺少 key', items: missingEn })
|
||||
if (missingJa.length) problems.push({ title: 'ja 缺少 key', items: missingJa })
|
||||
if (extraEn.length) problems.push({ title: 'en 多余 key', items: extraEn })
|
||||
if (extraJa.length) problems.push({ title: 'ja 多余 key', items: extraJa })
|
||||
|
||||
if (problems.length) {
|
||||
console.error('[i18n-check] locales key mismatch found:')
|
||||
for (const p of problems) {
|
||||
console.error(`\n- ${p.title}(${p.items.length})`)
|
||||
for (const it of p.items) console.error(` - ${it}`)
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(`[i18n-check] OK: ${keysZh.size} keys in sync (zh/en/ja).`)
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
console.error('[i18n-check] Failed:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in new issue
Block a user