Skip to content

Commit 692e0dc

Browse files
fix(showcase): translate the task detail review banner under zh-CN (#29104)
<!-- claude-projects-attribution: {"github_login":"marchtian"} --> _Requested by **田騏** · [project thread](https://claude.ai/code/project/chan_01VmuUhXU9SSUzqJYyXSmYSi?thread=cmsg_01VmuUhXU9SSUzqJYyXSmYSi9paTx1Lu8ENYwwssthfK3h)_ Fixes #28982 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:showcase 任务详情页顶部的「待评审」黄色提示条在中文会话下改为中文——标题走翻译包,正文用页面上的内联多语言文本。 - 为什么改:中文用户打开评审中的任务,整页都是中文,唯独这条提示是英文,像没翻完;发版清单 i18n.notification-localized-and-clears 的 A1(不得中英混排)因此一直红。 - 风险与回滚:只动示例应用,不发布任何包;提示条的「关闭记忆」改用固定键,之前关掉过它的人会再看到一次;回滚即还原本 PR。 - 先看:`examples/app-showcase/src/ui/pages/task-detail.page.ts`(record:alert 节点的 id、body、dismissKey)→ `examples/app-showcase/src/system/translations/index.ts`(zh-CN 的 pages.showcase_task_detail)→ 新测试文件。 - 两分钟验证:`pnpm --filter @objectstack/example-showcase exec vitest run test/task-detail-review-alert-zh-cn.test.ts`,预期 3 passed;或中文会话打开种子任务「Design system」,提示条显示「待评审」和中文正文。 - 需要你做的:无,席位落地。 ## What changes The Task Detail page (`showcase_task_detail`) shows a `record:alert` banner while a task is in review. On a zh-CN session it rendered in English because the node had no component `id`, and page component copy is translated through `pages.NAME.components.COMPONENT_ID.KEY`. - `task-detail.page.ts`: the banner gets `id: 'review_alert'` (snake_case, like the page ids elsewhere in the showcase: `new_project_form`, `project_picker`). - `translations/index.ts`: the zh-CN bundle gains `pages.showcase_task_detail.components.review_alert.title` = 待评审. The `en` block carries no `pages` entries, and the authored English stays the default text. The showcase ships `en` and `zh-CN` only (`objectstack.config.ts` `supportedLocales`), so no other locale needs the key. - **`body` does not go through the bundle, because the bundle has no key for it.** The page-component copy face is `title / description / label / placeholder / emptyText` (`PAGE_COMPONENT_COPY_KEYS`, `packages/spec/src/system/i18n-resolver.ts`), and the bundle schema is strict there. Measured on the built spec: an entry with only `title` parses, and one with `title` plus `body` is refused with `unrecognized_keys` ("Unrecognized key(s) on this page component translation: `body`"). `RecordAlertProps.body` is declared `I18nLabelSchema`, and the renderer reads it through `pickLocalized`, so the body is now an inline locale map holding both `en` and `zh-CN`. This follows the recorded precedent for `element:text` `content` in `translation.zod.ts`: the inline locale map is the ruled route for page prose, and that shape was not added to the bundle. - `dismissKey: 'showcase_task_review'`: the dismissal key defaults to the English resolution of `title`. Once the bundle translates the title, a zh-CN session would resolve that key to the translation, so a banner dismissed in one locale would come back in the other. The key is now fixed. ## Tests - New pin: `examples/app-showcase/test/task-detail-review-alert-zh-cn.test.ts`. It applies `translateMetadataDocument('page', …)` to the page with the app's own bundle, which is the same thing the REST boundary does for each request locale. It asserts the zh-CN title, that the body's locale map comes back intact, the fixed `dismissKey`, the English title under `en`, and that the zh-CN bundle still parses under `TranslationBundleSchema`. Its model is `zh-cn-report-blocks-inline-titles.test.ts`. - Reverse check, run once: with the two source files restored to base `ab085a0482` and the test kept, the pin goes red (`expected undefined to be 'review_alert'`, 1 failed and 2 passed). Restored from `HEAD`, `git diff HEAD` is empty. ## Acceptance notes - The card listed `title/body` under the bundle key. Only `title` can go there (see above). Adding `body` to the page-component face would widen the spec (`Metadata-protocol: added`), and the `content` precedent declined that for prose of the same shape. This PR stays inside the current contract. - The inline locale map on `body` cannot be seen by `os i18n extract` or `check:i18n-coverage`. That extractor question is a known one and is out of scope here. - Read-only survey of the showcase pages, not fixed here and not measured in a browser: these id-less components carry copy on the bundle face, so they have no zh-CN key. `showcase_my_work`: the `object-metric` label and description ("Open Tasks", "In Review", "At-Risk Projects") and the `page:card` titles "Shortcuts" and "Leadership View". `showcase_component_gallery`: four `object-metric` blocks and an `element:button` "Create Task". `showcase_project_detail`: the `record:line_items` and `record:related_list` titles "Tasks". Several `element:text` `content` strings on those pages are plain English. Their route is the inline map, not the bundle. ## Verification Head `6c6289c0c9` (`origin/main` merged once, at `c708de67b2`). The dependency closure was rebuilt after the merge. <details><summary>Showcase package: typecheck, tests, validate</summary> - `pnpm --filter @objectstack/example-showcase typecheck && … exec vitest run --maxWorkers=2` (run under the verify lock): `VERDICT command-exit 0`, Test Files 43 passed (43), Tests 514 passed (514) - `pnpm --filter @objectstack/example-showcase validate`: exit 0. No finding names `showcase_task_detail` or the banner. </details> <details><summary>Derived gates (dispatch-gates --commands, 40)</summary> - 39 gates exited 0, including `check:i18n-coverage` ("OK (14 config(s), 426 baselined untranslated string(s), none new)"), `check:page-declaration-shape`, `check:nul-bytes` and `check:examples-live-imports`. - `check:dual-build-cjs-loads` exited 3 (PREREQUISITE NOT MET). It needs dist output from packages outside this diff's closure, so it is NOT MEASURED here and is left to CI. - `--ran` reconciliation: "40 derived famil(ies) accounted for — 39 run, 1 NOT-MEASURED (1 DERIVED from a recorded exit 3)". </details> Changeset: none. `@objectstack/example-showcase` is `private: true` and publishes nothing, so the PR carries `skip-changeset`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 93153f0 commit 692e0dc

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

‎examples/app-showcase/src/system/translations/index.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,14 @@ export const ShowcaseTranslationBundle = {
12431243
showcase_active_projects: { label: '进行中的项目' },
12441244
// `ui/pages/invoice-document.page.ts` — the invoice print page.
12451245
showcase_invoice_document: { label: '发票' },
1246+
// `ui/pages/task-detail.page.ts` — the banner a task in review shows.
1247+
// Only its `title` has a key on this face; its `body` carries its
1248+
// zh-CN text inline on the page (see the comment on the node there).
1249+
showcase_task_detail: {
1250+
components: {
1251+
review_alert: { title: '待评审' },
1252+
},
1253+
},
12461254
showcase_contact_form: {
12471255
components: {
12481256
field_name: { label: '姓名', placeholder: '艾达·洛夫莱斯' },

‎examples/app-showcase/src/ui/pages/task-detail.page.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,35 @@ export const TaskDetailPage = definePage({
9191
// hence no `visible` beside it: a node `visibleWhen` and
9292
// `properties.visible` compose as AND, so leaving both would keep the
9393
// legacy predicate load-bearing.
94+
//
95+
// The banner's copy reaches a zh-CN reader by two routes, one per key.
96+
// `title` is translated by the bundle at
97+
// `pages.showcase_task_detail.components.review_alert.title`, which is
98+
// why the node carries an `id`: the page-component route addresses a
99+
// component by its id, so an id-less node has no bundle key at all.
100+
// `body` has no bundle key on that face (`PAGE_COMPONENT_COPY_KEYS` in
101+
// `@objectstack/spec/system` is title / description / label /
102+
// placeholder / emptyText, and the bundle schema refuses any other),
103+
// so it carries its translation at the authoring site, as the inline
104+
// locale map `RecordAlertProps.body` accepts. `dismissKey` keeps the
105+
// dismissal under one name in every locale: its default is the English
106+
// resolution of `title`, and a bundle-translated title would resolve
107+
// to the translation, so a banner dismissed in one locale would come
108+
// back in the other.
94109
{
110+
id: 'review_alert',
95111
type: 'record:alert',
96112
visibleWhen: "has(record.status) && record.status == 'in_review'",
97113
properties: {
98114
severity: 'warning',
99115
icon: 'eye',
100116
title: 'Awaiting review',
101-
body: 'This task is in review — confirm the work before marking it done.',
117+
body: {
118+
en: 'This task is in review — confirm the work before marking it done.',
119+
'zh-CN': '此任务正在评审中——请先确认工作成果,再标记为完成。',
120+
},
102121
dismissible: true,
122+
dismissKey: 'showcase_task_review',
103123
},
104124
},
105125
{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* Under zh-CN, the Task Detail page's "Awaiting review" banner
5+
* (`record:alert`, shown while a task is in review) is served in Chinese
6+
* like the rest of the page.
7+
*
8+
* The banner's two strings travel by two routes. `title` is translated by the
9+
* bundle through the page-component route
10+
* (`pages.showcase_task_detail.components.review_alert.title`), which needs
11+
* the node's `id` — before it had one the route could not address it and the
12+
* title stayed English. `body` has no key on that face, so it is an inline
13+
* locale map on the page; the renderer picks the reader's locale from it
14+
* (`pickLocalized`), so the served document must still carry that map
15+
* intact. The pin is the translator applied to the page with the app's own
16+
* bundle, which is what the REST boundary does per request locale.
17+
*/
18+
import { describe, expect, it } from 'vitest';
19+
import {
20+
translateMetadataDocument,
21+
TranslationBundleSchema,
22+
type TranslationBundle,
23+
} from '@objectstack/spec/system';
24+
import { TaskDetailPage } from '../src/ui/pages/task-detail.page.js';
25+
import { ShowcaseTranslationBundle } from '../src/system/translations/index.js';
26+
27+
const bundle = ShowcaseTranslationBundle as unknown as TranslationBundle;
28+
29+
type Node = { id?: string; type: string; properties?: Record<string, unknown> };
30+
const reviewAlert = (page: { regions?: Array<{ components: Node[] }> }): Node | undefined =>
31+
page.regions?.flatMap((r) => r.components).find((c) => c.type === 'record:alert');
32+
33+
describe('showcase Task Detail — the review banner under zh-CN', () => {
34+
it('serves the banner title from the bundle and keeps the body\'s locale map', () => {
35+
const out = translateMetadataDocument('page', TaskDetailPage, bundle, { locale: 'zh-CN' });
36+
const alert = reviewAlert(out);
37+
expect(alert?.id).toBe('review_alert');
38+
expect(alert?.properties?.title).toBe('待评审');
39+
expect(alert?.properties?.body).toEqual({
40+
en: 'This task is in review — confirm the work before marking it done.',
41+
'zh-CN': '此任务正在评审中——请先确认工作成果,再标记为完成。',
42+
});
43+
// The dismissal key does not move with the translated title.
44+
expect(alert?.properties?.dismissKey).toBe('showcase_task_review');
45+
});
46+
47+
it('leaves the authored English title in place for the default locale', () => {
48+
const out = translateMetadataDocument('page', TaskDetailPage, bundle, { locale: 'en' });
49+
expect(reviewAlert(out)?.properties?.title).toBe('Awaiting review');
50+
});
51+
52+
it('carries the title entry in a bundle the spec accepts', () => {
53+
// The bundle schema is strict on `components.<id>`: a key outside the
54+
// page-component copy face (such as `body`) is refused, so the entry
55+
// this page relies on must parse as written.
56+
const zh = (ShowcaseTranslationBundle as Record<string, unknown>)['zh-CN'];
57+
expect(TranslationBundleSchema.safeParse({ 'zh-CN': zh }).success).toBe(true);
58+
});
59+
});

0 commit comments

Comments
 (0)