mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-12-01 16:59:32 +01:00
fix(#618): translate the release toast for zh-CN
The toast every user sees once per release had no zh-CN entries, so a Chinese interface showed it, button included, in English. The button gets an entry and the frame a translateDynamic pattern that keeps the version, the "(+N more)" count and the highlights (those come from CHANGELOG.md and stay English). Tested through the real i18n.js in JSDOM, plus a pin on the strings settings-ui.js builds, which the pattern depends on. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
71439c525b
commit
a61db218ee
2 files changed
+37
No files matched your search
@@ -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('<!doctype html><html><body></body></html>', {
|
||||
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<string, string>): 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"`);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user