index.js
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import React, { PureComponent } from 'react';
import { formatMessage, setLocale, getLocale } from 'umi/locale';
import { Menu, Icon } from 'antd';
import classNames from 'classnames';
import HeaderDropdown from '../HeaderDropdown';
import styles from './index.less';
export default class SelectLang extends PureComponent {
changeLang = ({ key }) => {
setLocale(key);
};
render() {
const { className } = this.props;
const selectedLang = getLocale();
const langMenu = (
<Menu className={styles.menu} selectedKeys={[selectedLang]} onClick={this.changeLang}>
<Menu.Item key="zh-CN">
<span role="img" aria-label="简体中文">
🇨🇳
</span>{' '}
简体中文
</Menu.Item>
<Menu.Item key="zh-TW">
<span role="img" aria-label="繁体中文">
🇭🇰
</span>{' '}
繁体中文
</Menu.Item>
<Menu.Item key="en-US">
<span role="img" aria-label="English">
🇬🇧
</span>{' '}
English
</Menu.Item>
<Menu.Item key="pt-BR">
<span role="img" aria-label="Português">
🇵🇹
</span>{' '}
Português
</Menu.Item>
</Menu>
);
return (
<HeaderDropdown overlay={langMenu} placement="bottomRight">
<span className={classNames(styles.dropDown, className)}>
<Icon type="global" title={formatMessage({ id: 'navBar.lang' })} />
</span>
</HeaderDropdown>
);
}
}