2023-01-11 02:18:59 +01:00
|
|
|
import { useIntl, defineMessages } from 'react-intl';
|
|
|
|
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';
|
2022-03-01 05:54:32 +01:00
|
|
|
|
2023-01-11 02:18:59 +01:00
|
|
|
const messages = defineMessages({
|
|
|
|
reset: { id: 'label.reset', defaultMessage: 'Reset' },
|
|
|
|
});
|
|
|
|
|
2022-03-01 05:54:32 +01:00
|
|
|
export default function LanguageSetting() {
|
2023-01-11 02:18:59 +01:00
|
|
|
const { formatMessage } = useIntl();
|
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
|
|
|
|
|
|
|
function handleReset() {
|
|
|
|
saveLocale(DEFAULT_LOCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-01-11 02:18:59 +01:00
|
|
|
<Flexbox gap={10} style={{ width: 400 }}>
|
|
|
|
<Dropdown items={options} value={locale} onChange={saveLocale}>
|
|
|
|
{item => <Item key={item}>{languages[item].label}</Item>}
|
|
|
|
</Dropdown>
|
|
|
|
<Button onClick={handleReset}>{formatMessage(messages.reset)}</Button>
|
|
|
|
</Flexbox>
|
2022-03-01 05:54:32 +01:00
|
|
|
);
|
|
|
|
}
|