diff --git a/src/web/public/i18n.js b/src/web/public/i18n.js index e9cb509b..8deb90ce 100644 --- a/src/web/public/i18n.js +++ b/src/web/public/i18n.js @@ -798,6 +798,8 @@ // Dynamic common status / toasts 'Settings saved': '设置已保存', + // The once-per-release toast (settings-ui.js checkWhatsNew); its highlights stay English. + "See what's new": '查看更新内容', 'Settings applied': '设置已应用', 'Save and keep Settings open': '保存并保持设置打开', 'Settings saved locally': '设置已保存到本机', @@ -1244,6 +1246,10 @@ [/^Update to v(.+)$/, (_m, version) => `更新到 v${version}`], [/^You're up to date \(v(.+)\)\.$/, (_m, version) => `已是最新版本(v${version})。`], [/^Update available: v(.+)$/, (_m, version) => `有可用更新:v${version}`], + [ + /^Codeman updated to v([^:\s]+): (.+?)(?: \(\+(\d+) more\))?$/, + (_m, version, shown, more) => `Codeman 已更新到 v${version}:${shown}${more ? `(另有 ${more} 项)` : ''}`, + ], [/^Selected: (.+)$/, (_m, value) => `已选择:${value}`], [/^Failed to (.+)$/, (_m, action) => `操作失败:${action}`], [/^Will create: (.+)$/, (_m, path) => `将创建:${path}`], diff --git a/test/whats-new.test.ts b/test/whats-new.test.ts index 84264a5c..15eff559 100644 --- a/test/whats-new.test.ts +++ b/test/whats-new.test.ts @@ -1,6 +1,8 @@ import { describe, it, expect } from 'vitest'; import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; +import vm from 'node:vm'; +import { JSDOM } from 'jsdom'; // @ts-expect-error plain .mjs helper shared with scripts/generate-whats-new.mjs import { extractHighlights, versionSection, buildWhatsNew } from '../scripts/lib/whats-new.mjs'; @@ -95,3 +97,32 @@ describe('shipped whats-new.json', () => { ); }); }); + +describe('the announcement in zh-CN', () => { + const dom = new JSDOM('', { + runScripts: 'outside-only', + url: 'http://localhost/', + }); + vm.runInContext(readFileSync(resolve(root, 'src/web/public/i18n.js'), 'utf8'), dom.getInternalVMContext()); + const api = ( + dom.window as unknown as { CodemanI18n: { t(s: string): string; configure(o: Record): void } } + ).CodemanI18n; + api.configure({ language: 'zh-CN' }); + + it('translates the button and the toast frame, keeping the version and the English highlights', () => { + expect(api.t("See what's new")).toBe('查看更新内容'); + expect(api.t('Codeman updated to v1.41.2: Tab layouts (#538) · Split view')).toBe( + 'Codeman 已更新到 v1.41.2:Tab layouts (#538) · Split view' + ); + expect(api.t('Codeman updated to v1.41.2: A · B · C (+5 more)')).toBe( + 'Codeman 已更新到 v1.41.2:A · B · C(另有 5 项)' + ); + }); + + it('builds the strings the pattern expects', () => { + const ui = readFileSync(resolve(root, 'src/web/public/settings-ui.js'), 'utf8'); + expect(ui).toContain('`Codeman updated to v${runningVersion}: ${shown}${more}`'); + expect(ui).toContain('` (+${notes.highlights.length - 3} more)`'); + expect(ui).toContain(`label: "See what's new"`); + }); +});