fix: 修复i18n格式化错误

This commit is contained in:
Baobhan Sith
2025-05-12 00:08:02 +08:00
parent 564db89d0f
commit e0bc12dcc3
2 changed files with 29 additions and 2 deletions
@@ -0,0 +1,23 @@
import zhCN from '../locales/zh-CN.json';
import enUS from '../locales/en-US.json';
import jaJP from '../locales/ja-JP.json';
const languages = {
'zh-CN': zhCN,
'en-US': enUS,
'ja-JP': jaJP,
};
export function getTranslation(key: string, locale: string = 'zh-CN'): string {
const keys = key.split('.');
let current: any = languages[locale as keyof typeof languages] || languages['zh-CN'];
for (const k of keys) {
current = current[k];
if (!current) {
return key;
}
}
return current;
}