2023-11-18 20:55:46 +01:00
|
|
|
import { FlagIcon } from "@/components/FlagIcon";
|
2023-11-26 16:04:23 +01:00
|
|
|
import { Dropdown } from "@/components/form/Dropdown";
|
2023-11-18 20:55:46 +01:00
|
|
|
import { Heading1 } from "@/components/utils/Text";
|
|
|
|
import { appLanguageOptions } from "@/setup/i18n";
|
|
|
|
import { sortLangCodes } from "@/utils/sortLangCodes";
|
|
|
|
|
2023-11-24 17:11:00 +01:00
|
|
|
export function LocalePart(props: {
|
|
|
|
language: string;
|
|
|
|
setLanguage: (l: string) => void;
|
|
|
|
}) {
|
2023-11-26 16:04:23 +01:00
|
|
|
const sorted = sortLangCodes(appLanguageOptions.map((t) => t.code));
|
2023-11-18 20:55:46 +01:00
|
|
|
|
|
|
|
const options = appLanguageOptions
|
2023-11-26 16:04:23 +01:00
|
|
|
.sort((a, b) => sorted.indexOf(a.code) - sorted.indexOf(b.code))
|
2023-11-18 20:55:46 +01:00
|
|
|
.map((opt) => ({
|
2023-11-26 16:04:23 +01:00
|
|
|
id: opt.code,
|
|
|
|
name: `${opt.name} — ${opt.nativeName}`,
|
|
|
|
leftIcon: <FlagIcon countryCode={opt.code} />,
|
2023-11-18 20:55:46 +01:00
|
|
|
}));
|
|
|
|
|
2023-11-24 17:11:00 +01:00
|
|
|
const selected = options.find((t) => t.id === props.language);
|
2023-11-18 20:55:46 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Heading1 border>Locale</Heading1>
|
|
|
|
<p className="text-white font-bold mb-3">Application language</p>
|
|
|
|
<p className="max-w-[20rem] font-medium">
|
|
|
|
Language applied to the entire application.
|
|
|
|
</p>
|
|
|
|
<Dropdown
|
|
|
|
options={options}
|
|
|
|
selectedItem={selected || options[0]}
|
2023-11-24 17:11:00 +01:00
|
|
|
setSelectedItem={(opt) => props.setLanguage(opt.id)}
|
2023-11-18 20:55:46 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|