From 21728be4451fc99c9551f9f95c8b3f98ef3bcbf4 Mon Sep 17 00:00:00 2001 From: attacker Date: Thu, 16 Jul 2026 02:29:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(i18n):=20U46=20=E6=AE=8B=E4=BD=99UI?= =?UTF-8?q?=E7=A1=AC=E7=BC=96=E7=A0=81=E4=B8=AD=E6=96=87=E6=B8=85=E9=9B=B6?= =?UTF-8?q?=20=E2=80=94=206=E6=96=87=E4=BB=B612=E5=A4=84=E2=86=920=20(User?= =?UTF-8?q?FormDialog/CredentialManager/RdpAuditViewer/LiveMonitorDialog/S?= =?UTF-8?q?erverFileBrowser/context-loaders)=20+17=E7=BF=BB=E8=AF=91?= =?UTF-8?q?=E9=94=AE=20zh/en=208085=E2=86=928102=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ROADMAP.md | 1 + TDD_PLAN.md | 15 ++++ .../aiops/aiops-assistant/context-loaders.ts | 69 +++++++++++++++---- .../components/server/ServerFileBrowser.tsx | 2 +- .../components/system/CredentialManager.tsx | 2 +- .../components/system/LiveMonitorDialog.tsx | 2 +- .../src/components/system/RdpAuditViewer.tsx | 4 +- .../src/components/system/UserFormDialog.tsx | 2 +- frontend/src/locales/en-US.json | 23 ++++++- frontend/src/locales/zh-CN.json | 23 ++++++- 10 files changed, 118 insertions(+), 25 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 5ed8c1a..7e25ec1 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -533,6 +533,7 @@ services/api.ts (1324L) | U44 | i18n 残余硬编码中文清零 — 终端审计状态 + 凭证类型 + 流水线阶段 + 时间格式 + CSV 导出(20 文件 ~70 处→0: credential-manager/constants.ts 8 凭证类型 label/desc → labelKey/descKey + i18n.t() + pipeline-run-detail/types.ts 6 阶段 label → i18n.t('deploy.stage.*') + labelKey + pipeline-manager/constants.ts + pipeline-editor/types.ts 分秒 duration → i18n.t('common.duration.minSec') + LiveMonitorDialog 6 终端状态消息 → t() + RdpAuditViewer 6 RDP审计状态 → i18n.t('monitor.rdp.*') + WorkspaceTermDialog 2 终端连接状态 → t() + TerminalSessionsTab 4 时长格式+状态标签 → i18n.t()/t() + k8s-event-utils 3 相对时间 → i18n.t('common.duration.*Ago') + QueryHistoryPanel 3 相对时间 → i18n.t('common.duration.*Ago') + export-audit.ts 9 CSV导出表头 → i18n.t('system.auditExport.*') + useAuditSettings 4 审计保留策略消息 → i18n.t('system.auditSettings.*') + event-handler.ts 4 AgentCLI事件消息 → i18n.t('aiops.cli.*') + NotifyPolicyTab 默认平台名 → i18n.t('monitor.notify.defaultPlatform') + RoleFormDialog AIOps智能分组 → i18n.t('system.role.aiopsGroup') + CronJobViewDialog 关联脚本/无命令内容 → t() + TerminalOutput 无输出 → i18n.t('task.terminal.noOutput') + shared-components 内存标签 → i18n.t('k8s.workloadView.memoryLabel') + prometheus-ds/helpers 连接成功 → i18n.t('monitor.prometheus.connSuccess') + CloudServerImport 发现主机失败 → t() + AdvancedSettingsPanel Job名称 → t('deploy.jobName') + releaseManagerHelpers 4 环境标签硬编码中文移除(已有ENV_LABEL_KEY) — 新增 75 翻译键 (deploy.credType 8+credTypeDesc 8+fmtDuration 1+terminal 2+jobName 1, monitor.terminal 6+rdp 6+notify 1+prometheus 1, deploy.terminal 2, common.duration 2, system.terminalSession 4+csvHeader 7+auditExport 9+auditSettings 4+credTypeLabel 3+role 1, task.cronJob 2+terminal 1, k8s.workloadView 1, aiops.cli 5, server.import 1), zh/en 7987→8059 +72 对齐;tsc -b=0, npm build✓ (17.13s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | | U42 | i18n 残余硬编码中文彻底清零 — 全量 JSX children + toast/confirm + sr-only 描述(33 文件 54 处→0: PredictiveCapacityTab AI深度解读/紧急/警告/7天使用率预测/预计N天/后达到阈值/AI建议 + PredictiveCostTab AI深度解读 + event-handler.ts 高危操作确认 toast + DeployCredentials 启用/禁用 + DeployRBAC 删除角色 confirm + WorkspaceTermDialog 标题 + CredFormDialog Windows用户 + ClusterOverviewPage 核 + DeploymentEditContainers Pod级别 + DeploymentEditService 无selector/个关联/Ingresses应用路由/暂无Service/暂无Ingress/自动高亮 + DeploymentEditStorage 无容器 + KubectlTerminal sr-only + KubernetesClusterDialog 已配置 + ResourceVisualEditor YAML编辑 + CreateHPADialog CPU目标 + UpdateStrategyCard maxSurge/maxUnavailable/revisionHistoryLimit/progressDeadlineSeconds 说明 + IngressCreateForm host域名/Service端口 + ServiceCreateForm 端口配置/个端口/selector自动检测 + PodInstancesTable Pod名称 + UpdateStrategySelectorCards Pod管理策略 + AlertRulesTab 删除confirm/分钟 + PrometheusDatasourceManager 删除confirm + LogDatasourcePage 删除confirm + QueryHistoryPanel 条 + ServerFileBrowser sr-only + TerminalDialog sr-only + CredentialManager 删除confirm + RdpAuditViewer sr-only + SystemManager 删除用户/批量删除 confirm + TerminalSessionsTab 删除confirm + SecuritySettingsTab 30分钟/2小时 + CronJobViewDialog 次 — 新增 k8s.editAdvanced 6键+k8s.editService 11键+k8s.cluster 2键+k8s.clusterDialog 1键+k8s.kubectlTerminalDesc/k8s.rve.yamlEditBtn/k8s.hpa.cpuTarget/k8s.podLevel/k8s.podNameLabel/k8s.podManagePolicy 共 28键 + aiops.capacity 8键+aiops.cost 1键+aiops.cli 2键 + deploy.cred.windowsUser/deploy.workspaceTerminalTitle/deploy.rbac.deleteRoleDesc/deploy.cred.badgeDefault 4键 + monitor.deleteRulesConfirmDesc/deleteDatasourceConfirmDesc/deleteLogDsConfirmDesc/durationMinutes/queryHistory.count 5键 + system.rdpLiveAudit/rdpHistoryReplay/rdpAuditDesc/sshTerminalDesc/sftpFileDesc/sftpFileLabel/deleteUserConfirmDesc/batchDeleteUsersConfirmDesc/deleteCredConfirmDesc/deleteTermSessionsConfirmDesc 10键 + task.cronJob.runCount 1键 + common.minutes30/hours2 2键, zh/en 7847→7898 对齐;tsc -b=0, npm build✓ (17.71s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | | U45 | AI 告警分析模块 i18n 补全(analyzerHelpers.ts 6 告警类型 × ~4 模板字符串 = 25 处硬编码中文 rootCause/impact/recommendations→i18n.t() 插值 + mapAlertEvent locale 硬编码 zh-CN→动态 i18n.language + 事件ID比较硬编码→i18n.t(defaultEvent) + AIPredictiveAnalytics 预测图标中文-only includes→match() 双语兼容 — 新增 aiops.analyzer 26 翻译键, zh/en 8059→8085 对齐;tsc -b=0, npm build✓ (17.40s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | +| U46 | i18n 残余 UI 硬编码中文清零 — 深度边角(6 文件 12 处→0: UserFormDialog '新建用户' + CredentialManager '显示' title + RdpAuditViewer RDP实时审计/RDP历史回放/录屏帧解码失败 + LiveMonitorDialog 连接超时提示 + ServerFileBrowser prompt输入目录名 + context-loaders.ts AI上下文模板字符串(alertSummary/alertLine/metricLine/highLoadHosts/agentMetricsSummary/platformOverview/highLoadAssets/recentAlerts/recentReleases/overviewFallback) 全量 i18n.t() 插值 — 新增 common.show/dirNamePrompt + system.createUser/rdpFrameError/rdpHistoryReplayId/connectTimeoutActive + aiops.ctx 11 键 共 17 翻译键, zh/en 8085→8102 对齐;tsc -b=0, npm build✓ (18.05s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | | U37 | 全量 JSX 文本节点硬编码中文清零(65 文件 151 处→0: MiddlewareMonitor/SiteMonitor/SNMPMonitor/HealthProbeSection/ContextSwitchCard/ProcessTable/PortMonitorTab/MwTargetChartsPanel/MiddlewareDialog/ChartRangeHint/SnmpDeviceChartsPanel/AlertRulesTab/LogClusterPanel/LogDatasourcePage/LogQueryToolbar/LogAlertsPanel/PrometheusDatasourceManager/PodMetricsPage/CapacityPage/NamespaceManagementPage/NamespaceResourcePage/DeploymentEditService/EventsPage/DeploymentDetail/ClusterOverviewPage/DeploymentEditContainers/DeploymentEditStorage/WorkloadViewPage/BottomStatusBar/UpdateStrategySelectorCards/PodInstancesTable/shared-components/UpdateStrategyCard/TolerationsCard/HostSettingsCard/IngressListItem/ServiceListItem/ServiceCreateForm/IngressCreateForm/CreateHPADialog/DeployCredentials/DeployRBAC/UserGroupsManager/BuildNodesManager/DeployTargetFields/PipelineCreateDialog/CredFormDialog/WorkspaceTermDialog/AgentAlerts/AgentRuleDialog/LiveMonitorDialog/RoleFormDialog/CronJobViewDialog/TerminalOutput/AIAnalysisResult/AIPredictiveAnalytics/PredictiveCostTab/PredictiveCapacityTab/ActiveSessionsPanel/HistorySessionsPanel/TerminalDialog/ServerFileBrowser/PodFileBrowser/SiteResultsPanel/SiteProtocolPieChart — 151 JSX 文本节点中文全部替换为 t()/i18n.t() 调用;新增 common.* 98 翻译键 (selectedCount/itemsCount/newValue/namespaceLabel/containerLabel/replicasLabel/minReplicas/maxReplicas/createNamespace/noNamespace/unknownResource/exportYaml/loadTrend/loadCapacity/predicted/threshold/hostSettings/addVolume/addMount/createService/createIngress/editAction/updateStrategy/selectAndLabel/historyVersion/fileBrowser/scale/back/createHpa/allNamespaces/certLabel/observable/deviceList/addDevice/addMonitor/collectNow/addTask/addProbe/restoreFull/contextSwitch/processTop/listenPorts/terminalRealtime/auditWebssh/buildTerminal/fileBrowse/newDir/loadDeployment/notLinked/selectedPerms/none/hasLabel/deleteNamespace/deleteNamespaceWarn/allResources/notFoundDeploy/nodeList/fileLabel/addCustom/newInstanceService/newInstanceIngress/totalContainers/workContainers/loadingEllipsis/volumeClaimTemplates/containerTemplate/passwordOptional/updated/page/perPage/clusterMode/totalLogs/countLabel/percentage/queryTime/addDatasource/newPermission/newEnv/envLabel/displayName/newUserGroup/auditTrace/predictValue/confidence/predictMonthEnd/noCapacityData/securityMode/standardRdp/domainLabel/noRdpActive/noRdpHistory/buffer/matched/podLogs/createHpaTitle/password/events/total);37 文件已有 import i18n→i18n.t() 模式, 2 文件新增 import i18n;zh/en 7640→3526 namespace-flat +98 键对齐;tsc -b=0, npm build✓ (17.96s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | --- diff --git a/TDD_PLAN.md b/TDD_PLAN.md index 5740afc..bf38be7 100644 --- a/TDD_PLAN.md +++ b/TDD_PLAN.md @@ -1519,3 +1519,18 @@ curl -s -o /dev/null -w "%{http_code}" -H "Authorization: Bearer ${TOKEN}" "http - [x] 17/17 集成回归测试通过(零回归) - [x] Docker 部署 healthy +--- + +## U46: i18n 残余 UI 硬编码中文清零 — 深度边角 + +### 通过标准 +- [x] 6 个修复文件中无残余硬编码中文(UserFormDialog/CredentialManager/RdpAuditViewer/LiveMonitorDialog/ServerFileBrowser/context-loaders) +- [x] context-loaders.ts 全部模板字符串使用 i18n.t() 插值 +- [x] `tsc -b` 零错误 +- [x] `npm run build` 零错误(✓ built in 18.05s) +- [x] ESLint errors=0, any=0 +- [x] zh/en 8102=8102 完全对齐(+17 新键) +- [x] `go build` 零错误 +- [x] 17/17 集成回归测试通过(零回归) +- [x] Docker 部署 healthy + diff --git a/frontend/src/components/aiops/aiops-assistant/context-loaders.ts b/frontend/src/components/aiops/aiops-assistant/context-loaders.ts index d5b49a3..ad46365 100644 --- a/frontend/src/components/aiops/aiops-assistant/context-loaders.ts +++ b/frontend/src/components/aiops/aiops-assistant/context-loaders.ts @@ -8,27 +8,49 @@ export async function loadAlertsContext(): Promise { const alerts: JsonData[] = (res as JsonData)?.list || []; if (!alerts.length) return i18n.t('aiops.noAlertsNow'); const lines = alerts.slice(0, 15).map((a, i) => - `${i + 1}. [${a.severity || i18n.t('common.unknown')}|${a.status || '-'}] ${a.rule_name || i18n.t('dashboard.stat.alerts')} → 目标:${a.target || '-'} 值:${a.value ?? '-'} 时间:${(a.started_at || '').slice(0, 16)}`, + i18n.t('aiops.ctx.alertLine', { + i: i + 1, + severity: a.severity || i18n.t('common.unknown'), + status: a.status || '-', + name: a.rule_name || i18n.t('dashboard.stat.alerts'), + target: a.target || '-', + value: a.value ?? '-', + time: (a.started_at || '').slice(0, 16), + }), ); const firing = alerts.filter((a) => a.status === 'firing').length; - return `共 ${alerts.length} 条告警(firing ${firing} 条),前 ${Math.min(15, alerts.length)} 条:\n${lines.join('\n')}`; + return i18n.t('aiops.ctx.alertSummary', { + total: alerts.length, + firing, + shown: Math.min(15, alerts.length), + }) + '\n' + lines.join('\n'); } /** 拉取 Agent 实时主机指标,识别高负载主机 */ export async function loadMetricsContext(): Promise { const res = await agentApi.getLatest(); const hosts: JsonData[] = Array.isArray(res) ? res : (res as JsonData)?.list || []; - if (!hosts.length) return i18n.t('aiops.noAgentData'); - const lines = hosts.slice(0, 20).map((h, i) => { - const cpu = h.cpu_usage ?? '-'; - const mem = h.mem_usage ?? '-'; - return `${i + 1}. ${h.hostname || '-'} | CPU:${cpu}% | 内存:${mem}% (${h.mem_used ?? '-'}/${h.mem_total ?? '-'}GB) | 核数:${h.cpu_cores ?? '-'} | 上报:${(h.report_time || '').slice(0, 16)}`; - }); + if (!hosts.length) return i18n.t('aiops.ctx.noAgentData'); + const lines = hosts.slice(0, 20).map((h, i) => + i18n.t('aiops.ctx.metricLine', { + i: i + 1, + host: h.hostname || '-', + cpu: h.cpu_usage ?? '-', + mem: h.mem_usage ?? '-', + used: h.mem_used ?? '-', + total: h.mem_total ?? '-', + cores: h.cpu_cores ?? '-', + time: (h.report_time || '').slice(0, 16), + }), + ); const hot = hosts.filter((h) => (h.cpu_usage ?? 0) >= 80 || (h.mem_usage ?? 0) >= 80); const note = hot.length - ? `\n⚠️ 高负载主机 ${hot.length} 台:${hot.map((h) => `${h.hostname}(CPU${h.cpu_usage}%/MEM${h.mem_usage}%)`).join('、')}` + ? '\n' + i18n.t('aiops.ctx.highLoadHosts', { + count: hot.length, + hosts: hot.map((h) => `${h.hostname}(CPU${h.cpu_usage}%/MEM${h.mem_usage}%)`).join('、'), + }) : ''; - return `Agent 监控的 ${hosts.length} 台主机实时指标:\n${lines.join('\n')}${note}`; + return i18n.t('aiops.ctx.agentMetricsSummary', { count: hosts.length }) + '\n' + lines.join('\n') + note; } /** 拉取仪表盘综合数据,生成运维报告上下文 */ @@ -42,12 +64,18 @@ export async function loadReportContext(): Promise { `${i + 1}.${h.hostname || h.ip} CPU:${h.cpu_usage}% MEM:${h.memory_usage}% DISK:${h.disk_usage}% Agent:${h.agent_status}`, ); return [ - `平台概览:服务器:${summary.server_total}(在线${summary.server_online}) | Kubernetes集群:${summary.cluster_total} | 平台告警:${summary.firing_alerts} | Agent未恢复告警:${summary.unresolved_alerts}`, + i18n.t('aiops.ctx.platformOverview', { + servers: summary.server_total, + online: summary.server_online, + clusters: summary.cluster_total, + alerts: summary.firing_alerts, + unresolved: summary.unresolved_alerts, + }), '', - '高负载资产:', + i18n.t('aiops.ctx.highLoadAssets'), highLoadLines.join('\n') || i18n.t('aiops.noneFallback'), '', - '最近告警:', + i18n.t('aiops.ctx.recentAlerts'), alertLines.join('\n') || i18n.t('aiops.noneFallback'), ].join('\n'); } @@ -60,10 +88,21 @@ export async function loadReportContext(): Promise { const s: JsonData = stats || {}; const ss = s.server_stats || {}, ks = s.kubernetes_stats || {}, as = s.alert_stats || {}, ps = s.pipeline_stats || {}, cs = s.cost_stats || {}; - const overview = `服务器:${ss.total ?? 0}(运行${ss.running ?? 0}) | Kubernetes集群:${ks.total ?? 0} 节点:${ks.total_nodes ?? 0} Pod:${ks.total_pods ?? 0} | 告警:${as.total ?? 0}(firing ${as.firing ?? 0}) | 流水线:${ps.total ?? 0}(成功率${ps.success_rate ?? 0}%) | 本月成本:¥${cs.month_cost ?? 0}`; + const overview = i18n.t('aiops.ctx.overviewFallback', { + servers: ss.total ?? 0, + running: ss.running ?? 0, + clusters: ks.total ?? 0, + nodes: ks.total_nodes ?? 0, + pods: ks.total_pods ?? 0, + alerts: as.total ?? 0, + firing: as.firing ?? 0, + pipelines: ps.total ?? 0, + rate: ps.success_rate ?? 0, + cost: cs.month_cost ?? 0, + }); const alertList: JsonData[] = Array.isArray(alerts) ? alerts : (alerts as JsonData)?.list || []; const releaseList: JsonData[] = Array.isArray(releases) ? releases : (releases as JsonData)?.list || []; const alertLines = alertList.slice(0, 10).map((a: JsonData, i: number) => `${i + 1}.[${a.severity || '?'}|${a.status || '?'}] ${a.rule_name || '-'} → ${a.target || '-'}`); const releaseLines = releaseList.slice(0, 10).map((r: JsonData, i: number) => `${i + 1}.${r.app_name || '-'} ${r.version || ''} [${r.environment || '-'}/${r.status || '-'}] by ${r.author || '-'}`); - return `平台概览:${overview}\n\n最近告警:\n${alertLines.join('\n') || i18n.t('aiops.noneFallback')}\n\n最近发布:\n${releaseLines.join('\n') || i18n.t('aiops.noneFallback')}`; + return `${overview}\n\n${i18n.t('aiops.ctx.recentAlerts')}\n${alertLines.join('\n') || i18n.t('aiops.noneFallback')}\n\n${i18n.t('aiops.ctx.recentReleases')}\n${releaseLines.join('\n') || i18n.t('aiops.noneFallback')}`; } diff --git a/frontend/src/components/server/ServerFileBrowser.tsx b/frontend/src/components/server/ServerFileBrowser.tsx index 1aa4412..94d054b 100644 --- a/frontend/src/components/server/ServerFileBrowser.tsx +++ b/frontend/src/components/server/ServerFileBrowser.tsx @@ -127,7 +127,7 @@ export function ServerFileBrowser({ open, onOpenChange, serverId, serverName }: }; const handleMkdir = async () => { - const name = prompt('输入目录名:'); + const name = prompt(i18n.t('common.dirNamePrompt')); if (!name || !serverId) return; const newPath = currentPath === '/' ? `/${name}` : `${currentPath}/${name}`; try { diff --git a/frontend/src/components/system/CredentialManager.tsx b/frontend/src/components/system/CredentialManager.tsx index 1baf326..dcc0233 100644 --- a/frontend/src/components/system/CredentialManager.tsx +++ b/frontend/src/components/system/CredentialManager.tsx @@ -349,7 +349,7 @@ export function CredentialManager() { size="icon" className="absolute top-2 right-2 h-7 w-7 text-[var(--dg-text-muted)] hover:text-[var(--dg-text-primary)]" onClick={() => setShowContent(!showContent)} - title={showContent ? t('common.hidden') : '显示'} + title={showContent ? t('common.hidden') : t('common.show')} > {showContent ? : } diff --git a/frontend/src/components/system/LiveMonitorDialog.tsx b/frontend/src/components/system/LiveMonitorDialog.tsx index bef23c8..49a9db8 100644 --- a/frontend/src/components/system/LiveMonitorDialog.tsx +++ b/frontend/src/components/system/LiveMonitorDialog.tsx @@ -139,7 +139,7 @@ export function LiveMonitorDialog({ open, onOpenChange, sessionId, sessionInfo } const timeout = setTimeout(() => { if (!didOpen) { - setConnectError('连接超时 — 请确认已登录且有活跃会话'); + setConnectError(t('system.connectTimeoutActive')); ws.close(); } }, 5000); diff --git a/frontend/src/components/system/RdpAuditViewer.tsx b/frontend/src/components/system/RdpAuditViewer.tsx index 1318973..047ad6b 100644 --- a/frontend/src/components/system/RdpAuditViewer.tsx +++ b/frontend/src/components/system/RdpAuditViewer.tsx @@ -70,7 +70,7 @@ async function drawImageFrame(ctx: CanvasRenderingContext2D, frame: RdpFrame) { ctx.drawImage(img, frame.x || 0, frame.y || 0, frame.width || img.width, frame.height || img.height); resolve(); }; - img.onerror = () => reject(new Error('RDP 录屏帧解码失败')); + img.onerror = () => reject(new Error(i18n.t('system.rdpFrameError'))); img.src = frame.image || ''; }); } @@ -242,7 +242,7 @@ export function RdpAuditViewer({ open, onOpenChange, sessionId, mode }: RdpAudit {i18n.t("system.rdpAuditDesc")}
- {mode === 'live' ? 'RDP 实时审计' : `RDP 历史回放 #${sessionId || ''}`} + {mode === 'live' ? i18n.t('system.rdpLiveAudit') : i18n.t('system.rdpHistoryReplayId', { id: sessionId || '' })}