Skip to content

Commit 22d5eee

Browse files
fix(plugin-detail): translate the related list count badge's accessible name (#39719)
<!-- claude-projects-attribution: {"github_login":"os-elon-musk"} --> _Requested by **Elon** · [project thread](https://claude.ai/code/project/chan_01WedDzV26nniwxv7jC88B9D?thread=cmsg_01WedDzV26nniwxv7jC88B9D6q8dUDEiRaQSo6oAsacVv3)_ Fixes #39680 Clause-②: no Metadata-protocol: none ## 维护者速读 - 用读屏软件的用户在记录详情页的相关列表标题处,原先听到的条数总是英文,现在按控制台语言播报,中文控制台读作「3 条记录」,英文在 1 条时读单数。 - 属于控制台多语言补全,替非英文界面的读屏用户解决。 - 若有问题,只影响读屏播报的文字,画面上的数字不变,可直接撤回。 - 无 ## What changes The related list header's count badge drew a bare number whose `aria-label` was the hard-coded English template "N records". It now reads the translated pair the same component already uses for the tab list's summary row lead (`tabRecordCountLead`: `detail.relatedRecordOne` at one record, `detail.relatedRecords` otherwise). The visible number is unchanged. - `ui/packages/plugin-detail/src/RelatedList.tsx`: the badge's `aria-label` only. - `ui/packages/plugin-detail/src/RelatedList.i18n.test.tsx` (new pin, beside the component): zh-CN at 3 rows reads 「3 条记录」, en at 1 reads "1 record", en at 3 reads "3 records", de at 1 reads "1 Datensatz". - `ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx`: the `headBadge` selector matched only a label ending in " records"; its one-row case now correctly reads "1 record", so the selector matches either suffix (one line, claim amendment 7413253105). - `.changeset/39680-related-list-count-badge-name.md`: `@object-ui/plugin-detail` patch. Read first, by risk: 1. `RelatedList.tsx`, the count badge hunk (the only runtime change). 2. `RelatedList.countPending-36235.test.tsx`, the `headBadge` selector. Two-minute check: `pnpm --dir ui exec vitest run packages/plugin-detail/src/RelatedList.i18n.test.tsx` from the repo root, expect 4 passed. ## Tests Read at head 646a0f3. <details><summary>Targeted suites: 5 files, 46 passed</summary> `pnpm --dir ui exec vitest run --maxWorkers=2` over the new pin, `RelatedList.countPending-36235`, `RelatedList.addPickerGuard` (asserts the plural label by text), `RelatedPanel.header-27524` and `RelatedList.tab-35892`: `Test Files 5 passed (5)`, `Tests 46 passed (46)`, lock VERDICT command-exit 0. </details> <details><summary>Reverse check: pin turns red without the fix</summary> With the badge's label put back to the English template on disk, the pin reads `Tests 3 failed | 1 passed (4)`: the zh-CN, en-singular and de-singular cases fail, and the en-plural case passes as the control (the old template happens to be right there). Restored from HEAD afterwards; the tree is clean. </details> ## Acceptance notes - The whole `packages/plugin-detail/` suite was not run locally: it ran past the foreground limit on the shared box and was stopped. `Test UI` runs it on this PR. - `plugin-detail` has no package `typecheck` script; `Type Check UI` covers it in CI. ## Verification <details><summary>Derived gate subset: 39 derived, 36 run, 3 not measured</summary> `node scripts/pm/dispatch-gates.mjs --commands` (tree objectstack-ai/objectstack at 646a0f3, 4 paths): 39 commands. 36 exited 0, including `pnpm --dir ui exec vitest run scripts/` (`Test Files 172 passed | 2 skipped (174)`). NOT MEASURED: `check-comment-mask-corpus`, `check:query-options-erasure` and `check:type-check-debt`, reason: my per-command timeout wrapper fired (exit 124) on the shared box before a verdict; CI runs them. `--ran` reconciliation: `39 derived famil(ies) accounted for — 36 run, 3 NOT-MEASURED`, exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_016WV4d1cnRvyiAqrarmDhZV)_ <!-- signed: repo:objectstack@os-elon-musk · os-elon-musk · session_016WV4d1cnRvyiAqrarmDhZV --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent bf95e78 commit 22d5eee

4 files changed

Lines changed: 95 additions & 2 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): a related list's count badge announces its count in the console language
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
The count badge in a related list's header showed a number and announced it to screen readers in English ("3 records") whatever the console language. It now reads the translated pair the related list already uses elsewhere: a zh-CN console announces 「3 条记录」, and an English console says "1 record" at one record rather than "1 records". What the badge draws is unchanged.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* A related list's header count badge speaks the session locale.
11+
*
12+
* The badge draws a bare number, so its `aria-label` is what a screen reader
13+
* announces for it. It reads `detail.relatedRecordOne` at one record and
14+
* `detail.relatedRecords` otherwise — the same pair the tab list's summary
15+
* row lead reads — so a zh-CN console announces 「3 条记录」 and an English
16+
* one never says "1 records".
17+
*/
18+
import { describe, it, expect, vi, beforeAll, afterEach } from 'vitest';
19+
import { cleanup, render, waitFor } from '@testing-library/react';
20+
import '@testing-library/jest-dom';
21+
import React from 'react';
22+
import { I18nProvider } from '@object-ui/i18n';
23+
import { RelatedList } from './RelatedList';
24+
25+
beforeAll(() => {
26+
Object.defineProperty(window, 'innerWidth', { configurable: true, value: 1280 });
27+
});
28+
29+
afterEach(() => cleanup());
30+
31+
const rows = (n: number) => Array.from({ length: n }, (_, i) => ({ id: `c${i + 1}`, name: `Contact ${i + 1}` }));
32+
33+
function renderListIn(language: string, n: number) {
34+
const find = vi.fn(async () => ({ data: rows(n), total: n }));
35+
render(
36+
<I18nProvider config={{ defaultLanguage: language, detectBrowserLanguage: false }}>
37+
<RelatedList
38+
title="Contacts"
39+
type="table"
40+
api="contact"
41+
objectName="contact"
42+
referenceField="account"
43+
parentId="ACC-1"
44+
columns={[{ accessorKey: 'name', header: 'Name' }]}
45+
dataSource={{ find } as any}
46+
/>
47+
</I18nProvider>,
48+
);
49+
}
50+
51+
/** The accessible name of the list header's count badge, once it draws `n`. */
52+
async function headBadgeName(n: number): Promise<string | null> {
53+
let name: string | null = null;
54+
await waitFor(() => {
55+
const badges = Array.from(document.querySelectorAll('[data-related-list-head] [aria-label]'))
56+
.filter((el) => el.textContent === String(n));
57+
expect(badges).toHaveLength(1);
58+
name = badges[0].getAttribute('aria-label');
59+
});
60+
return name;
61+
}
62+
63+
describe('related list count badge — accessible name is translated', () => {
64+
it('announces the zh bundle value under a zh-CN session', async () => {
65+
renderListIn('zh-CN', 3);
66+
expect(await headBadgeName(3)).toBe('3 条记录');
67+
});
68+
69+
it('announces the singular under an en session at one record', async () => {
70+
renderListIn('en', 1);
71+
expect(await headBadgeName(1)).toBe('1 record');
72+
});
73+
74+
it('announces the plural under an en session', async () => {
75+
renderListIn('en', 3);
76+
expect(await headBadgeName(3)).toBe('3 records');
77+
});
78+
79+
it('announces the singular under a de session at one record', async () => {
80+
renderListIn('de', 1);
81+
expect(await headBadgeName(1)).toBe('1 Datensatz');
82+
});
83+
});

‎ui/packages/plugin-detail/src/RelatedList.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4758,7 +4758,7 @@ export const RelatedList: React.FC<RelatedListProps> = ({
47584758
'text-xs font-normal h-5 px-1.5',
47594759
recordCount === 0 && 'bg-muted text-muted-foreground'
47604760
)}
4761-
aria-label={`${recordCount} records`}
4761+
aria-label={tabRecordCountLead(recordCount)}
47624762
>
47634763
{recordCount}
47644764
</Badge>

‎ui/packages/plugin-detail/src/__tests__/RelatedList.countPending-36235.test.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function flush() {
5656

5757
/** The list header's count badge (the only `N records` label in the head). */
5858
const headBadge = () =>
59-
document.querySelector('[data-related-list-head] [aria-label$=" records"]')?.textContent ?? null;
59+
document.querySelector('[data-related-list-head] [aria-label$=" records"], [data-related-list-head] [aria-label$=" record"]')?.textContent ?? null;
6060
const cardCount = () => document.querySelector('[data-related-card-count]')?.textContent ?? null;
6161

6262
function renderList(find: ReturnType<typeof vi.fn>) {

0 commit comments

Comments
 (0)