index.js 1.48 KB
Newer Older
1
import React, { PureComponent } from 'react';
2
import { formatMessage, setLocale, getLocale } from 'umi/locale';
3 4 5 6 7
import { Menu, Icon, Dropdown } from 'antd';
import classNames from 'classnames';
import styles from './index.less';

export default class SelectLang extends PureComponent {
David Z. Han's avatar
David Z. Han committed
8
  changeLang = ({ key }) => {
9 10 11 12 13
    setLocale(key);
  };

  render() {
    const { className } = this.props;
14
    const selectedLang = getLocale();
15
    const langMenu = (
David Z. Han's avatar
David Z. Han committed
16
      <Menu className={styles.menu} selectedKeys={[selectedLang]} onClick={this.changeLang}>
17
        <Menu.Item key="zh-CN">
18 19 20 21
          <span role="img" aria-label="简体中文">
            🇨🇳
          </span>{' '}
          简体中文
22 23
        </Menu.Item>
        <Menu.Item key="zh-TW">
24 25 26 27
          <span role="img" aria-label="繁体中文">
            🇭🇰
          </span>{' '}
          繁体中文
28 29
        </Menu.Item>
        <Menu.Item key="en-US">
30 31 32 33
          <span role="img" aria-label="English">
            🇬🇧
          </span>{' '}
          English
34 35
        </Menu.Item>
        <Menu.Item key="pt-BR">
36 37 38 39
          <span role="img" aria-label="Português">
            🇵🇹
          </span>{' '}
          Português
40
        </Menu.Item>
41 42 43
      </Menu>
    );
    return (
afc163's avatar
afc163 committed
44
      <Dropdown overlay={langMenu} placement="bottomRight">
afc163's avatar
afc163 committed
45 46 47 48 49
        <Icon
          type="global"
          className={classNames(styles.dropDown, className)}
          title={formatMessage({ id: 'navBar.lang' })}
        />
50 51 52 53
      </Dropdown>
    );
  }
}