@@ -5,12 +5,17 @@ import { IReduxState } from './store';
5
5
import { useSelector } from 'react-redux' ;
6
6
import { StyledEngineProvider , ThemeProvider } from '@mui/system' ;
7
7
import { EmptyBox , HeaderProgress , SpinIndicator } from '@actiontech/shared' ;
8
- import zhCN from 'antd/locale/zh_CN' ;
8
+ import antd_zh_CN from 'antd/locale/zh_CN' ;
9
+ import antd_en_US from 'antd/locale/en_US' ;
9
10
import {
10
11
useChangeTheme ,
11
12
useNotificationContext
12
13
} from '@actiontech/shared/lib/hooks' ;
13
- import { SupportTheme , UserRolesType } from '@actiontech/shared/lib/enum' ;
14
+ import {
15
+ SupportLanguage ,
16
+ SupportTheme ,
17
+ UserRolesType
18
+ } from '@actiontech/shared/lib/enum' ;
14
19
import Nav from './page/Nav' ;
15
20
import {
16
21
useCurrentUser ,
@@ -34,6 +39,7 @@ import dayjs from 'dayjs';
34
39
import 'dayjs/locale/zh-cn' ;
35
40
import updateLocale from 'dayjs/plugin/updateLocale' ;
36
41
import { PermissionReduxState } from '@actiontech/shared/lib/types/common.type' ;
42
+ import i18n , { getPreferredLanguages } from './locale' ;
37
43
38
44
import './index.less' ;
39
45
@@ -69,6 +75,15 @@ function App() {
69
75
token : state . user . token
70
76
} ) ) ;
71
77
78
+ const { currentLanguage, antdLanguage } = useMemo ( ( ) => {
79
+ const lang = getPreferredLanguages ( ) ?. [ 0 ] ?? SupportLanguage . zhCN ;
80
+
81
+ return {
82
+ currentLanguage : lang ,
83
+ antdLanguage : lang === SupportLanguage . enUS ? antd_en_US : antd_zh_CN
84
+ } ;
85
+ } , [ ] ) ;
86
+
72
87
const { notificationContextHolder } = useNotificationContext ( ) ;
73
88
74
89
const { getUserBySession } = useSessionUser ( ) ;
@@ -161,14 +176,18 @@ function App() {
161
176
}
162
177
} , [ getUserBySession , token , updateDriverList , updateFeaturePermission ] ) ;
163
178
179
+ useEffect ( ( ) => {
180
+ i18n . changeLanguage ( currentLanguage ) ;
181
+ } , [ currentLanguage ] ) ;
182
+
164
183
return (
165
184
< Wrapper >
166
185
< StyleProvider
167
186
hashPriority = "high"
168
187
transformers = { [ legacyLogicalPropertiesTransformer ] }
169
188
>
170
189
< ConfigProvider
171
- locale = { zhCN }
190
+ locale = { antdLanguage }
172
191
theme = { {
173
192
algorithm :
174
193
theme === SupportTheme . DARK
0 commit comments