Skip to content

Commit eca8e9f

Browse files
authored
[frontend] 使用elsa导出的i18n文件 (#182)
* [frontend] 使用elsa导出的i18n文件 * [frontend] 检视意见修复
1 parent c1b27b2 commit eca8e9f

File tree

1 file changed

+14
-2
lines changed
  • app-engine/frontend/src/locale

1 file changed

+14
-2
lines changed

app-engine/frontend/src/locale/i18n.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,27 @@ import i18n from 'i18next';
77
import { initReactI18next } from "react-i18next";
88
import en from './en_US.json';
99
import zh from './zh_CN.json';
10+
import coreEn from '@fit-elsa/elsa-core/locales/en.json';
11+
import coreZh from '@fit-elsa/elsa-core/locales/zh.json';
12+
import reactEn from '@fit-elsa/elsa-react/locales/en.json';
13+
import reactZh from '@fit-elsa/elsa-react/locales/zh.json';
14+
15+
const mergeTranslations = (...translationObjects) => {
16+
// 从右向左合并(右侧优先级更高)
17+
return translationObjects
18+
.filter(obj => obj) // 过滤掉假值(undefined/null
19+
.reduce((merged, current) => ({ ...merged, ...current }), {});
20+
};
1021

1122
const resources = {
1223
en: {
13-
translation: en
24+
translation: mergeTranslations(coreEn, reactEn, en) // 优先级顺序: en > reactEn > coreEn
1425
},
1526
zh: {
16-
translation: zh
27+
translation: mergeTranslations(coreZh, reactZh, zh) // 优先级顺序: zh > reactZh > coreZh
1728
}
1829
};
30+
1931
const getCookie = (cname) => {
2032
const name = `${cname}=`;
2133
const ca = document.cookie.split(';');

0 commit comments

Comments
 (0)