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

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

View File

@ -34,8 +34,16 @@ export const getTemplateByKey = (key: string) => {
if (Object.keys(message).includes(key)) {
return message[key]
}
console.error(`[i18n] Function getTemplateByKey(), key param ${key} is not existed.`)
return ''
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 ''
}
}
/**