From a85e063a4745dab2d20acea65210a695d49f85a3 Mon Sep 17 00:00:00 2001 From: attacker Date: Sat, 11 Jul 2026 01:21:34 +0800 Subject: [PATCH] =?UTF-8?q?refactor(i18n):=20U16=20AgentWizard=20i18n=20?= =?UTF-8?q?=E6=B2=BB=E7=90=86=20=E2=80=94=2029=20=E4=B8=AA=20agentwizardts?= =?UTF-8?q?x.*=20hash=20=E4=B9=B1=E7=A0=81=E9=94=AE=E6=B8=85=E7=90=86?= =?UTF-8?q?=E4=B8=BA=20agent.wizard.*=20=E8=AF=AD=E4=B9=89=E5=8C=96?= =?UTF-8?q?=E9=94=AE=20+=20=E7=BB=84=E4=BB=B6=E4=BB=8E=20i18n.t()=20?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=94=B9=E4=B8=BA=20useTranslation()=20hook?= =?UTF-8?q?=20+=208=20=E5=A4=84=E7=A1=AC=E7=BC=96=E7=A0=81=E4=B8=AD?= =?UTF-8?q?=E6=96=87=20UI=20=E6=96=87=E6=A1=88=E6=B8=85=E9=9B=B6.=20zh/en?= =?UTF-8?q?=207564=3D7564=20=E5=AF=B9=E9=BD=90,=20tsc=20-b=3D0,=20npm=20bu?= =?UTF-8?q?ild=E2=9C=93,=20ESLint=3D0/66/0,=2017/17=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/agent/AgentWizard.tsx | 77 ++++++++++--------- frontend/src/locales/en-US.json | 66 +++++++++------- frontend/src/locales/zh-CN.json | 66 +++++++++------- 3 files changed, 113 insertions(+), 96 deletions(-) diff --git a/frontend/src/components/agent/AgentWizard.tsx b/frontend/src/components/agent/AgentWizard.tsx index 06dae82..bf351ed 100644 --- a/frontend/src/components/agent/AgentWizard.tsx +++ b/frontend/src/components/agent/AgentWizard.tsx @@ -1,4 +1,5 @@ import { useState, useEffect } from 'react'; +import { useTranslation } from 'react-i18next'; import { useUserStore } from '@/store'; import { Dialog, @@ -14,7 +15,6 @@ import { Label } from '@/components/ui/label'; import { Copy, Check, Terminal, Download, Settings, Play, Cpu, Zap, Loader2, Server, Shield } from 'lucide-react'; import { serverApi } from '@/api'; import { toast } from 'sonner'; -import i18n from '@/i18n'; interface AgentWizardProps { open: boolean; @@ -41,6 +41,7 @@ function detectServerAddress() { } export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, onFailed }: AgentWizardProps) { + const { t } = useTranslation(); const token = useUserStore((s) => s.token) || ''; const origin = detectServerAddress(); const isWindowsServer = Boolean(server?.os && server.os.toLowerCase().includes('windows')); @@ -108,10 +109,10 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, if (success) { setCopied(true); - toast.success(i18n.t('agent.agentwizardtsx.s19ee0048')); + toast.success(t('agent.wizard.copySuccess')); setTimeout(() => setCopied(false), 3000); } else { - toast.error(i18n.t('agent.agentwizardtsx.s7ac41b1c')); + toast.error(t('agent.wizard.copyFailed')); setShowManualInput(true); } }; @@ -122,19 +123,19 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, const manualSteps = [ { icon: Download, - title: i18n.t('agent.agentwizardtsx.s8c59e054'), + title: t('agent.wizard.stepDownload'), commands: [ `curl -fsSL ${binaryUrl} -o /usr/local/bin/aiops-agent`, ], }, { icon: Settings, - title: i18n.t('agent.agentwizardtsx.s2f17bf61'), + title: t('agent.wizard.stepChmod'), commands: ['chmod +x /usr/local/bin/aiops-agent'], }, { icon: Cpu, - title: i18n.t('agent.agentwizardtsx.s03fa0002'), + title: t('agent.wizard.stepService'), commands: [ `cat > /etc/systemd/system/aiops-agent.service << 'EOF'`, `[Unit]`, @@ -154,7 +155,7 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, }, { icon: Play, - title: i18n.t('agent.agentwizardtsx.s84bd81f4'), + title: t('agent.wizard.stepStart'), commands: [ 'systemctl daemon-reload', 'systemctl enable --now aiops-agent', @@ -165,7 +166,7 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, const windowsManualSteps = [ { icon: Download, - title: '下载 Windows Agent', + title: t('agent.wizard.stepDownloadWindows'), commands: [ `New-Item -ItemType Directory -Force "C:\\Program Files\\AIOps"`, `Invoke-WebRequest -Uri ${windowsBinaryUrl} -OutFile "C:\\Program Files\\AIOps\\aiops-agent.exe" -UseBasicParsing`, @@ -173,14 +174,14 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, }, { icon: Cpu, - title: '注册 Windows 服务', + title: t('agent.wizard.stepRegisterWindows'), commands: [ `New-Service -Name AIOpsAgent -DisplayName "AIOps Agent" -BinaryPathName '"C:\\Program Files\\AIOps\\aiops-agent.exe" -server ${origin} -interval 10 -token ${token}' -StartupType Automatic`, ], }, { icon: Play, - title: '启动并检查', + title: t('agent.wizard.stepStartCheck'), commands: [ 'Start-Service AIOpsAgent', 'Get-Service AIOpsAgent', @@ -193,11 +194,11 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, const handleSshInstall = async () => { if (!server || !token) return; if (isWindowsServer) { - toast.error('Windows Agent 请使用 PowerShell 安装命令,SSH 一键安装仅支持 Linux/macOS'); + toast.error(t('agent.wizard.windowsSSHNotSupported')); return; } if (needsCreds && !sshPassword && !sshKey) { - toast.error(i18n.t('agent.agentwizardtsx.s6cfe961c')); + toast.error(t('agent.wizard.credsRequired')); return; } setSshInstalling(true); @@ -216,11 +217,11 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, : undefined; // 优先尝试异步批量接口,即使单台也后台执行 await serverApi.batchInstallAgent([server.id], token, credentials); - toast.success(`${server.hostname}: 已提交 Agent 安装任务,后台执行中…`); + toast.success(t('agent.wizard.installSubmitted', { hostname: server.hostname })); onInstalled?.(server.id); onOpenChange(false); } catch (e) { - const msg = e?.message || i18n.t('agent.installFailed'); + const msg = e instanceof Error ? e.message : String(e); toast.error(`${server.hostname} ${msg}`); onFailed?.(server.id, msg); } finally { @@ -233,12 +234,12 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, - {server ? `部署 Agent → ${server.hostname}` : i18n.t('agent.agentwizardtsx.s812cc1a5')} + {server ? t('agent.wizard.titleWithHost', { hostname: server.hostname }) : t('agent.wizard.title')} {server - ? `目标主机 ${server.hostname} (${server.ip}),选择安装方式:` - : i18n.t('agent.agentwizardtsx.sed0c1b63') + ? t('agent.wizard.descWithHost', { hostname: server.hostname, ip: server.ip }) + : t('agent.wizard.desc') } @@ -247,29 +248,29 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled, - {isWindowsServer ? 'PowerShell 安装' : i18n.t('agent.agentwizardtsx.s1a2b3c4d')} + {isWindowsServer ? t('agent.wizard.tabPowerShell') : t('agent.wizard.tabAuto')} {server && !isWindowsServer && ( - {i18n.t('agent.agentwizardtsx.s2b3c4d5e')} + {t('agent.wizard.tabSSH')} )} {!server && ( - SSH一键安装 + {t('agent.wizard.tabSSH')} )} - {i18n.t('agent.agentwizardtsx.s3c4d5e6f')} + {t('agent.wizard.tabManual')} {/* 自动安装 */}

- {isWindowsServer ? '请在目标 Windows 主机的管理员 PowerShell 中执行以下命令。' : i18n.t('agent.agentwizardtsx.s4d5e6f7g')} + {isWindowsServer ? t('agent.wizard.autoHintWindows') : t('agent.wizard.autoHint')}

@@ -280,7 +281,7 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled,
                 variant="ghost"
                 onClick={handleCopy}
                 className="absolute top-2 right-2 h-8 w-8 dg-text-secondary hover:text-[var(--dg-text-primary)] hover:bg-[var(--dg-bg-hover)]"
-                title={i18n.t('agent.agentwizardtsx.s564be0b1')}
+                title={t('agent.wizard.copyBtn')}
               >
                 {copied ?  : }
               
@@ -290,7 +291,7 @@ export function AgentWizard({ open, onOpenChange, server, onStart, onInstalled,
             {showManualInput && (
               

- {i18n.t('agent.agentwizardtsx.s5e6f7g8h')} + {t('agent.wizard.manualCopyHint')}