feat(i18n): 安全批量转换 135 文件 — 覆盖率 34%→62%

使用 i18n.t() 全局方式(避免 hook 定位问题):
- 288 目标文件中 135 个成功转换
- 2228 处中文替换为 i18n.t() 调用
- 1006 个新翻译 key 添加到 zh-CN.json + en-US.json
- 词典总量: 3554 keys (22 namespaces)
- tsc 零错误 + Vite 构建成功
- 6 个含代码示例/数据字符串的文件安全回退
This commit is contained in:
attacker committed 2026-07-03 02:14:20 +08:00
1 parent 72bfb0e12d
commit 55f216cfbb
131 files changed
+4049 -1908

No files matched your search

@@ -2,6 +2,7 @@
import type { ReplaySessionMeta, CommandBookmark } from './replay-utils';
import { isHighRiskCommand } from './replay-utils';
import i18n from '@/i18n';
// downloadBlob 触发浏览器下载 // Logan.Li
function downloadBlob(blob: Blob, filename: string) {
@@ -22,7 +23,7 @@ function escapeCsv(s: string): string {
// exportAuditReportCsv 导出会话审计报告 CSV // Logan.Li
export function exportAuditReportCsv(meta: ReplaySessionMeta, commands: CommandBookmark[]) {
const lines: string[] = [
'# 终端会话审计报告',
i18n.t('system.exportauditts.s3cb7eb59'),
`会话ID,${meta.id}`,
`用户,${escapeCsv(meta.username || '')}`,
`目标主机,${escapeCsv(meta.server_name || '')}`,
@@ -32,7 +33,7 @@ export function exportAuditReportCsv(meta: ReplaySessionMeta, commands: CommandB
`时长(秒),${meta.duration || 0}`,
`录制大小,${meta.record_size || 0}`,
'',
'时间偏移,命令,高危',
i18n.t('system.exportauditts.s7a85eed7'),
];
for (const c of commands) {
lines.push(`${c.label},${escapeCsv(c.command)},${c.highRisk ? '是' : '否'}`);
@@ -54,7 +55,7 @@ export interface CommandExportRow {
// exportCommandsListCsv 导出命令列表 CSV // Logan.Li
export function exportCommandsListCsv(commands: CommandExportRow[]) {
const lines: string[] = ['时间,用户,命令,输出大小,会话ID,高危'];
const lines: string[] = [i18n.t('system.exportauditts.s6e047305')];
for (const c of commands) {
const ts = c.timestamp || c.created_at || '';
const highRisk = isHighRiskCommand(c.command || '');
@@ -2,6 +2,7 @@
import { useState, useEffect, useCallback } from 'react';
import { toast } from 'sonner';
import { auditSettingsApi, type AuditSettings } from '@/api';
import i18n from '@/i18n';
const RETENTION_OPTIONS = [7, 15, 30, 90, 180, 365] as const;
@@ -20,7 +21,7 @@ export function useAuditSettings() {
setRetentionDays(String(data.retention_days || 180));
setRecordAll(data.record_all !== false);
} catch {
toast.error('加载审计设置失败');
toast.error(i18n.t('system.useauditsetting.s32e8a76e'));
} finally {
setLoading(false);
}
@@ -33,7 +34,7 @@ export function useAuditSettings() {
const handleApply = async () => {
const days = Number(retentionDays);
if (!RETENTION_OPTIONS.includes(days as (typeof RETENTION_OPTIONS)[number])) {
toast.error('请选择有效的保留天数');
toast.error(i18n.t('system.useauditsetting.s51680af0'));
return;
}
setApplying(true);
@@ -52,7 +53,7 @@ export function useAuditSettings() {
: `已应用 ${days} 天保留策略,暂无超期记录需清理`,
);
} catch (e: unknown) {
toast.error(e instanceof Error ? e.message : '应用失败');
toast.error(e instanceof Error ? e.message : i18n.t('kubernetes.msg.applyFailed'));
} finally {
setApplying(false);
}
@@ -66,7 +67,7 @@ export function useAuditSettings() {
try {
const s = JSON.parse(settings.last_cleanup_summary) as { total?: number };
if (typeof s.total === 'number') {
detail = s.total > 0 ? `,清理 ${s.total} 条` : ',无超期记录';
detail = s.total > 0 ? `,清理 ${s.total} 条` : i18n.t('system.useauditsetting.s7d55bd57');
}
} catch {
// ignore
@@ -4,6 +4,7 @@ import { useConfirm } from '@/components/ui/confirm-dialog';
import { ldapApi } from '@/api';
import type { LdapFormData } from './SystemSettingsTab';
import type { JsonData } from '@/types/common';
import i18n from '@/i18n';
/**
* useLdapManagement — 封装 SystemManager 中所有 LDAP 相关状态与业务逻辑
@@ -103,9 +104,9 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
try {
await ldapApi.updateConfig(ldapForm);
const res = await ldapApi.testConnection();
setLdapTestResult(res?.message || (res?.success ? '连接成功' : '连接失败'));
setLdapTestResult(res?.message || (res?.success ? i18n.t('aiops.llmTestSuccess') : i18n.t('aiops.llmTestFailed')));
} catch (error) {
setLdapTestResult(error?.message || '连接失败');
setLdapTestResult(error?.message || i18n.t('aiops.llmTestFailed'));
} finally {
setLdapTesting(false);
}
@@ -147,7 +148,7 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
if (msg.includes('Already Exists') || msg.includes('68')) {
toast.error(`OU "${ouForm.ou_name}" 已存在,请使用其他名称`);
} else {
toast.error('创建失败: ' + msg);
toast.error(i18n.t('system.useldapmanageme.sa2bddca3') + msg);
}
} finally { setLdapSaving(false); }
};
@@ -160,20 +161,20 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
setCreateUserOpen(false);
setNewUser({ username: '', password: '', display_name: '', email: '', ou_dn: '' });
await loadLdapOUUsers(selectedOUDN);
} catch (e) { toast.error(e?.message || '创建失败'); }
} catch (e) { toast.error(e?.message || i18n.t('monitor.dashboard.custom.toastCreateFailed')); }
finally { setLdapSaving(false); }
};
/** 删除 LDAP 条目 // Logan.Li */
const handleDeleteLDAPEntry = async (dn: string, silent = false) => {
if (!silent) {
const ok = await confirm({ title: '删除 LDAP 条目', description: `确定删除 ${dn}?`, confirmText: '删除', variant: 'destructive' });
const ok = await confirm({ title: i18n.t('system.useldapmanageme.s9724378b'), description: `确定删除 ${dn}?`, confirmText: i18n.t('kubernetes.storage.delete2'), variant: 'destructive' });
if (!ok) return;
}
try {
await ldapApi.deleteUser(dn);
if (!silent) await loadLdapOUUsers(selectedOUDN);
} catch (e) { if (!silent) toast.error(e?.message || '删除失败'); }
} catch (e) { if (!silent) toast.error(e?.message || i18n.t('kubernetes.msg.deleteFailed2')); }
};
/** 打开 LDAP 用户编辑 // Logan.Li */
@@ -189,7 +190,7 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
await ldapApi.updateUser({ dn: editLdapUser.dn, ...editLdapForm });
setEditLdapUser(null);
await loadLdapOUUsers(selectedOUDN);
} catch (e) { toast.error(e?.message || '修改失败'); }
} catch (e) { toast.error(e?.message || i18n.t('common.profilepagetsx.s5badb3ba')); }
};
/** LDAP 账号验证测试 // Logan.Li */
@@ -200,7 +201,7 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
const res = await ldapApi.testConnection({ test_user: ldapTestUser, test_password: ldapTestPass });
setLdapUserTestResult(res);
} catch (e) {
setLdapUserTestResult({ success: false, message: e?.message || '验证失败' });
setLdapUserTestResult({ success: false, message: e?.message || i18n.t('system.useldapmanageme.se441b11e') });
} finally { setLdapUserTesting(false); }
};
@@ -233,11 +234,11 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
} else if (opts?.importAll) {
selected = ldapUsers;
} else {
toast.error('请至少选择一个用户');
toast.error(i18n.t('system.useldapmanageme.sa8ca9651'));
return;
}
if (selected.length === 0) {
toast.error('没有可导入的用户');
toast.error(i18n.t('system.useldapmanageme.sd196a1c0'));
return;
}
setImporting(true);
@@ -263,8 +264,8 @@ export function useLdapManagement(onUsersChanged: () => Promise<void> | void) {
setSelectedLDAPUsers([]);
await onUsersChanged();
} catch (error: unknown) {
const errMsg = error instanceof Error ? error.message : '未知错误';
const result = { code: 500, message: '导入失败: ' + errMsg };
const errMsg = error instanceof Error ? error.message : i18n.t('monitor.dashboard.agent.toast.unknownError');
const result = { code: 500, message: i18n.t('system.useldapmanageme.s45332d13') + errMsg };
if (opts?.setResult) {
opts.setResult(result);
} else {