index.js 1.26 KB
Newer Older
1
import React, { PureComponent } from 'react';
afc163's avatar
afc163 committed
2
import { formatMessage, FormattedMessage, setLocale, getLocale } from 'umi/locale';
3 4 5 6 7 8 9 10 11 12 13
import { Menu, Icon, Dropdown } from 'antd';
import classNames from 'classnames';
import styles from './index.less';

export default class SelectLang extends PureComponent {
  changLang = ({ key }) => {
    setLocale(key);
  };

  render() {
    const { className } = this.props;
14
    const selectedLang = getLocale();
15
    const langMenu = (
16 17 18 19 20 21 22 23 24 25 26 27 28
      <Menu className={styles.menu} selectedKeys={[selectedLang]} onClick={this.changLang}>
        <Menu.Item key="zh-CN">
          <FormattedMessage id="lang.simplified-chinese" />
        </Menu.Item>
        <Menu.Item key="zh-TW">
          <FormattedMessage id="lang.traditional-chinese" />
        </Menu.Item>
        <Menu.Item key="en-US">
          <FormattedMessage id="lang.english" />
        </Menu.Item>
        <Menu.Item key="pt-BR">
          <FormattedMessage id="lang.portuguese" />
        </Menu.Item>
29 30 31
      </Menu>
    );
    return (
afc163's avatar
afc163 committed
32
      <Dropdown overlay={langMenu} placement="bottomRight">
afc163's avatar
afc163 committed
33 34 35 36 37
        <Icon
          type="global"
          className={classNames(styles.dropDown, className)}
          title={formatMessage({ id: 'navBar.lang' })}
        />
38 39 40 41
      </Dropdown>
    );
  }
}