Skip to content

Commit d5e7e00

Browse files
committed
fix: improve language switch
1 parent a9dc9f6 commit d5e7e00

File tree

1 file changed

+6
-2
lines changed
  • frontend/src/app/pages/MainPage/Navbar

1 file changed

+6
-2
lines changed

frontend/src/app/pages/MainPage/Navbar/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { downloadFile } from 'app/utils/fetch';
4747
import { BASE_RESOURCE_URL } from 'globalConstants';
4848
import { changeLang } from 'locales/i18n';
4949
import React, { cloneElement, useCallback, useMemo, useState } from 'react';
50+
import { useTranslation } from 'react-i18next';
5051
import { useDispatch, useSelector } from 'react-redux';
5152
import { NavLink, useHistory, useRouteMatch } from 'react-router-dom';
5253
import styled from 'styled-components/macro';
@@ -84,6 +85,7 @@ export function Navbar() {
8485
const [modifyPasswordVisible, setModifyPasswordVisible] = useState(false);
8586
const dispatch = useDispatch();
8687
const history = useHistory();
88+
const { i18n } = useTranslation();
8789
const systemInfo = useSelector(selectSystemInfo);
8890
const orgId = useSelector(selectOrgId);
8991
const currentOrganization = useSelector(selectCurrentOrganization);
@@ -228,7 +230,9 @@ export function Navbar() {
228230
break;
229231
case 'zh':
230232
case 'en':
231-
changeLang(key);
233+
if (i18n.language !== key) {
234+
changeLang(key);
235+
}
232236
break;
233237
case 'dark':
234238
case 'light':
@@ -238,7 +242,7 @@ export function Navbar() {
238242
break;
239243
}
240244
},
241-
[dispatch, history, handleChangeThemeFn],
245+
[dispatch, history, i18n, handleChangeThemeFn],
242246
);
243247

244248
const onSetPolling = useCallback(

0 commit comments

Comments
 (0)