1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2025-01-09 17:37:40 +01:00
smov/src/pages/parts/settings/LocalePart.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-11-26 16:33:04 +01:00
import { useTranslation } from "react-i18next";
import { FlagIcon } from "@/components/FlagIcon";
import { Dropdown } from "@/components/form/Dropdown";
import { Heading1 } from "@/components/utils/Text";
import { appLanguageOptions } from "@/setup/i18n";
import { sortLangCodes } from "@/utils/sortLangCodes";
export function LocalePart(props: {
language: string;
setLanguage: (l: string) => void;
}) {
2023-11-26 16:33:04 +01:00
const { t } = useTranslation();
const sorted = sortLangCodes(appLanguageOptions.map((item) => item.code));
const options = appLanguageOptions
.sort((a, b) => sorted.indexOf(a.code) - sorted.indexOf(b.code))
.map((opt) => ({
id: opt.code,
name: `${opt.name}${opt.nativeName}`,
leftIcon: <FlagIcon countryCode={opt.code} />,
}));
2023-11-26 16:33:04 +01:00
const selected = options.find((item) => item.id === props.language);
return (
<div>
2023-11-26 16:33:04 +01:00
<Heading1 border>{t("settings.locale.title")}</Heading1>
<p className="text-white font-bold mb-3">
{t("settings.locale.language")}
</p>
<p className="max-w-[20rem] font-medium">
2023-11-26 16:33:04 +01:00
{t("settings.locale.languageDescription")}
</p>
<Dropdown
options={options}
selectedItem={selected || options[0]}
setSelectedItem={(opt) => props.setLanguage(opt.id)}
/>
</div>
);
}