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

+22 -21
View File
@@ -23,6 +23,7 @@ import { PageShell } from '@/components/layout/PageShell';
import { ContentPanel } from '@/components/layout/ContentPanel';
import { PageEmpty } from '@/components/layout/PageEmpty';
import type { JsonData } from '@/types/common';
import i18n from '@/i18n';
export function ScriptManager() {
const _confirm = useConfirm();
@@ -51,7 +52,7 @@ export function ScriptManager() {
const items = (res as JsonData)?.list || [];
setScripts(items.map(mapScript));
} catch {
toast.error('获取脚本列表失败');
toast.error(i18n.t('task.scriptmanagerts.s0fa2607f'));
} finally {
setLoading(false);
}
@@ -112,7 +113,7 @@ export function ScriptManager() {
const handleSave = async () => {
if (!formData.name.trim() || !formData.content.trim()) {
toast.error('请填写名称和脚本内容');
toast.error(i18n.t('task.scriptmanagerts.s54c121b2'));
return;
}
const payload = {
@@ -126,15 +127,15 @@ export function ScriptManager() {
try {
if (editingId !== null) {
await scriptApi.updateScript(editingId, payload);
toast.success('脚本更新成功');
toast.success(i18n.t('task.scriptmanagerts.sdb91e3c4'));
} else {
await scriptApi.createScript(payload);
toast.success('脚本创建成功');
toast.success(i18n.t('task.scriptmanagerts.s4aac59ea'));
}
setEditorOpen(false);
fetchScripts();
} catch (e) {
toast.error(e instanceof Error ? e.message : (editingId !== null ? '更新失败' : '创建失败'));
toast.error(e instanceof Error ? e.message : (editingId !== null ? i18n.t('kubernetes.deployment.imageUpdateFailed') : i18n.t('monitor.dashboard.custom.toastCreateFailed')));
}
};
@@ -148,27 +149,27 @@ export function ScriptManager() {
content: sc.content,
timeout: sc.timeout,
});
toast.success('复制成功');
toast.success(i18n.t('common.copySuccess'));
fetchScripts();
} catch (e) {
toast.error(e instanceof Error ? e.message : '复制失败');
toast.error(e instanceof Error ? e.message : i18n.t('monitor.logPanel.copyFailed'));
}
};
const handleDelete = async (sc: Script) => {
const ok = await _confirm({
title: '删除脚本',
title: i18n.t('automation.deleteScript'),
description: `确定删除「${sc.name}」吗?此操作不可恢复。`,
confirmText: '删除',
confirmText: i18n.t('kubernetes.storage.delete2'),
variant: 'destructive',
});
if (!ok) return;
try {
await scriptApi.deleteScript(sc.id);
toast.success('删除成功');
toast.success(i18n.t('kubernetes.msg.deleteSuccess'));
fetchScripts();
} catch (e) {
toast.error(e instanceof Error ? e.message : '删除失败');
toast.error(e instanceof Error ? e.message : i18n.t('kubernetes.msg.deleteFailed2'));
}
};
@@ -193,9 +194,9 @@ export function ScriptManager() {
const handleBatchDelete = async () => {
if (selectedIds.length === 0) return;
const ok = await _confirm({
title: '批量删除脚本',
title: i18n.t('task.scriptmanagerts.sd730a0fc'),
description: `确定删除选中的 ${selectedIds.length} 个脚本吗?此操作不可恢复。`,
confirmText: '批量删除',
confirmText: i18n.t('system.terminalBatchDelete'),
variant: 'destructive',
});
if (!ok) return;
@@ -205,7 +206,7 @@ export function ScriptManager() {
setSelectedIds([]);
fetchScripts();
} catch (e) {
toast.error(e instanceof Error ? e.message : '批量删除失败');
toast.error(e instanceof Error ? e.message : i18n.t('system.batchDeleteFailed'));
}
};
@@ -215,7 +216,7 @@ export function ScriptManager() {
<div className="relative flex-1">
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 dg-text-muted" />
<Input
placeholder="搜索名称、描述..."
placeholder={i18n.t('deploy.label.searchPlaceholder')}
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-10 dg-input"
@@ -223,10 +224,10 @@ export function ScriptManager() {
</div>
<Select value={typeFilter} onValueChange={setTypeFilter}>
<SelectTrigger className="w-[140px] dg-input">
<SelectValue placeholder="类型" />
<SelectValue placeholder={i18n.t('system.credentialType')} />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">全部类型</SelectItem>
<SelectItem value="all"> {i18n.t('k8s.topology.allTypes')} </SelectItem>
{scriptTypes.map(t => (
<SelectItem key={t.value} value={t.value}>{t.label}</SelectItem>
))}
@@ -240,8 +241,8 @@ export function ScriptManager() {
<>
<PageShell
variant="list"
title="脚本库"
subtitle="脚本编辑与管理"
title={i18n.t('automation.scripts')}
subtitle={i18n.t('task.scriptmanagerts.sed1decc7')}
icon={<FileCode className="h-5 w-5" />}
toolbar={toolbar}
loading={loading}
@@ -294,8 +295,8 @@ export function ScriptManager() {
{filteredScripts.length === 0 ? (
<PageEmpty
title={scripts.length === 0 ? '暂无脚本' : '未匹配到符合条件的脚本'}
description={scripts.length === 0 ? '点击「新建脚本」创建第一个' : undefined}
title={scripts.length === 0 ? i18n.t('automation.noScript') : i18n.t('task.scriptmanagerts.s83533de7')}
description={scripts.length === 0 ? i18n.t('task.scriptmanagerts.sc31b6baa') : undefined}
action={scripts.length === 0 && canWrite ? (
<Button className="dg-btn-primary" onClick={openCreate}>
<Plus className="w-4 h-4 mr-2" />