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:
1 parent
72bfb0e12d
commit
55f216cfbb
131 files changed
+4049
-1908
No files matched your search
@@ -22,13 +22,14 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { toast } from 'sonner';
|
||||
import { cronJobApi, scriptApi } from '@/api';
|
||||
import type { JsonData } from '@/types/common';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
// 定时任务类型定义 // Logan.Li
|
||||
const jobTypes = [
|
||||
{ value: 'shell', label: 'Shell', desc: '关联脚本库中的 Shell 脚本' },
|
||||
{ value: 'python', label: 'Python', desc: '关联脚本库中的 Python 脚本' },
|
||||
{ value: 'powershell', label: 'PowerShell', desc: '关联脚本库中的 PowerShell 脚本' },
|
||||
{ value: 'command', label: '自定义命令', desc: '手动输入命令或脚本路径' },
|
||||
{ value: 'shell', label: 'Shell', desc: i18n.t('task.cronjobformdial.s570531a7') },
|
||||
{ value: 'python', label: 'Python', desc: i18n.t('task.cronjobformdial.s021fae85') },
|
||||
{ value: 'powershell', label: 'PowerShell', desc: i18n.t('task.cronjobformdial.s783cca2d') },
|
||||
{ value: 'command', label: i18n.t('task.cronjobformdial.sad6526bb'), desc: i18n.t('task.cronjobformdial.s492a4c28') },
|
||||
];
|
||||
|
||||
const scriptJobTypes = ['shell', 'python', 'powershell'];
|
||||
@@ -120,12 +121,12 @@ export function CronJobFormDialog({
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!form.name || !form.cron_expr) {
|
||||
toast.error('请填写任务名称和 Cron 表达式');
|
||||
toast.error(i18n.t('task.cronjobformdial.s69fb01d7'));
|
||||
return;
|
||||
}
|
||||
// 脚本类型必须选关联脚本 // Logan.Li
|
||||
if (scriptJobTypes.includes(form.type) && !form.script_id) {
|
||||
toast.error('请选择关联的脚本');
|
||||
toast.error(i18n.t('task.cronjobformdial.sd4df2957'));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -140,16 +141,16 @@ export function CronJobFormDialog({
|
||||
};
|
||||
if (editJob) {
|
||||
await cronJobApi.updateJob(editJob.id, payload);
|
||||
toast.success('任务更新成功');
|
||||
toast.success(i18n.t('task.cronjobformdial.s8398c31d'));
|
||||
} else {
|
||||
await cronJobApi.createJob(payload);
|
||||
toast.success('任务创建成功');
|
||||
toast.success(i18n.t('task.cronjobformdial.s3799bdae'));
|
||||
}
|
||||
onOpenChange(false);
|
||||
onSuccess();
|
||||
} catch (error) {
|
||||
console.error('Failed to save cron job:', error);
|
||||
toast.error(editJob ? '更新失败' : '创建失败');
|
||||
toast.error(editJob ? i18n.t('kubernetes.deployment.imageUpdateFailed') : i18n.t('monitor.dashboard.custom.toastCreateFailed'));
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
@@ -159,28 +160,28 @@ export function CronJobFormDialog({
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-2xl bg-[var(--dg-bg-primary)] border-[var(--dg-border)] text-[var(--dg-text-primary)]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{editJob ? '编辑定时任务' : '新建定时任务'}</DialogTitle>
|
||||
<DialogDescription className="text-[var(--dg-text-secondary)]">配置 Cron 定时任务</DialogDescription>
|
||||
<DialogTitle>{editJob ? i18n.t('automation.editCronJob') : i18n.t('task.cronjobformdial.s1b9746cb')}</DialogTitle>
|
||||
<DialogDescription className="text-[var(--dg-text-secondary)]"> {i18n.t('task.cronjobformdial.s2e10ee70')} </DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4 max-h-[60vh] overflow-y-auto pr-1">
|
||||
{/* 任务名称 */}
|
||||
<div>
|
||||
<Label className="text-[var(--dg-text-primary)]">任务名称</Label>
|
||||
<Label className="text-[var(--dg-text-primary)]"> {i18n.t('automation.cronJobName')} </Label>
|
||||
<Input
|
||||
value={form.name}
|
||||
onChange={(e) => setForm({ ...form, name: e.target.value })}
|
||||
placeholder="例如: 数据库备份"
|
||||
placeholder={i18n.t('task.cronjobformdial.s2c69d350')}
|
||||
className="bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] text-[var(--dg-text-primary)] mt-1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* 描述 */}
|
||||
<div>
|
||||
<Label className="text-[var(--dg-text-primary)]">描述</Label>
|
||||
<Label className="text-[var(--dg-text-primary)]"> {i18n.t('aiops.llmModelDesc')} </Label>
|
||||
<Textarea
|
||||
value={form.description}
|
||||
onChange={(e) => setForm({ ...form, description: e.target.value })}
|
||||
placeholder="任务描述..."
|
||||
placeholder={i18n.t('task.cronjobformdial.s405de06b')}
|
||||
rows={2}
|
||||
className="bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] text-[var(--dg-text-primary)] mt-1"
|
||||
/>
|
||||
@@ -198,23 +199,23 @@ export function CronJobFormDialog({
|
||||
/>
|
||||
<Select onValueChange={(v) => setForm({ ...form, cron_expr: v })}>
|
||||
<SelectTrigger className="w-48 bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] text-[var(--dg-text-primary)] mt-1">
|
||||
<SelectValue placeholder="快速选择" />
|
||||
<SelectValue placeholder={i18n.t('task.cronjobformdial.s1b054b19')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="bg-[var(--dg-bg-secondary)] border-[var(--dg-border)]">
|
||||
<SelectItem value="*/5 * * * *" className="text-[var(--dg-text-primary)]">每 5 分钟</SelectItem>
|
||||
<SelectItem value="0 * * * *" className="text-[var(--dg-text-primary)]">每小时</SelectItem>
|
||||
<SelectItem value="0 2 * * *" className="text-[var(--dg-text-primary)]">每天 02:00</SelectItem>
|
||||
<SelectItem value="0 3 * * 0" className="text-[var(--dg-text-primary)]">每周日 03:00</SelectItem>
|
||||
<SelectItem value="0 9 * * 1" className="text-[var(--dg-text-primary)]">每周一 09:00</SelectItem>
|
||||
<SelectItem value="*/5 * * * *" className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronJob.cron.every5min')} </SelectItem>
|
||||
<SelectItem value="0 * * * *" className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronJob.cron.everyHour')} </SelectItem>
|
||||
<SelectItem value="0 2 * * *" className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronJob.cron.daily2')} </SelectItem>
|
||||
<SelectItem value="0 3 * * 0" className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronJob.cron.weeklySun3')} </SelectItem>
|
||||
<SelectItem value="0 9 * * 1" className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronJob.cron.weeklyMon9')} </SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<p className="text-xs text-[var(--dg-text-muted)] mt-1">格式: 分 时 日 月 周</p>
|
||||
<p className="text-xs text-[var(--dg-text-muted)] mt-1"> {i18n.t('task.cronjobformdial.s3b56b1f9')} </p>
|
||||
</div>
|
||||
|
||||
{/* 执行类型 */}
|
||||
<div>
|
||||
<Label className="text-[var(--dg-text-primary)]">执行类型</Label>
|
||||
<Label className="text-[var(--dg-text-primary)]"> {i18n.t('task.cronjobformdial.s15d864c1')} </Label>
|
||||
<div className="grid grid-cols-2 sm:grid-cols-4 gap-2 mt-1">
|
||||
{jobTypes.map(t => (
|
||||
<button
|
||||
@@ -258,7 +259,7 @@ export function CronJobFormDialog({
|
||||
onValueChange={handleSelectScript}
|
||||
>
|
||||
<SelectTrigger className="bg-[var(--dg-bg-secondary)] border-[var(--dg-border)] text-[var(--dg-text-primary)] mt-1">
|
||||
<SelectValue placeholder="选择脚本库中的脚本..." />
|
||||
<SelectValue placeholder={i18n.t('task.cronjobformdial.s3e4f7c4d')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="bg-[var(--dg-bg-secondary)] border-[var(--dg-border)]">
|
||||
{filteredScripts.map(sc => (
|
||||
@@ -283,14 +284,14 @@ export function CronJobFormDialog({
|
||||
</span>
|
||||
</div>
|
||||
<pre className="max-h-48 overflow-auto rounded-md bg-[var(--dg-bg-tertiary)] border border-[var(--dg-border)] p-3 text-xs font-mono text-[var(--dg-text-secondary)] whitespace-pre-wrap break-all">
|
||||
{selectedScript.content || '(空脚本)'}
|
||||
{selectedScript.content || i18n.t('task.cronjobformdial.s331ff82e')}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div>
|
||||
<Label className="text-[var(--dg-text-primary)]">执行命令</Label>
|
||||
<Label className="text-[var(--dg-text-primary)]"> {i18n.t('aiops.assistantCommand')} </Label>
|
||||
<Textarea
|
||||
value={form.content}
|
||||
onChange={(e) => setForm({ ...form, content: e.target.value })}
|
||||
@@ -310,7 +311,7 @@ export function CronJobFormDialog({
|
||||
onClick={handleSave}
|
||||
disabled={submitting}
|
||||
>
|
||||
{submitting ? '保存中...' : editJob ? '保存修改' : '创建任务'}
|
||||
{submitting ? i18n.t('system.savingDot') : editJob ? i18n.t('cloud.saveChanges') : i18n.t('monitor.sitemonitortsx.s6ef95fe9')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
|
||||
Reference in new issue
Block a user