Files
upscayl/renderer/components/sidebar/settings-tab/language-switcher.tsx
Aaron Liu 729ce04fd6 fix(language-switcher): unlabel as theme selector, use already-fetched
atom value

Co-authored-by: coderabbitai[bot]
<136622811+coderabbitai[bot]@users.noreply.github.com>
2025-09-24 15:44:09 -04:00

56 lines
1.5 KiB
TypeScript

import { localeAtom, translationAtom } from "@/atoms/translations-atom";
import { useAtom, useAtomValue, useSetAtom } from "jotai";
const locales = {
ar: "العربية",
en: "English",
tr: "Türkçe",
ru: "Русский",
uk: "Українська",
ja: "日本語",
zh: "简体中文",
es: "Español",
fr: "Français",
de: "Deutsch",
vi: "Tiếng Việt",
pt: "Português (Portugal)",
ptBR: "Português (Brasil)",
id: "Bahasa Indonesia",
caVAL: "Català (Valencià)",
hu: "Magyar",
pl: "Polski",
};
const LanguageSwitcher = ({ hideLabel = false }: { hideLabel?: boolean }) => {
const [locale, setLocale] = useAtom(localeAtom);
const t = useAtomValue(translationAtom);
return (
<div>
<div className="flex flex-col gap-2">
{!hideLabel && (
<p className="text-sm font-medium">{t("SETTINGS.LANGUAGE.TITLE")}</p>
)}
<select
className="select select-primary"
value={locale}
onChange={(e) => setLocale(e.target.value as keyof typeof locales)}
>
{Object.entries(locales)
.sort(([, a], [, b]) => a.localeCompare(b))
.map((entry) => {
const [locale, label] = entry;
return (
<option value={locale} key={locale}>
{label.toLocaleUpperCase()}
</option>
);
})}
</select>
</div>
</div>
);
};
export default LanguageSwitcher;