feat: 支持多语言文件深层写法

This commit is contained in:
Joker 2024-09-17 23:55:04 +02:00
parent deda75ffdd
commit eb816e4a78

View File

@ -34,9 +34,17 @@ export const getTemplateByKey = (key: string) => {
if (Object.keys(message).includes(key)) {
return message[key]
}
try {
const keyList = key.split('.')
return keyList.reduce((pre, cur) => {
return pre[cur]
}, message)
} catch (error) {
console.error(`[i18n] Function getTemplateByKey(), key param ${key} is not existed.`)
return ''
}
}
/**
* formatI18n('我是{name},身高{detail.height},体重{detail.weight}',{name:'张三',detail:{height:178,weight:'75kg'}})