2023-01-11 02:18:59 +01:00
|
|
|
import { Button, Dropdown, Item, Flexbox } from 'react-basics';
|
2022-03-01 05:54:32 +01:00
|
|
|
import useLocale from 'hooks/useLocale';
|
|
|
|
import { DEFAULT_LOCALE } from 'lib/constants';
|
2022-11-08 07:35:51 +01:00
|
|
|
import { languages } from 'lib/lang';
|
2023-03-22 22:05:55 +01:00
|
|
|
import useMessages from 'hooks/useMessages';
|
2023-01-11 02:18:59 +01:00
|
|
|
|
2023-04-21 17:00:42 +02:00
|
|
|
export function LanguageSetting() {
|
2023-03-22 22:05:55 +01:00
|
|
|
const { formatMessage, labels } = useMessages();
|
2022-03-01 05:54:32 +01:00
|
|
|
const { locale, saveLocale } = useLocale();
|
2023-01-11 02:18:59 +01:00
|
|
|
const options = Object.keys(languages);
|
2022-03-01 05:54:32 +01:00
|
|
|
|
2023-01-11 17:33:43 +01:00
|
|
|
const handleReset = () => saveLocale(DEFAULT_LOCALE);
|
|
|
|
|
|
|
|
const renderValue = value => languages[value].label;
|
2022-03-01 05:54:32 +01:00
|
|
|
|
|
|
|
return (
|
2023-04-13 02:43:08 +02:00
|
|
|
<Flexbox gap={10}>
|
2023-01-19 00:05:39 +01:00
|
|
|
<Dropdown
|
|
|
|
items={options}
|
|
|
|
value={locale}
|
|
|
|
renderValue={renderValue}
|
|
|
|
onChange={saveLocale}
|
|
|
|
menuProps={{ style: { height: 300, width: 300 } }}
|
|
|
|
>
|
2023-01-11 02:18:59 +01:00
|
|
|
{item => <Item key={item}>{languages[item].label}</Item>}
|
|
|
|
</Dropdown>
|
2023-01-25 16:42:46 +01:00
|
|
|
<Button onClick={handleReset}>{formatMessage(labels.reset)}</Button>
|
2023-01-11 02:18:59 +01:00
|
|
|
</Flexbox>
|
2022-03-01 05:54:32 +01:00
|
|
|
);
|
|
|
|
}
|
2023-04-21 17:00:42 +02:00
|
|
|
|
|
|
|
export default LanguageSetting;
|