fix: small refactor

This commit is contained in:
blagodaren 2024-12-28 13:57:30 +03:00
parent 8461046a4f
commit bab291a60b
2 changed files with 27 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import getSystem from "@/utils/get-system";
import { routers } from "@/pages/_routers"; import { routers } from "@/pages/_routers";
import { TooltipIcon } from "@/components/base/base-tooltip-icon"; import { TooltipIcon } from "@/components/base/base-tooltip-icon";
import { ContentCopyRounded } from "@mui/icons-material"; import { ContentCopyRounded } from "@mui/icons-material";
import { languages } from "@/services/i18n";
interface Props { interface Props {
onError?: (err: Error) => void; onError?: (err: Error) => void;
@ -35,6 +36,19 @@ interface Props {
const OS = getSystem(); const OS = getSystem();
const languageOptions = Object.entries(languages).map(([code, _]) => {
const labels: { [key: string]: string } = {
en: "English",
ru: "Русский",
zh: "中文",
fa: "فارسی",
tt: "Татар",
id: "Bahasa Indonesia",
ar: "العربية",
};
return { code, label: labels[code] };
});
const SettingVerge = ({ onError }: Props) => { const SettingVerge = ({ onError }: Props) => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -96,13 +110,11 @@ const SettingVerge = ({ onError }: Props) => {
onGuard={(e) => patchVerge({ language: e })} onGuard={(e) => patchVerge({ language: e })}
> >
<Select size="small" sx={{ width: 110, "> div": { py: "7.5px" } }}> <Select size="small" sx={{ width: 110, "> div": { py: "7.5px" } }}>
<MenuItem value="zh"></MenuItem> {languageOptions.map(({ code, label }) => (
<MenuItem value="en">English</MenuItem> <MenuItem key={code} value={code}>
<MenuItem value="ru">Русский</MenuItem> {label}
<MenuItem value="fa">فارسی</MenuItem> </MenuItem>
<MenuItem value="id">Bahasa Indonesia</MenuItem> ))}
<MenuItem value="tt">Татар</MenuItem>
<MenuItem value="ar">العربية</MenuItem>
</Select> </Select>
</GuardState> </GuardState>
</SettingItem> </SettingItem>

View File

@ -8,15 +8,14 @@ import tt from "@/locales/tt.json";
import id from "@/locales/id.json"; import id from "@/locales/id.json";
import ar from "@/locales/ar.json"; import ar from "@/locales/ar.json";
const resources = { export const languages = { en, ru, zh, fa, tt, id, ar };
en: { translation: en },
ru: { translation: ru }, const resources = Object.fromEntries(
zh: { translation: zh }, Object.entries(languages).map(([key, value]) => [
fa: { translation: fa }, key,
tt: { translation: tt }, { translation: value },
id: { translation: id }, ]),
ar: { translation: ar }, );
};
i18n.use(initReactI18next).init({ i18n.use(initReactI18next).init({
resources, resources,