index.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import './index.less'
  2. import { Icon, Menu, Dropdown } from 'ant-design-vue'
  3. import { i18nRender } from '@/locales'
  4. import i18nMixin from '@/store/i18n-mixin'
  5. const locales = ['zh-CN', 'zh-TW', 'en-US', 'pt-BR']
  6. const languageLabels = {
  7. 'zh-CN': '简体中文',
  8. 'zh-TW': '繁体中文',
  9. 'en-US': 'English',
  10. 'pt-BR': 'Português'
  11. }
  12. // eslint-disable-next-line
  13. const languageIcons = {
  14. 'zh-CN': '🇨🇳',
  15. 'zh-TW': '🇭🇰',
  16. 'en-US': '🇺🇸',
  17. 'pt-BR': '🇧🇷'
  18. }
  19. const SelectLang = {
  20. props: {
  21. prefixCls: {
  22. type: String,
  23. default: 'ant-pro-drop-down'
  24. }
  25. },
  26. name: 'SelectLang',
  27. mixins: [i18nMixin],
  28. render () {
  29. const { prefixCls } = this
  30. const changeLang = ({ key }) => {
  31. this.setLang(key)
  32. }
  33. const langMenu = (
  34. <Menu class={['menu', 'ant-pro-header-menu']} selectedKeys={[this.currentLang]} onClick={changeLang}>
  35. {locales.map(locale => (
  36. <Menu.Item key={locale}>
  37. <span role="img" aria-label={languageLabels[locale]}>
  38. {languageIcons[locale]}
  39. </span>{' '}
  40. {languageLabels[locale]}
  41. </Menu.Item>
  42. ))}
  43. </Menu>
  44. )
  45. return (
  46. <Dropdown overlay={langMenu} placement="bottomRight">
  47. <span class={prefixCls}>
  48. <Icon type="global" title={i18nRender('navBar.lang')} />
  49. </span>
  50. </Dropdown>
  51. )
  52. }
  53. }
  54. export default SelectLang