@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
4
4
import { Link } from 'bisheng/router' ;
5
5
import axios from 'axios' ;
6
6
import { Row , Col , Icon , Menu , Button , Modal , Popover , Select } from 'antd' ;
7
-
7
+ import * as utils from '../utils' ;
8
8
import { enquireScreen , getLocalizedPathname } from '../utils' ;
9
9
10
10
const { Option, OptGroup } = Select ;
@@ -150,6 +150,23 @@ class Header extends React.Component {
150
150
} ) ;
151
151
} ;
152
152
153
+ handleLangChange = ( ) => {
154
+ const { pathname } = this . props . location ;
155
+ const currentProtocol = `${ window . location . protocol } //` ;
156
+ const currentHref = window . location . href . substr ( currentProtocol . length ) ;
157
+
158
+ if ( utils . isLocalStorageNameSupported ( ) ) {
159
+ localStorage . setItem ( 'locale' , utils . isZhCN ( pathname ) ? 'en-US' : 'zh-CN' ) ;
160
+ }
161
+
162
+ window . location . href =
163
+ currentProtocol +
164
+ currentHref . replace (
165
+ window . location . pathname ,
166
+ utils . getLocalizedPathname ( pathname , ! utils . isZhCN ( pathname ) )
167
+ ) ;
168
+ } ;
169
+
153
170
render ( ) {
154
171
const { inputValue, menuMode, menuVisible, searchOption, searching } = this . state ;
155
172
const { location, intl } = this . props ;
@@ -188,7 +205,7 @@ class Header extends React.Component {
188
205
< FormattedMessage id = "app.header.menu.components" />
189
206
</ Link >
190
207
</ Menu . Item >
191
- < Menu . Item >
208
+ < Menu . Item key = "v1" >
192
209
< a href = "https://v1.pro.ant.design" target = "_blank" rel = "noopener noreferrer" >
193
210
v1
194
211
</ a >
@@ -299,6 +316,11 @@ class Header extends React.Component {
299
316
</ Button >
300
317
</ a >
301
318
</ div >
319
+ < div id = "lang" >
320
+ < Button onClick = { this . handleLangChange } >
321
+ < FormattedMessage id = "app.header.lang" />
322
+ </ Button >
323
+ </ div >
302
324
{ menuMode === 'horizontal' ? < div id = "menu" > { menu } </ div > : null }
303
325
</ div >
304
326
</ Col >
0 commit comments