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

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

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