Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions app-engine/frontend/src/locale/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,27 @@ import i18n from 'i18next';
import { initReactI18next } from "react-i18next";
import en from './en_US.json';
import zh from './zh_CN.json';
import coreEn from '@fit-elsa/elsa-core/locales/en.json';
import coreZh from '@fit-elsa/elsa-core/locales/zh.json';
import reactEn from '@fit-elsa/elsa-react/locales/en.json';
import reactZh from '@fit-elsa/elsa-react/locales/zh.json';

const mergeTranslations = (...translationObjects) => {
// 从右向左合并(右侧优先级更高)
return translationObjects
.filter(obj => obj) // 过滤掉假值(undefined/null
.reduce((merged, current) => ({ ...merged, ...current }), {});
};

const resources = {
en: {
translation: en
translation: mergeTranslations(coreEn, reactEn, en) // 优先级顺序: en > reactEn > coreEn
},
zh: {
translation: zh
translation: mergeTranslations(coreZh, reactZh, zh) // 优先级顺序: zh > reactZh > coreZh
}
};

const getCookie = (cname) => {
const name = `${cname}=`;
const ca = document.cookie.split(';');
Expand Down