1
1
import { hot } from 'react-hot-loader/root' ;
2
2
import { Spin , message } from 'antd' ;
3
- import React , { Suspense , lazy , useState , useEffect } from 'react' ;
3
+ import React , { Suspense , lazy , useEffect } from 'react' ;
4
4
import ReactDom from 'react-dom' ;
5
5
import { Route , BrowserRouter as Router , Switch , useHistory } from 'react-router-dom' ;
6
6
import { observer } from 'mobx-react-lite' ;
7
7
import dayjs from 'dayjs' ;
8
- import intl from 'react-intl-universal' ;
9
8
import duration from 'dayjs/plugin/duration' ;
10
9
import Cookie from 'js-cookie' ;
11
10
import { trackPageView } from '@app/utils/stat' ;
11
+ import { I18nProvider , getI18n } from '@vesoft-inc/i18n' ;
12
12
import { INTL_LOCALES } from '@app/config/constants' ;
13
- import { LanguageContext } from '@app/context' ;
14
13
import { useStore } from '@app/stores' ;
15
14
import AuthorizedRoute from './AuthorizedRoute' ;
16
15
import rootStore , { StoreProvider } from './stores' ;
@@ -24,44 +23,21 @@ message.config({
24
23
maxCount : 1 ,
25
24
} ) ;
26
25
const defaultLanguage = Cookie . get ( 'lang' ) || document . documentElement . getAttribute ( 'lang' ) ;
27
- intl . init ( {
28
- currentLocale : defaultLanguage || 'EN_US' ,
29
- locales : INTL_LOCALES ,
30
- } ) ;
31
-
32
-
26
+ const { initI18n } = getI18n ( ) ;
27
+ initI18n ( defaultLanguage , INTL_LOCALES ) ;
33
28
const PageRoot = observer ( ( ) => {
34
29
const { global : { version } } = useStore ( ) ;
35
- const [ currentLocale , setCurrentLocale ] = useState (
36
- defaultLanguage || 'EN-US' ,
37
- ) ;
38
-
39
- const toggleLanguage = ( locale : string ) => {
40
- Cookie . set ( 'lang' , locale ) ;
41
- setCurrentLocale ( locale ) ;
42
- intl
43
- . init ( {
44
- currentLocale : locale ,
45
- locales : INTL_LOCALES ,
46
- } ) ;
47
- } ;
48
-
49
30
useEffect ( ( ) => {
50
31
trackPageView ( `Studio/v${ version } ` ) ;
51
32
} , [ ] ) ;
52
33
53
34
return (
54
35
< StoreProvider value = { rootStore } >
55
- < LanguageContext . Provider
56
- value = { {
57
- currentLocale,
58
- toggleLanguage,
59
- } }
60
- >
36
+ < I18nProvider locales = { INTL_LOCALES } >
61
37
< Router >
62
38
< App />
63
39
</ Router >
64
- </ LanguageContext . Provider >
40
+ </ I18nProvider >
65
41
</ StoreProvider >
66
42
) ;
67
43
} ) ;
0 commit comments