diff --git a/src/components/ServerDetailChart.tsx b/src/components/ServerDetailChart.tsx index e56ca9b..46311bb 100644 --- a/src/components/ServerDetailChart.tsx +++ b/src/components/ServerDetailChart.tsx @@ -16,6 +16,7 @@ import { import { ServerDetailChartLoading } from "./loading/ServerDetailLoading"; import AnimatedCircularProgressBar from "./ui/animated-circular-progress-bar"; import { useWebSocketContext } from "@/hooks/use-websocket-context"; +import { useTranslation } from "react-i18next"; type cpuChartData = { timeStamp: string; @@ -54,12 +55,10 @@ export default function ServerDetailChart() { const { id } = useParams(); const { lastMessage, readyState } = useWebSocketContext(); - // 检查连接状态 if (readyState !== 1) { return ; } - // 解析消息 const nezhaWsData = lastMessage ? (JSON.parse(lastMessage.data) as NezhaAPIResponse) : null; @@ -183,6 +182,7 @@ function CpuChart({ data }: { data: NezhaAPI }) { } function ProcessChart({ data }: { data: NezhaAPI }) { + const { t } = useTranslation(); const [processChartData, setProcessChartData] = useState( [] as processChartData[], ); @@ -222,7 +222,9 @@ function ProcessChart({ data }: { data: NezhaAPI }) {
-

{"Process"}

+

+ {t("serverDetailChart.process")} +

{process}

@@ -273,6 +275,7 @@ function ProcessChart({ data }: { data: NezhaAPI }) { } function MemChart({ data }: { data: NezhaAPI }) { + const { t } = useTranslation(); const [memChartData, setMemChartData] = useState([] as memChartData[]); const { mem, swap } = formatNezhaInfo(data); @@ -315,7 +318,9 @@ function MemChart({ data }: { data: NezhaAPI }) {
-

{"Mem"}

+

+ {t("serverDetailChart.mem")} +

-

{"Swap"}

+

+ {t("serverDetailChart.swap")} +

-

{"Disk"}

+

{t("serverDetailChart.disk")}

{disk.toFixed(0)}% @@ -494,6 +502,7 @@ function DiskChart({ data }: { data: NezhaAPI }) { } function NetworkChart({ data }: { data: NezhaAPI }) { + const { t } = useTranslation(); const [networkChartData, setNetworkChartData] = useState( [] as networkChartData[], ); @@ -544,14 +553,18 @@ function NetworkChart({ data }: { data: NezhaAPI }) {

-

{"Upload"}

+

+ {t("serverDetailChart.upload")} +

{up.toFixed(2)} M/s

-

{"Download"}

+

+ {t("serverDetailChart.download")} +

{down.toFixed(2)} M/s

diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 0d74718..0ff5d00 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -2,6 +2,12 @@ "nezha": "Nezha Monitoring", "overview": "Overview", "whereTheTimeIs": "Where the time is", + "info": { + "websocketConnecting": "WebSocket connecting", + "websocketConnected": "WebSocket connected", + "websocketDisconnected": "WebSocket disconnected", + "processing": "Processing..." + }, "serverOverview": { "totalServers": "Total Servers", "onlineServers": "Online Servers", @@ -27,6 +33,14 @@ "region": "Region", "system": "System" }, + "serverDetailChart": { + "process": "Process", + "disk": "Disk", + "mem": "Mem", + "swap": "Swap", + "upload": "Upload", + "download": "Download" + }, "footer": { "themeBy": "Theme by " }, diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json index 2d6e9e0..0876162 100644 --- a/src/locales/zh-CN/translation.json +++ b/src/locales/zh-CN/translation.json @@ -2,6 +2,12 @@ "nezha": "哪吒监控", "overview": "概览", "whereTheTimeIs": "当前时间", + "info": { + "websocketConnecting": "WebSocket 连接中", + "websocketConnected": "WebSocket 连接成功", + "websocketDisconnected": "WebSocket 连接断开", + "processing": "处理中..." + }, "serverOverview": { "totalServers": "服务器总数", "onlineServers": "在线服务器", @@ -27,6 +33,14 @@ "region": "区域", "system": "系统" }, + "serverDetailChart": { + "process": "进程数", + "disk": "磁盘", + "mem": "内存", + "swap": "虚拟内存", + "upload": "上传", + "download": "下载" + }, "footer": { "themeBy": "主题-" }, diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json index 0d4b1f4..a87b08c 100644 --- a/src/locales/zh-TW/translation.json +++ b/src/locales/zh-TW/translation.json @@ -2,6 +2,12 @@ "nezha": "哪吒監控", "overview": "概覽", "whereTheTimeIs": "目前時間", + "info": { + "websocketConnecting": "WebSocket 連接中", + "websocketConnected": "WebSocket 連接成功", + "websocketDisconnected": "WebSocket 連接斷開", + "processing": "處理中..." + }, "serverOverview": { "totalServers": "總服務器", "onlineServers": "線上服務器", @@ -27,6 +33,14 @@ "region": "地區", "system": "系統" }, + "serverDetailChart": { + "process": "進程數", + "disk": "磁盤", + "mem": "內存", + "swap": "虛擬記憶體", + "upload": "上傳", + "download": "下載" + }, "footer": { "themeBy": "主題-" }, diff --git a/src/pages/Server.tsx b/src/pages/Server.tsx index 9b65e14..194a663 100644 --- a/src/pages/Server.tsx +++ b/src/pages/Server.tsx @@ -9,8 +9,10 @@ import { fetchServerGroup } from "@/lib/nezha-api"; import GroupSwitch from "@/components/GroupSwitch"; import { ServerGroup } from "@/types/nezha-api"; import { useWebSocketContext } from "@/hooks/use-websocket-context"; +import { useTranslation } from "react-i18next"; export default function Servers() { + const { t } = useTranslation(); const { data: groupData } = useQuery({ queryKey: ["server-group"], queryFn: () => fetchServerGroup(), @@ -26,14 +28,14 @@ export default function Servers() { useEffect(() => { if (readyState == 1) { - toast.success("WebSocket connected"); + toast.success(t("info.websocketConnected")); } }, [readyState]); if (readyState !== 1) { return (
-

connecting...

+

{t("info.websocketConnecting")}

); } @@ -45,7 +47,7 @@ export default function Servers() { if (!nezhaWsData) { return (
-

processing...

+

{t("info.processing")}

); }