Files
Homarr/src/components/Settings/LanguageSwitch.tsx

85 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-08-18 21:46:46 +02:00
import { Group, Image, Select, Stack, Text } from '@mantine/core';
import { showNotification } from '@mantine/notifications';
import { IconLanguage } from '@tabler/icons';
import { forwardRef, useState } from 'react';
2022-08-22 09:50:54 +02:00
import { useTranslation } from 'next-i18next';
2022-08-18 21:46:46 +02:00
export default function LanguageSwitch() {
2022-08-22 09:50:54 +02:00
const { t, i18n } = useTranslation('settings/general/internationalization');
/*const { language, languages, changeLanguage } = i18n;
2022-08-18 21:46:46 +02:00
const [selectedLanguage, setSelectedLanguage] = useState<string | null>(language);
const data = languages.map((language) => ({
image: `https://countryflagsapi.com/png/${language.split('-').pop()}`,
2022-08-22 09:50:54 +02:00
label: 'JA',
2022-08-18 21:46:46 +02:00
value: language,
2022-08-22 09:50:54 +02:00
}));*/
2022-08-18 21:46:46 +02:00
const onChangeSelect = (value: string) => {
2022-08-22 09:50:54 +02:00
//setSelectedLanguage(value);
2022-08-18 21:46:46 +02:00
2022-08-22 09:50:54 +02:00
const languageName = 'JA IS HALZ SCHEISSE NE';
2022-08-18 21:46:46 +02:00
2022-08-22 09:50:54 +02:00
/*changeLanguage(value)
2022-08-18 21:46:46 +02:00
.then(() => {
showNotification({
title: 'Language changed',
message: `You changed the language to '${languageName}'`,
color: 'green',
autoClose: 5000,
});
})
.catch((err) => {
showNotification({
title: 'Failed to change language',
message: `Failed to change to '${languageName}', Error:'${err}`,
color: 'red',
autoClose: 5000,
});
2022-08-22 09:50:54 +02:00
});*/
2022-08-18 21:46:46 +02:00
};
return (
<Stack>
<Select
icon={<IconLanguage size={18} />}
2022-08-22 09:50:54 +02:00
label={t('label')}
data={[
{
value: 'uwu',
label: 'asdf',
},
]}
2022-08-18 21:46:46 +02:00
itemComponent={SelectItem}
nothingFound="Nothing found"
onChange={onChangeSelect}
2022-08-22 09:50:54 +02:00
/*
2022-08-18 21:46:46 +02:00
value={selectedLanguage}
defaultValue={language}
2022-08-22 09:50:54 +02:00
*/
2022-08-18 21:46:46 +02:00
/>
</Stack>
);
}
interface ItemProps extends React.ComponentPropsWithoutRef<'div'> {
image: string;
label: string;
}
const SelectItem = forwardRef<HTMLDivElement, ItemProps>(
({ image, label, ...others }: ItemProps, ref) => (
<div ref={ref} {...others}>
<Group noWrap>
<Image src={image} width={30} height={20} radius="xs" />
<div>
<Text size="sm">{label}</Text>
</div>
</Group>
</div>
)
);