2020-09-21 06:31:53 +02:00
|
|
|
import React from 'react';
|
2021-06-30 03:41:34 +02:00
|
|
|
import { languages } from 'lib/lang';
|
2020-09-17 09:17:11 +02:00
|
|
|
import useLocale from 'hooks/useLocale';
|
2020-09-21 06:31:53 +02:00
|
|
|
import MenuButton from 'components/common/MenuButton';
|
2020-09-17 09:17:11 +02:00
|
|
|
import Globe from 'assets/globe.svg';
|
2020-10-02 21:15:42 +02:00
|
|
|
import styles from './LanguageButton.module.css';
|
2020-09-07 10:22:16 +02:00
|
|
|
|
2020-09-21 06:31:53 +02:00
|
|
|
export default function LanguageButton() {
|
2021-06-30 03:41:34 +02:00
|
|
|
const { locale, saveLocale } = useLocale();
|
|
|
|
const menuOptions = Object.keys(languages).map(key => ({ ...languages[key], value: key }));
|
2020-09-07 10:22:16 +02:00
|
|
|
|
|
|
|
function handleSelect(value) {
|
2021-06-30 03:41:34 +02:00
|
|
|
saveLocale(value);
|
2020-09-07 10:22:16 +02:00
|
|
|
}
|
|
|
|
|
2021-05-20 22:21:30 +02:00
|
|
|
switch (locale) {
|
2021-05-21 19:55:37 +02:00
|
|
|
case 'zh-CN':
|
2021-05-22 03:28:20 +02:00
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-sc/chinese-simplified-400.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-sc/chinese-simplified-500.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-sc/chinese-simplified-700.css');
|
2021-05-20 22:21:30 +02:00
|
|
|
break;
|
|
|
|
case 'zh-TW':
|
2021-05-22 03:28:20 +02:00
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-tc/chinese-traditional-400.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-tc/chinese-traditional-500.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-tc/chinese-traditional-700.css');
|
2021-05-20 22:21:30 +02:00
|
|
|
break;
|
|
|
|
case 'ja-JP':
|
2021-05-22 03:28:20 +02:00
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-jp/japanese-400.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-jp/japanese-500.css');
|
|
|
|
import(/* webpackMode: "eager" */ '@fontsource/noto-sans-jp/japanese-700.css');
|
2021-05-20 22:21:30 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-09-07 10:22:16 +02:00
|
|
|
return (
|
2021-05-20 22:21:30 +02:00
|
|
|
<MenuButton
|
|
|
|
icon={<Globe />}
|
|
|
|
options={menuOptions}
|
|
|
|
value={locale}
|
|
|
|
menuClassName={styles.menu}
|
|
|
|
onSelect={handleSelect}
|
2021-11-04 23:55:12 +01:00
|
|
|
hideLabel
|
2021-05-20 22:21:30 +02:00
|
|
|
/>
|
2020-09-07 10:22:16 +02:00
|
|
|
);
|
|
|
|
}
|