From f829d38433adaf05764831ad1402a7e5690d54e7 Mon Sep 17 00:00:00 2001 From: lingting Date: Tue, 19 Oct 2021 17:07:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(I18n):=20=E6=B7=BB=E5=8A=A0=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=20=E5=BC=80=E5=85=B3=20=E7=9A=84=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.ts | 3 +++ src/components/RightContent/index.tsx | 3 ++- src/layouts/BasicLayout.tsx | 7 +++++++ src/pages/user/Login/index.tsx | 2 +- src/utils/I18nUtils.ts | 4 ++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/config/settings.ts b/config/settings.ts index a883459..923b359 100644 --- a/config/settings.ts +++ b/config/settings.ts @@ -4,6 +4,8 @@ export type ProjectSetting = LayoutSettings & { pwa?: boolean; logo?: string; historyType: 'browser' | 'hash' | 'memory'; + // 是否开启国际化 + i18n: boolean; // 默认语言 defaultLocal: 'zh-CN' | 'en-US'; // 是否展示水印 @@ -29,6 +31,7 @@ const Settings: ProjectSetting = { pwa: false, logo: './logo.svg', historyType: 'hash', + i18n: true, defaultLocal: 'zh-CN', waterMark: true, multiTab: true, diff --git a/src/components/RightContent/index.tsx b/src/components/RightContent/index.tsx index 9dba02a..8c0b4e1 100644 --- a/src/components/RightContent/index.tsx +++ b/src/components/RightContent/index.tsx @@ -7,6 +7,7 @@ import Avatar from './AvatarDropdown'; import styles from './index.less'; import SettingDrawer from '@/components/SettingDrawer'; import FullScreen from '../FullScreen'; +import { settings } from '@/utils/ConfigUtils'; const GlobalHeaderRight: React.FC = () => { const { initialState } = useModel('@@initialState'); @@ -40,7 +41,7 @@ const GlobalHeaderRight: React.FC = () => { {/* 如果不需要退出确认. 移除 exitConfirm 即可 */} - + {settings.i18n && } = (props) => { const [collapsed, setCollapsed] = useState(false); const [reload, setReload] = useState(false); I18n.setIntl(useIntl()); + + // 国际化关闭, 当前语言与默认语言不符 + if (!settings.i18n && I18n.getLocal() !== settings.defaultLocal) { + // 切换语言 + I18n.setLocal(settings.defaultLocal); + } + const { initialState, setInitialState } = useModel('@@initialState'); const [keepAlivePropsState, keepAlivePropsDispatch] = useReducer( (_state: any, newVal: any) => newVal, diff --git a/src/pages/user/Login/index.tsx b/src/pages/user/Login/index.tsx index dba0674..542d00d 100644 --- a/src/pages/user/Login/index.tsx +++ b/src/pages/user/Login/index.tsx @@ -118,7 +118,7 @@ const Login: React.FC = () => { return (
-
+ { + setLocale(local); + }, text: (key: string, params?: Record, defaultMessage = key) => { return I18n.getIntl().formatMessage({ id: key, defaultMessage }, params); },