From 4032ff62a2d0d9130b6f8d73de8e5318b5d3638b Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 09:24:54 +0800 Subject: [PATCH] fix: i18n --- src/components/CycleTransferStatsClient.tsx | 9 ++++++--- src/components/ServerCardInline.tsx | 4 ++-- src/components/ServerDetailOverview.tsx | 3 ++- src/components/ServiceTracker.tsx | 10 ++++++++-- src/components/ServiceTrackerClient.tsx | 8 +++++--- src/locales/en/translation.json | 14 ++++++++++++++ src/locales/zh-CN/translation.json | 14 ++++++++++++++ src/locales/zh-TW/translation.json | 14 ++++++++++++++ 8 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/components/CycleTransferStatsClient.tsx b/src/components/CycleTransferStatsClient.tsx index 78e25a8..68f1760 100644 --- a/src/components/CycleTransferStatsClient.tsx +++ b/src/components/CycleTransferStatsClient.tsx @@ -3,6 +3,7 @@ import { cn } from "@/lib/utils"; import { formatBytes } from "@/lib/format"; import AnimatedCircularProgressBar from "./ui/animated-circular-progress-bar"; import { CircleStackIcon } from "@heroicons/react/24/outline"; +import { useTranslation } from "react-i18next"; interface CycleTransferStatsClientProps { name: string; @@ -21,6 +22,7 @@ interface CycleTransferStatsClientProps { export const CycleTransferStatsClient: React.FC< CycleTransferStatsClientProps > = ({ name, from, to, max, serverStats, className }) => { + const { t } = useTranslation(); return (
- {formatBytes(transfer)} used + {formatBytes(transfer)} {t("cycleTransfer.used")} - {formatBytes(max)} total + {formatBytes(max)} {t("cycleTransfer.total")}
- Next update: {new Date(nextUpdate).toLocaleString()} + {t("cycleTransfer.nextUpdate")}:{" "} + {new Date(nextUpdate).toLocaleString()}
diff --git a/src/components/ServerCardInline.tsx b/src/components/ServerCardInline.tsx index 318f421..db03c50 100644 --- a/src/components/ServerCardInline.tsx +++ b/src/components/ServerCardInline.tsx @@ -135,11 +135,11 @@ export default function ServerCardInline({ {t("serverCard.uptime")}

- {(uptime / 86400).toFixed(0)} {"Days"} + {(uptime / 86400).toFixed(0)} {t("serverCard.days")}
-

{t("CPU")}

+

{"CPU"}

{cpu.toFixed(2)}%
diff --git a/src/components/ServerDetailOverview.tsx b/src/components/ServerDetailOverview.tsx index 0dea33e..ecb3c33 100644 --- a/src/components/ServerDetailOverview.tsx +++ b/src/components/ServerDetailOverview.tsx @@ -96,7 +96,8 @@ export default function ServerDetailOverview({

{" "} - {online ? (uptime / 86400).toFixed(0) : "N/A"} {"Days"}{" "} + {online ? (uptime / 86400).toFixed(0) : "N/A"}{" "} + {t("serverDetail.days")}
diff --git a/src/components/ServiceTracker.tsx b/src/components/ServiceTracker.tsx index 72caaf3..1ca2883 100644 --- a/src/components/ServiceTracker.tsx +++ b/src/components/ServiceTracker.tsx @@ -5,8 +5,11 @@ import { fetchService } from "@/lib/nezha-api"; import { ServiceData } from "@/types/nezha-api"; import { CycleTransferStatsCard } from "./CycleTransferStats"; import { Loader } from "./loading/Loader"; +import { useTranslation } from "react-i18next"; +import { ExclamationTriangleIcon } from "@heroicons/react/20/solid"; export const ServiceTracker: React.FC = () => { + const { t } = useTranslation(); const { data: serviceData, isLoading } = useQuery({ queryKey: ["service"], queryFn: () => fetchService(), @@ -40,7 +43,7 @@ export const ServiceTracker: React.FC = () => { return (
- Loading... + {t("serviceTracker.loading")}
); } @@ -50,7 +53,10 @@ export const ServiceTracker: React.FC = () => { !serviceData?.data?.cycle_transfer_stats ) { return ( -
No service data available
+
+ + {t("serviceTracker.noService")} +
); } diff --git a/src/components/ServiceTrackerClient.tsx b/src/components/ServiceTrackerClient.tsx index a6f2cfd..0872e5d 100644 --- a/src/components/ServiceTrackerClient.tsx +++ b/src/components/ServiceTrackerClient.tsx @@ -1,6 +1,7 @@ import React from "react"; import { cn } from "@/lib/utils"; import { Separator } from "./ui/separator"; +import { useTranslation } from "react-i18next"; interface ServiceTrackerProps { days: Array<{ @@ -20,6 +21,7 @@ export const ServiceTrackerClient: React.FC = ({ uptime = 100, avgDelay = 0, }) => { + const { t } = useTranslation(); return (
= ({ - {uptime.toFixed(1)}% uptime + {uptime.toFixed(1)}% {t("serviceTracker.uptime")}
@@ -61,8 +63,8 @@ export const ServiceTrackerClient: React.FC = ({
- 30 DAYS AGO - TODAY + 30 {t("serviceTracker.daysAgo")} + {t("serviceTracker.today")}
); diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 8d6d675..59b5ba5 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -26,6 +26,7 @@ "serverCard": { "mem": "MEM", "stg": "STG", + "days": "Days", "upload": "Upload", "download": "Download", "system": "System", @@ -33,9 +34,22 @@ "totalUpload": "Upload", "totalDownload": "Download" }, + "cycleTransfer": { + "used": "used", + "total": "total", + "nextUpdate": "next update" + }, + "serviceTracker": { + "noService": "No service data", + "uptime": "Uptime", + "daysAgo": "days ago", + "today": "Today", + "loading": "Loading..." + }, "serverDetail": { "status": "Status", "online": "Online", + "days": "Days", "offline": "Offline", "unknown": "Unknown", "uptime": "Uptime", diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json index 55c2b04..56416fc 100644 --- a/src/locales/zh-CN/translation.json +++ b/src/locales/zh-CN/translation.json @@ -26,6 +26,7 @@ "serverCard": { "mem": "内存", "stg": "存储", + "days": "天", "upload": "上传", "download": "下载", "system": "系统", @@ -33,9 +34,22 @@ "totalUpload": "总上传", "totalDownload": "总下载" }, + "cycleTransfer": { + "used": "已使用", + "total": "总计", + "nextUpdate": "下次更新" + }, + "serviceTracker": { + "noService": "没有服务监测数据", + "uptime": "可用率", + "daysAgo": "天前", + "today": "今天", + "loading": "加载中..." + }, "serverDetail": { "status": "状态", "online": "在线", + "days": "天", "offline": "离线", "unknown": "未知", "uptime": "运行时间", diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json index aa5e734..b8bdde2 100644 --- a/src/locales/zh-TW/translation.json +++ b/src/locales/zh-TW/translation.json @@ -26,6 +26,7 @@ "serverCard": { "mem": "內存", "stg": "存儲", + "days": "天", "upload": "上傳", "download": "下載", "system": "系統", @@ -33,9 +34,22 @@ "totalUpload": "總上傳", "totalDownload": "總下載" }, + "cycleTransfer": { + "used": "已使用", + "total": "總量", + "nextUpdate": "下次更新" + }, + "serviceTracker": { + "noService": "沒有服務監控數據", + "uptime": "可用率", + "daysAgo": "天前", + "today": "今天", + "loading": "載入中..." + }, "serverDetail": { "status": "狀態", "online": "線上", + "days": "天", "offline": "離線", "unknown": "未知", "uptime": "運行時間",