2025-01-04 21:17:17 +08:00
|
|
|
import { Group, Text, Select } from "@mantine/core";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { updateUser } from "../services/user-service";
|
|
|
|
import { useAtom } from "jotai";
|
|
|
|
import { userAtom } from "../atoms/current-user-atom";
|
|
|
|
import { useState } from "react";
|
|
|
|
|
|
|
|
export default function AccountLanguage() {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Group justify="space-between" wrap="nowrap" gap="xl">
|
|
|
|
<div>
|
|
|
|
<Text size="md">{t("Language")}</Text>
|
|
|
|
<Text size="sm" c="dimmed">
|
|
|
|
{t("Choose your preferred interface language.")}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
<LanguageSwitcher />
|
|
|
|
</Group>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function LanguageSwitcher() {
|
|
|
|
const { t, i18n } = useTranslation();
|
|
|
|
const [user, setUser] = useAtom(userAtom);
|
|
|
|
const [language, setLanguage] = useState(
|
|
|
|
user?.locale === "en" ? "en-US" : user.locale,
|
|
|
|
);
|
|
|
|
|
|
|
|
const handleChange = async (value: string) => {
|
|
|
|
const updatedUser = await updateUser({ locale: value });
|
|
|
|
|
|
|
|
setLanguage(value);
|
|
|
|
setUser(updatedUser);
|
|
|
|
|
|
|
|
i18n.changeLanguage(value);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Select
|
|
|
|
label={t("Select language")}
|
|
|
|
data={[
|
2025-02-06 16:47:41 +00:00
|
|
|
{ value: "en-US", label: "English (US)" },
|
|
|
|
{ value: "de-DE", label: "Deutsch (German)" },
|
2025-03-13 15:25:03 +00:00
|
|
|
{ value: "nl-NL", label: "Dutch (Netherlands)" },
|
2025-02-06 16:47:41 +00:00
|
|
|
{ value: "fr-FR", label: "Français (French)" },
|
|
|
|
{ value: "es-ES", label: "Español (Spanish)" },
|
|
|
|
{ value: "pt-BR", label: "Português (Brasil)" },
|
|
|
|
{ value: "it-IT", label: "Italiano (Italian)" },
|
|
|
|
{ value: "ja-JP", label: "日本語 (Japanese)" },
|
|
|
|
{ value: "ko-KR", label: "한국어 (Korean)" },
|
|
|
|
{ value: "ru-RU", label: "Русский (Russian)" },
|
2025-01-04 21:17:17 +08:00
|
|
|
{ value: "zh-CN", label: "中文 (简体)" },
|
|
|
|
]}
|
2025-03-13 15:25:03 +00:00
|
|
|
value={language || "en-US"}
|
2025-01-04 21:17:17 +08:00
|
|
|
onChange={handleChange}
|
|
|
|
allowDeselect={false}
|
|
|
|
checkIconPosition="right"
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|