Skip to content

Commit 753079f

Browse files
committed
fix(projects): failed to switch sidebar language
1 parent 0d855e7 commit 753079f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/layouts/base-layout/MenuUtil.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import type { ElegantConstRoute } from '@elegant-router/types';
22

3-
import { $t } from '@/locales';
4-
53
/**
64
* Get global menus by auth routes
75
*
@@ -30,11 +28,15 @@ export function getGlobalMenusByAuthRoutes(routes: ElegantConstRoute[]) {
3028
*
3129
* @param route
3230
*/
31+
3332
export function getGlobalMenuByBaseRoute(route: ElegantConstRoute): App.Global.Menu {
3433
const { name } = route;
3534
const { title, i18nKey, icon = import.meta.env.VITE_MENU_ICON, localIcon } = route.meta ?? {};
3635

37-
const label = i18nKey ? $t(i18nKey) : title;
36+
// eslint-disable-next-line
37+
const { t } = useTranslation()
38+
// eslint-disable-next-line
39+
const label = i18nKey ? t(i18nKey) : title;
3840
const menu: App.Global.Menu = {
3941
key: name,
4042
label: <BeyondHiding title={label} />,

src/locales/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import i18n from 'i18next';
22
import { initReactI18next } from 'react-i18next';
33
import { localStg } from '@/utils/storage';
44
import locales from './locale';
5+
56
/** Setup plugin i18n */
67
export function setupI18n() {
78
i18n.use(initReactI18next).init({
@@ -12,7 +13,9 @@ export function setupI18n() {
1213
}
1314
});
1415
}
16+
1517
export const $t = i18n.t;
18+
1619
export function setLng(locale: App.I18n.LangType) {
1720
i18n.changeLanguage(locale);
1821
}

0 commit comments

Comments
 (0)