From bab291a60bc1a08245b8e16b0037475caff8f33c Mon Sep 17 00:00:00 2001 From: blagodaren Date: Sat, 28 Dec 2024 13:57:30 +0300 Subject: [PATCH] fix: small refactor --- src/components/setting/setting-verge.tsx | 26 +++++++++++++++++------- src/services/i18n.ts | 17 ++++++++-------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/components/setting/setting-verge.tsx b/src/components/setting/setting-verge.tsx index 2a38c9be..1363b47e 100644 --- a/src/components/setting/setting-verge.tsx +++ b/src/components/setting/setting-verge.tsx @@ -28,6 +28,7 @@ import getSystem from "@/utils/get-system"; import { routers } from "@/pages/_routers"; import { TooltipIcon } from "@/components/base/base-tooltip-icon"; import { ContentCopyRounded } from "@mui/icons-material"; +import { languages } from "@/services/i18n"; interface Props { onError?: (err: Error) => void; @@ -35,6 +36,19 @@ interface Props { 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 { t } = useTranslation(); @@ -96,13 +110,11 @@ const SettingVerge = ({ onError }: Props) => { onGuard={(e) => patchVerge({ language: e })} > diff --git a/src/services/i18n.ts b/src/services/i18n.ts index f72f10a6..2be67191 100644 --- a/src/services/i18n.ts +++ b/src/services/i18n.ts @@ -8,15 +8,14 @@ import tt from "@/locales/tt.json"; import id from "@/locales/id.json"; import ar from "@/locales/ar.json"; -const resources = { - en: { translation: en }, - ru: { translation: ru }, - zh: { translation: zh }, - fa: { translation: fa }, - tt: { translation: tt }, - id: { translation: id }, - ar: { translation: ar }, -}; +export const languages = { en, ru, zh, fa, tt, id, ar }; + +const resources = Object.fromEntries( + Object.entries(languages).map(([key, value]) => [ + key, + { translation: value }, + ]), +); i18n.use(initReactI18next).init({ resources,