mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 03:48:05 +08:00
feat: i18n demo
This commit is contained in:
parent
56b206b01f
commit
288d40df4a
@ -5,13 +5,30 @@ import enUS from './locales/en_US'
|
||||
/** 以中文为主,定义语言类型 */
|
||||
export type I18nLocaleType = typeof zhCN
|
||||
|
||||
// 深层递归合并,防止出现其他语言未覆盖问题
|
||||
const deepMerge = (...objects: Record<string, any>[]) => {
|
||||
const result: Record<string, any> = {}
|
||||
for (const obj of objects) {
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||
result[key] = deepMerge(result[key] || {}, obj[key])
|
||||
} else {
|
||||
result[key] = obj[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
// TODO 目前手动修改,后续抽离封装
|
||||
locale: 'zh-cn', //'en-us', // 默认显示语言
|
||||
locale: 'en-us', //'en-us', // 默认显示语言
|
||||
messages: {
|
||||
'zh-cn': zhCN,
|
||||
'en-us': enUS
|
||||
'en-us': deepMerge(zhCN, enUS)
|
||||
}
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user