From 24286a744991b555d4626a7c0fcf358b75652e3f Mon Sep 17 00:00:00 2001 From: GuGuGu Date: Fri, 29 Nov 2024 13:47:09 +0100 Subject: [PATCH] =?UTF-8?q?feat(I18n):=20Add=20multiple=20languages=20?= =?UTF-8?q?=E2=80=8B=E2=80=8B(zh-CN/zh-TW/en/it)=20(#8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 + src/components/action-button-group.tsx | 13 ++- src/components/alert-rule.tsx | 23 ++-- src/components/cron.tsx | 23 ++-- src/components/ddns.tsx | 33 +++--- src/components/fm.tsx | 89 ++++++++------- src/components/group-tab.tsx | 7 +- src/components/header-button-group.tsx | 16 ++- src/components/header.tsx | 52 +++++---- src/components/mode-toggle.tsx | 9 +- src/components/nat.tsx | 17 +-- src/components/note-menu.tsx | 7 +- src/components/notification-group.tsx | 13 ++- src/components/notification-tab.tsx | 8 +- src/components/notifier.tsx | 23 ++-- src/components/profile.tsx | 17 +-- src/components/server-group.tsx | 13 ++- src/components/server.tsx | 22 ++-- src/components/service.tsx | 39 ++++--- src/components/settings-tab.tsx | 9 +- src/components/user.tsx | 13 ++- src/lib/i18n.ts | 42 +++++++ src/locales/en/translation.json | 152 +++++++++++++++++++++++++ src/locales/it/translation.json | 152 +++++++++++++++++++++++++ src/locales/zh-CN/translation.json | 152 +++++++++++++++++++++++++ src/locales/zh-TW/translation.json | 152 +++++++++++++++++++++++++ src/main.tsx | 1 + src/routes/alert-rule.tsx | 29 +++-- src/routes/cron.tsx | 44 +++---- src/routes/ddns.tsx | 28 +++-- src/routes/login.tsx | 31 ++--- src/routes/nat.tsx | 24 ++-- src/routes/notification-group.tsx | 18 +-- src/routes/notification.tsx | 21 ++-- src/routes/root.tsx | 5 +- src/routes/server-group.tsx | 18 +-- src/routes/server.tsx | 52 +++++---- src/routes/service.tsx | 40 ++++--- src/routes/settings.tsx | 38 ++++--- src/routes/user.tsx | 16 ++- src/routes/waf.tsx | 18 +-- src/types/alert-rule.ts | 6 +- src/types/cron.ts | 12 +- src/types/service.ts | 5 +- 44 files changed, 1138 insertions(+), 366 deletions(-) create mode 100644 src/lib/i18n.ts create mode 100644 src/locales/en/translation.json create mode 100644 src/locales/it/translation.json create mode 100644 src/locales/zh-CN/translation.json create mode 100644 src/locales/zh-TW/translation.json diff --git a/package.json b/package.json index 41ecd38..c90ae67 100644 --- a/package.json +++ b/package.json @@ -32,12 +32,14 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", "cmdk": "^1.0.0", + "i18next": "^24.0.2", "jotai-zustand": "^0.6.0", "lucide-react": "^0.454.0", "next-themes": "^0.3.0", "react": "^18.3.1", "react-dom": "^18.3.1", "react-hook-form": "^7.53.1", + "react-i18next": "^15.1.2", "react-router-dom": "^6.27.0", "react-use-websocket": "^4.10.1", "react-virtuoso": "^4.12.0", diff --git a/src/components/action-button-group.tsx b/src/components/action-button-group.tsx index 9c9bb01..fee1faa 100644 --- a/src/components/action-button-group.tsx +++ b/src/components/action-button-group.tsx @@ -13,6 +13,8 @@ import { import { KeyedMutator } from "swr"; import { buttonVariants } from "@/components/ui/button" +import { useTranslation } from "react-i18next"; + interface ButtonGroupProps { className?: string; children: React.ReactNode; @@ -20,6 +22,7 @@ interface ButtonGroupProps { } export function ActionButtonGroup({ className, children, delete: { fn, id, mutate } }: ButtonGroupProps) { + const { t } = useTranslation(); const handleDelete = async () => { await fn([id]); await mutate(); @@ -30,18 +33,18 @@ export function ActionButtonGroup({ className, children, delete: { fn, id, {children} - + - Confirm Deletion? + {t("ConfirmDeletion")} - This operation is unrecoverable! + {t("Results.ThisOperationIsUnrecoverable")} - Cancel - Confirm + {t("Close")} + {t("Confirm")} diff --git a/src/components/alert-rule.tsx b/src/components/alert-rule.tsx index bf76c8d..e06f0db 100644 --- a/src/components/alert-rule.tsx +++ b/src/components/alert-rule.tsx @@ -43,6 +43,8 @@ import { Textarea } from "./ui/textarea" import { useNotification } from "@/hooks/useNotfication" import { Combobox } from "./ui/combobox" +import { useTranslation } from "react-i18next"; + interface AlertRuleCardProps { data?: ModelAlertRule; mutate: KeyedMutator; @@ -83,6 +85,7 @@ const alertRuleFormSchema = z.object({ }); export const AlertRuleCard: React.FC = ({ data, mutate }) => { + const { t } = useTranslation(); const form = useForm>({ resolver: zodResolver(alertRuleFormSchema), defaultValues: data ? { @@ -133,7 +136,7 @@ export const AlertRuleCard: React.FC = ({ data, mutate }) =>
- New Alert Rule + {data ? t("EditAlertRule") : t("CreateAlertRule")}
@@ -143,7 +146,7 @@ export const AlertRuleCard: React.FC = ({ data, mutate }) => name="name" render={({ field }) => ( - Name + {t("Name")} = ({ data, mutate }) => name="rules_raw" render={({ field }) => ( - Rules + {t("Rules")}