From 4e07279a54481b0dd81cf2497aa6621a548566d2 Mon Sep 17 00:00:00 2001 From: YiZixuan Date: Mon, 8 Sep 2025 14:18:05 +0800 Subject: [PATCH] refactory(i18n): Improve internationalization configuration and add new translations - Added multiple new translation items - Updated the two language files: en and zhcn - Added type definitions for new translation items in types/services.ts - Modified some components to use the new translation items --- .../components/services/LastCheckedTime.tsx | 10 +++--- .../components/services/ServiceEditDialog.tsx | 6 ++-- .../add-service/ServiceFormActions.tsx | 7 ++-- .../incident-history/IncidentTable.tsx | 4 +-- .../incident-history/LatestChecksTable.tsx | 4 ++- .../incident-history/TablePagination.tsx | 4 ++- .../service-row/ServiceRowActions.tsx | 16 ++++++---- .../alerts-templates/TemplateDialog.tsx | 2 ++ .../NotificationChannelDialog.tsx | 2 ++ application/src/translations/en/services.ts | 32 ++++++++++++++++++- .../src/translations/types/incident.ts | 1 + .../src/translations/types/services.ts | 30 +++++++++++++++-- application/src/translations/zhcn/services.ts | 28 +++++++++++++++- 13 files changed, 123 insertions(+), 23 deletions(-) diff --git a/application/src/components/services/LastCheckedTime.tsx b/application/src/components/services/LastCheckedTime.tsx index 3757f12..85756a3 100644 --- a/application/src/components/services/LastCheckedTime.tsx +++ b/application/src/components/services/LastCheckedTime.tsx @@ -2,6 +2,7 @@ import React from "react"; import { Clock, TimerOff } from "lucide-react"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; +import { useLanguage } from "@/contexts/LanguageContext"; interface LastCheckedTimeProps { lastCheckedTime: string; @@ -10,6 +11,7 @@ interface LastCheckedTimeProps { } export const LastCheckedTime = ({ lastCheckedTime, status, interval }: LastCheckedTimeProps) => { + const { t } = useLanguage(); // Format the time without seconds to display a static time const formatTimeWithoutSeconds = (timeString: string) => { try { @@ -55,7 +57,7 @@ export const LastCheckedTime = ({ lastCheckedTime, status, interval }: LastCheck )} - {isPaused ? "Paused at " : ""} + {isPaused ? t("pausedAt") : ""} {formattedTime} @@ -66,14 +68,14 @@ export const LastCheckedTime = ({ lastCheckedTime, status, interval }: LastCheck >
- {isPaused ? "Monitoring Paused" : "Last Check Details"} + {isPaused ? t("monitoringPaused") : t("lastCheckDetails")}
- {isPaused ? "No automatic checks" : `Checked at ${formattedTime}`} + {isPaused ? t("noAutomaticChecks") : t("checkedAt") + `${formattedTime}`}
{interval && !isPaused && (
- Check interval: {formatInterval(interval)} + {t("checkInterval")}: {formatInterval(interval)}
)}
diff --git a/application/src/components/services/ServiceEditDialog.tsx b/application/src/components/services/ServiceEditDialog.tsx index 8603398..d020d56 100644 --- a/application/src/components/services/ServiceEditDialog.tsx +++ b/application/src/components/services/ServiceEditDialog.tsx @@ -11,6 +11,7 @@ import { Service } from "@/types/service.types"; import { useQueryClient } from "@tanstack/react-query"; import { useState, useEffect } from "react"; import { ScrollArea } from "@/components/ui/scroll-area"; +import { useLanguage } from "@/contexts/LanguageContext"; interface ServiceEditDialogProps { open: boolean; @@ -19,6 +20,7 @@ interface ServiceEditDialogProps { } export function ServiceEditDialog({ open, onOpenChange, service }: ServiceEditDialogProps) { + const { t } = useLanguage(); const queryClient = useQueryClient(); const [isSubmitting, setIsSubmitting] = useState(false); @@ -53,9 +55,9 @@ export function ServiceEditDialog({ open, onOpenChange, service }: ServiceEditDi }}> - Edit Service + {t("editService")} - Update the details of your monitored service. + {t("editServiceDesc")} {open && service && ( diff --git a/application/src/components/services/add-service/ServiceFormActions.tsx b/application/src/components/services/add-service/ServiceFormActions.tsx index 4f6ad59..e9a5552 100644 --- a/application/src/components/services/add-service/ServiceFormActions.tsx +++ b/application/src/components/services/add-service/ServiceFormActions.tsx @@ -2,6 +2,7 @@ import { Button } from "@/components/ui/button"; import { Loader2 } from "lucide-react"; import { MouseEvent } from "react"; +import {useLanguage} from "@/contexts/LanguageContext.tsx"; interface ServiceFormActionsProps { isSubmitting: boolean; @@ -14,6 +15,8 @@ export function ServiceFormActions({ onCancel, submitLabel = "Create Service" }: ServiceFormActionsProps) { + + const {t} = useLanguage(); const handleCancel = (e: MouseEvent) => { e.preventDefault(); if (!isSubmitting) { @@ -29,7 +32,7 @@ export function ServiceFormActions({ variant="outline" disabled={isSubmitting} > - Cancel + {t("cancel")}