feat(i18n): the tab's exited-agent badge in Chinese (zh-CN)

Owner request: translate the EXITED badge. The badge carried
data-i18n-skip on purpose, because its in-place update compared the DOM
with the English label: a translated badge would never have matched, and
every incremental tab pass would have written English back for the
translator to redo. The tab's accessible name (which carries the exit,
the badge being aria-hidden) was set unconditionally on every pass, the
same trap once it is translated.

Now the badge is left to the translator. applyPaneExitBadge remembers the
last English badge text (data-label) and accessible name
(data-aria-source), both also seeded by the full render, and compares
with those, never the DOM. The tab strip's incremental path updates tabs
in place (no row-HTML comparison), so nothing else re-renders on a
translated badge.

i18n.js: "exited" -> 已退出, patterns for "exited (N)" -> 已退出(N) and
"exited (signal N)" -> 已退出(信号 N), and for the accessible name
"<name> session, agent exited ..." -> "<name> 会话,智能体已退出 ...", the
session name passed through untranslated. The header strip, the session
sidebar and the vertical rail all host the same tab markup, so this
covers all three. English reads exactly as before.

Tests: session-pane-exit-ui pins the new markup, the remembered English
and that a translated badge and accessible name survive an unchanged
pass; i18n-exit-run-help runs every paneExitLabel form (and the
accessible name, with names that are dictionary words) through the real
translator in both languages.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer
2026-10-07 02:07:27 +02:00
parent dfb9f32e23
commit 66da91f78b
4 changed files with 139 additions and 13 deletions
+25 -4
View File
@@ -92,10 +92,27 @@ describe('the exited-agent badge in a tab', () => {
expect(tab.querySelector('.tab-name')?.nextElementSibling?.className).toBe('tab-exited-badge');
});
it('marks the badge data-i18n-skip, like the other generated status text', () => {
it('leaves the badge to the translator (zh-CN) and remembers its English', () => {
const tab = makeTab();
applyPaneExitBadge(tab, { status: 0, at: 1 });
expect(badge(tab)?.hasAttribute('data-i18n-skip')).toBe(true);
expect(badge(tab)?.hasAttribute('data-i18n-skip')).toBe(false);
expect((badge(tab) as unknown as HTMLElement).dataset.label).toBe('exited (0)');
});
it('a translated badge and accessible name survive an unchanged pass; a change writes the new English', () => {
// The translator rewrites both in zh-CN. Comparing with the DOM would write
// the English back on every incremental pass for it to translate again.
const tab = makeTab();
applyPaneExitBadge(tab, { status: 3, at: 1 });
const el = badge(tab) as unknown as HTMLElement;
el.textContent = '已退出(3)';
tab.setAttribute('aria-label', 'w1-case 会话,智能体已退出(3)');
applyPaneExitBadge(tab, { status: 3, at: 1 });
expect(el.textContent).toBe('已退出(3)');
expect(tab.getAttribute('aria-label')).toBe('w1-case 会话,智能体已退出(3)');
applyPaneExitBadge(tab, { signal: 9, at: 2 });
expect(el.textContent).toBe('exited (signal 9)');
expect(tab.getAttribute('aria-label')).toBe('w1-case session, agent exited (signal 9)');
});
it('hides the badge from assistive technology, like its sibling badges', () => {
@@ -115,8 +132,12 @@ describe('the exited-agent badge in a tab', () => {
});
it('builds the full render path accessible name from the same helper', () => {
expect(appJs).toContain('aria-label="${escapeHtml(paneExitAriaLabel(name, paneExitBadge))}"');
expect(appJs).toContain('<span class="tab-exited-badge" data-i18n-skip aria-hidden="true">');
expect(appJs).toContain(
'aria-label="${escapeHtml(paneExitAriaLabel(name, paneExitBadge))}" data-aria-source="${escapeHtml(paneExitAriaLabel(name, paneExitBadge))}"'
);
expect(appJs).toContain(
'<span class="tab-exited-badge" data-label="${escapeHtml(paneExitBadge)}" aria-hidden="true">'
);
});
it('updates the text in place rather than stacking a second badge', () => {