File tree Expand file tree Collapse file tree
packages/neuron-ui/src/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import i18n from 'i18next'
22import { initReactI18next } from 'react-i18next'
3+ import { language } from 'utils/localCache'
34import zh from 'locales/zh.json'
45import en from 'locales/en.json'
56
@@ -8,7 +9,7 @@ i18n.use(initReactI18next).init({
89 en,
910 zh,
1011 } ,
11- fallbackLng : 'en' ,
12+ fallbackLng : language . load ( ) ,
1213 interpolation : {
1314 escapeValue : false ,
1415 } ,
Original file line number Diff line number Diff line change 88 currentNetworkID as currentNetworkIDCache ,
99 currentWallet as currentWalletCache ,
1010 systemScript as systemScriptCache ,
11+ language as languageCache ,
1112} from 'utils/localCache'
1213import { Routes , ConnectionStatus } from 'utils/const'
1314import { WalletWizardPath } from 'components/WalletWizard'
@@ -25,7 +26,7 @@ const intializeApp = ({
2526 dispatch : StateDispatch
2627} ) => {
2728 const {
28- locale = 'zh-CN' ,
29+ locale,
2930 networks = [ ] ,
3031 currentNetworkID : networkID = '' ,
3132 wallets = [ ] ,
@@ -36,8 +37,9 @@ const intializeApp = ({
3637 connectionStatus = false ,
3738 codeHash = '' ,
3839 } = initializedState
39- if ( locale !== i18n . language ) {
40+ if ( locale && locale !== i18n . language ) {
4041 i18n . changeLanguage ( locale )
42+ languageCache . save ( locale )
4143 }
4244 if ( wallet && wallet . id ) {
4345 history . push ( Routes . Overview )
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export enum LocalCacheKey {
66 CurrentWallet = 'currentWallet' ,
77 CurrentNetworkID = 'currentNetworkID' ,
88 SystemScript = 'systemScript' ,
9+ Language = 'lng' ,
910}
1011enum AddressBookVisibility {
1112 Invisible = '0' ,
@@ -141,6 +142,16 @@ export const systemScript = {
141142 } ,
142143}
143144
145+ export const language = {
146+ save : ( lng : string ) => {
147+ window . localStorage . setItem ( LocalCacheKey . Language , lng )
148+ return true
149+ } ,
150+ load : ( ) => {
151+ return window . localStorage . getItem ( LocalCacheKey . Language ) || 'en'
152+ } ,
153+ }
154+
144155export default {
145156 LocalCacheKey,
146157 addressBook,
@@ -150,4 +161,5 @@ export default {
150161 currentWallet,
151162 currentNetworkID,
152163 systemScript,
164+ language,
153165}
You can’t perform that action at this time.
0 commit comments