Skip to content

Commit d1553e4

Browse files
committed
add lang change in header
1 parent 3631bc2 commit d1553e4

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

site/theme/static/header.less

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
position: relative;
1616
z-index: 10;
1717
height: 64px;
18+
.ant-menu-overflowed-submenu {
19+
display: none;
20+
}
1821
}
1922

2023
#logo {
@@ -110,6 +113,14 @@
110113
border-radius: 32px;
111114
}
112115
}
116+
#lang {
117+
padding-top: 17px;
118+
margin-left: 32px;
119+
float: right;
120+
button {
121+
border-radius: 32px;
122+
}
123+
}
113124

114125
#preview-button {
115126
.ant-btn {

site/theme/template/Layout/Header.jsx

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types';
44
import { Link } from 'bisheng/router';
55
import axios from 'axios';
66
import { Row, Col, Icon, Menu, Button, Modal, Popover, Select } from 'antd';
7-
7+
import * as utils from '../utils';
88
import { enquireScreen, getLocalizedPathname } from '../utils';
99

1010
const { Option, OptGroup } = Select;
@@ -150,6 +150,23 @@ class Header extends React.Component {
150150
});
151151
};
152152

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+
153170
render() {
154171
const { inputValue, menuMode, menuVisible, searchOption, searching } = this.state;
155172
const { location, intl } = this.props;
@@ -188,7 +205,7 @@ class Header extends React.Component {
188205
<FormattedMessage id="app.header.menu.components" />
189206
</Link>
190207
</Menu.Item>
191-
<Menu.Item>
208+
<Menu.Item key="v1">
192209
<a href="https://v1.pro.ant.design" target="_blank" rel="noopener noreferrer">
193210
v1
194211
</a>
@@ -299,6 +316,11 @@ class Header extends React.Component {
299316
</Button>
300317
</a>
301318
</div>
319+
<div id="lang">
320+
<Button onClick={this.handleLangChange}>
321+
<FormattedMessage id="app.header.lang" />
322+
</Button>
323+
</div>
302324
{menuMode === 'horizontal' ? <div id="menu">{menu}</div> : null}
303325
</div>
304326
</Col>

0 commit comments

Comments
 (0)