index.js 916 Bytes
Newer Older
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
import React, { PureComponent } from 'react';
import { FormattedMessage, setLocale, getLocale } from 'umi/locale';
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;
    const langMenu = (
      <Menu className={styles.menu} selectedKeys={[getLocale()]} onClick={this.changLang}>
        <Menu.Item key="zh-CN">中文</Menu.Item>
        <Menu.Item key="en-US">English</Menu.Item>
        <Menu.Item key="pt-BR">Português</Menu.Item>
      </Menu>
    );
    return (
      <Dropdown overlay={langMenu}>
        <span className={classNames(styles.dropdown, className)}>
          <FormattedMessage id="navbar.lang" /> <Icon type="down" />
        </span>
      </Dropdown>
    );
  }
}