Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(i18n): 回应多语言审核反馈

david6f09e737f1d2
diff --git a/apps/desktop/src/main/i18n.ts b/apps/desktop/src/main/i18n.ts
index 32acf5fe4c..de6112a672 100644
--- a/apps/desktop/src/main/i18n.ts
+++ b/apps/desktop/src/main/i18n.ts
@@ -111,8 +111,8 @@ function lookup(bundle: Record<string, unknown>, key: string): string | null {
* {{appName}} 由品牌常量注入(本迷你 i18n 不支持其它变量,main 消费的 key 若
* 需要更多插值,应像 bootstrap 菜单那样在调用点自行 replace)。
*/
-export function t(key: string): string {
- const loc = getMainLocale();
+export function t(key: string, locale?: SupportedLocale): string {
+ const loc = locale ?? getMainLocale();
let raw: string | null = null;
for (const chainLocale of FALLBACK_CHAIN[loc]) {
raw = lookup(resources[chainLocale], key);
diff --git a/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts b/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts
index b0078ae709..7f8a0bbe1f 100644
--- a/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts
+++ b/apps/desktop/src/main/resource-usage-window/__tests__/controller.test.ts
@@ -14,6 +14,7 @@ interface FakeWindow {
destroy: ReturnType<typeof vi.fn>;
hide: ReturnType<typeof vi.fn>;
show: ReturnType<typeof vi.fn>;
+ setTitle: ReturnType<typeof vi.fn>;
focus: ReturnType<typeof vi.fn>;
restore: ReturnType<typeof vi.fn>;
setFullScreen: ReturnType<typeof vi.fn>;
@@ -75,6 +76,7 @@ function fakeWindow(id: number, minimized = false): FakeWindow {
show: vi.fn(() => {
visible = true;
}),
+ setTitle: vi.fn(),
focus: vi.fn(),
restore: vi.fn(),
setFullScreen: vi.fn(),
@@ -168,12 +170,13 @@ describe('ResourceUsageWindowController', () => {
expect(windows[0]?.focus).toHaveBeenCalledOnce();
});
- it('sends locale changes to an already prewarmed window', () => {
+ it('updates the native title and renderer locale of an already prewarmed window', () => {
const { controller, windows } = makeHarness();
controller.prewarm();
controller.setLocale('zh-CN');
+ expect(windows[0]?.setTitle).toHaveBeenCalledWith('资源用量');
expect(windows[0]?.send).toHaveBeenCalledWith(
RESOURCE_USAGE_WINDOW_LOCALE_CHANGED_CHANNEL,
'zh-CN',
diff --git a/apps/mobile/app/automations/[deviceId].tsx b/apps/mobile/app/automations/[deviceId].tsx
index f817a56b50..63b219261d 100644
--- a/apps/mobile/app/automations/[deviceId].tsx
+++ b/apps/mobile/app/automations/[deviceId].tsx
@@ -81,6 +81,10 @@ import {
type MobileScheduleDraft,
} from '@/scheduler/scheduleFormModel';
import { useRemoteScheduleEventSnapshot } from '@/scheduler/remoteScheduleEvents';
+import {
+ buildMobileTemplateOverrides,
+ isLocalizedBuiltinTemplate,
+} from '@/scheduler/scheduleTemplateLocalization';
import type {
RemoteSchedule,
RemoteScheduleRun,
@@ -428,11 +432,10 @@ export default function AutomationsScreen() {
return withTransientRemoteRetry(() => maker.schedule.update(formScheduleId, wireInput));
}
if (selectedTemplate && !templatePromptDirty) {
- const { prompt: _templatePrompt, ...overrides } = wireInput;
return maker.schedule.createFromTemplate({
templateId: selectedTemplate.id,
paramValues: templateParamValues,
- overrides,
+ overrides: buildMobileTemplateOverrides(wireInput, selectedTemplate),
});
}
return maker.schedule.create(wireInput);
@@ -970,7 +973,9 @@ export default function AutomationsScreen() {
</View>
{displayedRuns.length === 0 ? (
<MainWindowEmptyState
- copy={t('devices.automations.runs.emptyCopy')}
+ copy={t('devices.automations.runs.emptyCopy', {
+ runNow: t('devices.automations.runNow'),
+ })}
style={styles.emptyInline}
title={t('devices.automations.runs.emptyTitle')}
/>
@@ -2158,20 +2163,11 @@ const TEMPLATE_CATEGORY_RANK: Record<string, number> = {
'office-docs': 3,
};
-const BUILTIN_TEMPLATE_IDS = new Set([
- 'nightly-test-heal',
- 'pr-gatekeeper',
- 'domain-radar',
- 'competitor-watch',
- 'weekly-work-draft',
- 'knowledge-freshness',
-]);
-
function localizeBuiltinTemplate(
template: RemoteScheduleTemplate,
t: TFunction,
): RemoteScheduleTemplate {
- if (template.source !== 'builtin' || !BUILTIN_TEMPLATE_IDS.has(template.id)) return template;
+ if (!isLocalizedBuiltinTemplate(template)) return template;
const prefix = `devices.automations.template.builtin.${template.id}`;
const templateVariables = Object.fromEntries(
(template.parameters ?? []).map((parameter) => [parameter.key, `{{${parameter.key}}}`]),
diff --git a/apps/mobile/src/__tests__/scheduleTemplateLocalization.test.ts b/apps/mobile/src/__tests__/scheduleTemplateLocalization.test.ts
new file mode 100644
index 0000000000..efcb8d4636
--- /dev/null
+++ b/apps/mobile/src/__tests__/scheduleTemplateLocalization.test.ts
@@ -0,0 +1,47 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ buildMobileTemplateOverrides,
+ isLocalizedBuiltinTemplate,
+} from '@/scheduler/scheduleTemplateLocalization';
+import type { RemoteScheduleTemplate, RemoteScheduleWriteInput } from '@/scheduler/types';
+
+const input: RemoteScheduleWriteInput = {
+ name: 'Nightly test repair',
+ prompt: 'Run the test suite and repair clear failures.',
+ kind: 'cron',
+ cronExpr: '0 2 * * *',
+ timezone: 'Asia/Shanghai',
+ recurring: true,
+ agentKind: 'codex',
+ useWorktree: true,
+ notify: { desktop: true, feishu: false },
+};
+
+function template(patch: Partial<RemoteScheduleTemplate> = {}): RemoteScheduleTemplate {
+ return {
+ id: 'nightly-test-heal',
+ name: 'Nightly Test Repair',
+ description: 'Run tests and repair clear failures.',
+ category: 'dev-automation',
+ source: 'builtin',
+ prompt: '运行测试套件并修复明确的失败。',
+ ...patch,
+ };
+}
+
+describe('mobile schedule template localization', () => {
+ it('persists the prompt reviewed in the form for localized built-in templates', () => {
+ const builtin = template();
+
+ expect(isLocalizedBuiltinTemplate(builtin)).toBe(true);
+ expect(buildMobileTemplateOverrides(input, builtin)).toEqual(input);
+ });
+
+ it('keeps the existing desktop-canonical prompt behavior for other templates', () => {
+ const overrides = buildMobileTemplateOverrides(input, template({ id: 'custom', source: 'user' }));
+
+ expect(overrides).not.toHaveProperty('prompt');
+ expect(overrides).toMatchObject({ name: input.name, cronExpr: input.cronExpr });
+ });
+});
diff --git a/apps/mobile/src/i18n/locales/en/devices.json b/apps/mobile/src/i18n/locales/en/devices.json
index 44a1fa781e..ea638ace8a 100644
--- a/apps/mobile/src/i18n/locales/en/devices.json
+++ b/apps/mobile/src/i18n/locales/en/devices.json
@@ -401,7 +401,7 @@
"createAutomation": "New Automation",
"recentRuns": "Recent Runs",
"runs": {
- "emptyCopy": "After you tap Run now, new runs show up here.",
+ "emptyCopy": "After you tap {{runNow}}, new runs show up here.",
"emptyTitle": "No runs yet"
},
"form": {
diff --git a/apps/mobile/src/i18n/locales/ja/devices.json b/apps/mobile/src/i18n/locales/ja/devices.json
index 06a77ba70b..932406e852 100644
--- a/apps/mobile/src/i18n/locales/ja/devices.json
+++ b/apps/mobile/src/i18n/locales/ja/devices.json
@@ -401,7 +401,7 @@
"createAutomation": "自動化を新規作成",
"recentRuns": "最近の実行",
"runs": {
- "emptyCopy": "Run now をタップすると、新しい実行がここに表示されます。",
+ "emptyCopy": "「{{runNow}}」をタップすると、新しい実行がここに表示されます。",
"emptyTitle": "まだ実行記録がありません"
},
"form": {
diff --git a/apps/mobile/src/i18n/locales/ko/devices.json b/apps/mobile/src/i18n/locales/ko/devices.json
index c72e5d8537..bc1dbaa9e1 100644
--- a/apps/mobile/src/i18n/locales/ko/devices.json
+++ b/apps/mobile/src/i18n/locales/ko/devices.json
@@ -401,7 +401,7 @@
"createAutomation": "자동화 새로 만들기",
"recentRuns": "최근 실행",
"runs": {
- "emptyCopy": "Run now를 누르면 새 실행이 여기에 표시됩니다.",
+ "emptyCopy": "‘{{runNow}}’을 누르면 새 실행이 여기에 표시됩니다.",
"emptyTitle": "아직 실행 기록이 없습니다"
},
"form": {
diff --git a/apps/mobile/src/i18n/locales/zh-CN/devices.json b/apps/mobile/src/i18n/locales/zh-CN/devices.json
index 17a39a5e21..eedea8022d 100644
--- a/apps/mobile/src/i18n/locales/zh-CN/devices.json
+++ b/apps/mobile/src/i18n/locales/zh-CN/devices.json
@@ -401,7 +401,7 @@
"createAutomation": "新建自动化",
"recentRuns": "最近执行",
"runs": {
- "emptyCopy": "点击 Run now 后会在这里看到新 run。",
+ "emptyCopy": "点击“{{runNow}}”后,新的执行会显示在这里。",
"emptyTitle": "还没有执行记录"
},
"form": {
diff --git a/apps/mobile/src/i18n/locales/zh-TW/devices.json b/apps/mobile/src/i18n/locales/zh-TW/devices.json
index 0521bfc852..5ffc5ceeb9 100644
--- a/apps/mobile/src/i18n/locales/zh-TW/devices.json
+++ b/apps/mobile/src/i18n/locales/zh-TW/devices.json
@@ -401,7 +401,7 @@
"createAutomation": "新建自動化",
"recentRuns": "最近執行",
"runs": {
- "emptyCopy": "點選 Run now 後會在這裡看到新 run。",
+ "emptyCopy": "點選「{{runNow}}」後,新的執行會顯示在這裡。",
"emptyTitle": "還沒有執行記錄"
},
"form": {
diff --git a/apps/mobile/src/scheduler/scheduleTemplateLocalization.ts b/apps/mobile/src/scheduler/scheduleTemplateLocalization.ts
new file mode 100644
index 0000000000..0eef653562
--- /dev/null
+++ b/apps/mobile/src/scheduler/scheduleTemplateLocalization.ts
@@ -0,0 +1,27 @@
+import type { RemoteScheduleTemplate, RemoteScheduleWriteInput } from './types';
+
+const LOCALIZED_BUILTIN_TEMPLATE_IDS = new Set([
+ 'nightly-test-heal',
+ 'pr-gatekeeper',
+ 'domain-radar',
+ 'competitor-watch',
+ 'weekly-work-draft',
+ 'knowledge-freshness',
+]);
+
+export function isLocalizedBuiltinTemplate(template: RemoteScheduleTemplate): boolean {
+ return template.source === 'builtin' && LOCALIZED_BUILTIN_TEMPLATE_IDS.has(template.id);
+}
+
+/**
+ * Only localized built-ins override the desktop template prompt: users must execute the exact
+ * prompt they reviewed on mobile. Other templates keep the existing desktop-canonical behavior.
+ */
+export function buildMobileTemplateOverrides(
+ input: RemoteScheduleWriteInput,
+ template: RemoteScheduleTemplate,
+): Partial<RemoteScheduleWriteInput> {
+ if (isLocalizedBuiltinTemplate(template)) return input;
+ const { prompt: _templatePrompt, ...overrides } = input;
+ return overrides;
+}