Skip to content

Commit 2f4dfc0

Browse files
committed
fix(i18n)!: declare requestedLocale and carry the breaking disposition for the served bundle
The seat's contract review of the served-translations PR amends the claim to `Clause-②: yes (narrowing)`: the published `GetTranslationsResponseSchema` accepted a body carrying `metadataForms` and now refuses it, and the exported type loses that member. The changeset carries the BREAKING banner, the remedy (read the group from `/meta/types`) and one ADR-0087 disposition. `requestedLocale` is declared on the same schema, optional. The runtime door has served it on the locale-fallback exit since that fallback existed, with no declaration behind it; pins in the spec and runtime suites now read it from the schema. Two ui docblocks described the old composition. Both now say what is true: `SPEC_TRANSLATION_GROUPS` is a superset of the groups the server still serves, and the metadata designer's overlay names `/meta/types` as the channel that carries an environment's own `metadataForms`. Claude-Session: https://claude.ai/code/session_01Vy85beHdawtEtqNscYBy7V Co-authored-by: Claude <noreply@anthropic.com>
1 parent 8b2ad27 commit 2f4dfc0

8 files changed

Lines changed: 63 additions & 11 deletions

File tree

‎.changeset/25785-served-translations-without-metadata-forms.md‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
'@objectstack/runtime': patch
44
---
55

6-
fix(i18n): the translation bundle a console downloads leaves out Studio's `metadataForms`
6+
**BREAKING** fix(i18n)!: the translation bundle a console downloads leaves out Studio's `metadataForms`
77

8-
Clause-②: no
8+
Clause-②: yes (narrowing)
99
Metadata-protocol: none
1010

1111
`GET /i18n/translations/:locale` served the i18n service's whole locale tree, so every console open downloaded `metadataForms`, the translations of Studio's metadata-type authoring forms: 75 KB of the 221 KB raw zh-CN bundle on `examples/app-crm`. No browser reads that group from the bundle. Studio's forms already arrive translated, because `GET /meta` (and `/meta/types`) resolves `metadataForms.<type>` on the server, from the same i18n service, before it serves each form.
1212

1313
The route now serves every group except the ones the server resolves itself. The spec names them in `SERVER_RESOLVED_TRANSLATION_GROUPS`, which today holds only `metadataForms`. `GetTranslationsResponseSchema.translations` is now `ServedTranslationDataSchema`: the platform face without those groups, and closed, so a body that still carries one fails it. The runtime copies the tree and never edits the service's own one, which is the tree `/meta` translates from. The `ETag` still hashes the bytes served, so a warm reopen still gets `304`.
1414

15-
What to do: nothing, unless you read `metadataForms` from this route. Authoring is unchanged. `metadataForms` stays a group on every bundle face and in the i18n service. To show a metadata form in the reader's language, read it from `GET /meta/types`, which serves it already translated.
15+
**Why this is breaking.** A response body that carries `metadataForms` was accepted by the published `GetTranslationsResponseSchema` and now fails it, the exported `GetTranslationsResponse` type loses that member, and the route stops serving a group it served. Nothing an author writes moves, which is why the kind is `none` and the level is `patch`.
16+
17+
**What to do.** Nothing, unless you read `metadataForms` from this route. Read it from `GET /meta/types` instead, which serves each form already translated into the requested locale, rather than from the bundle this route returns. Authoring is unchanged: `metadataForms` stays a group on every bundle face (`TranslationData`, `PlatformTranslationData`), in `i18n:extract` and in the i18n service.
18+
19+
Also on this route: `requestedLocale`, which the door has always served when it fell back to another locale (`zh` served as `zh-CN`), is now declared on `GetTranslationsResponseSchema`, optional. It was served undeclared, so no generated client could read it.
20+
21+
<!-- adr-0087: not-required (no-migration-prescription) No metadata moves for an upgrading author: no spec key, authorable spelling, object definition, stored row or stored shape is added, removed, renamed or re-shaped, and `metadataForms` stays declared on both authored bundle faces and in the i18n service, so there is nothing for `objectstack migrate meta` to reach or rewrite. What narrows is one HTTP answer's shape — the console bundle no longer carries a group the server resolves itself — and the affected party is a code consumer reading that answer, whose channel is the compiler and the response schema, not the metadata ledger (ADR-0087 D8). The remedy is a read from another door (`GET /meta/types`, which serves the same forms already translated), never a conversion between two metadata versions. The other categories are closed on facts: both packages publish (not unpublished); no ADR-0087 id is named or touched (not registered or already-registered); the diff touches `packages/spec/**` and a `*.zod.ts` contract face (not type-surface-only); and the narrowed declaration IS a Zod projection, `z.input<typeof GetTranslationsResponseSchema>` (not runtime-interface-only), with no export retired (not runtime-export-retired). -->

‎content/docs/references/api/protocol.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,7 @@ The published metadata item body, opaque by ruling (1C). Shape is the item's own
17641764
| Property | Type | Required | Description |
17651765
| :--- | :--- | :--- | :--- |
17661766
| **locale** | `string` | ✅ | Locale code |
1767+
| **requestedLocale** | `string` | optional | The locale the caller asked for, when the served locale is a fallback from it |
17671768
| **translations** | `{ objects?: Record<string, object>; picklists?: Record<string, object>; apps?: Record<string, object>; messages?: Record<string, string>; … }` | ✅ | Translation data |
17681769

17691770
### Nested Shape: `GetTranslationsResponse.translations`

‎packages/runtime/src/domains/i18n-translations-served-groups.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,14 @@ describe('#25785 A — the served document leaves the server-resolved groups out
113113
expect(result.response.body.data.translations).not.toHaveProperty('metadataForms');
114114
});
115115

116-
it('the locale fallback exit (zh → zh-CN) leaves it out too', async () => {
116+
it('the locale fallback exit (zh → zh-CN) leaves it out too, and its body is declared', async () => {
117117
const result = await read(makeService({ en: {}, 'zh-CN': zhTree() }), '/translations/zh');
118118
expect(result.response.status).toBe(200);
119119
expect(result.response.body.data).toEqual({ locale: 'zh-CN', requestedLocale: 'zh', translations: SERVED_GROUPS });
120+
// `requestedLocale` is declared on the response face (#25785), so the
121+
// fallback body is read by the schema rather than tolerated by it.
122+
expect(GetTranslationsResponseSchema.safeParse(result.response.body.data).success).toBe(true);
123+
expect(Object.keys(GetTranslationsResponseSchema.shape)).toContain('requestedLocale');
120124
});
121125

122126
it('the body satisfies the closed GetTranslationsResponseSchema, which refuses the unserved group', async () => {

‎packages/spec/authorable-surface/api.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@
832832
"api/GetRunResponse:success",
833833
"api/GetTranslationsRequest:locale",
834834
"api/GetTranslationsResponse:locale",
835+
"api/GetTranslationsResponse:requestedLocale",
835836
"api/GetTranslationsResponse:translations",
836837
"api/GetUiViewRequest:object",
837838
"api/GetUiViewRequest:type",

‎packages/spec/src/api/protocol.zod.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3711,9 +3711,19 @@ export const GetTranslationsRequestSchema = lazySchema(() => z.object({
37113711
* translates Studio's authoring forms from it, and is not part of this answer.
37123712
* `translations` is therefore {@link ServedTranslationDataSchema}, the platform
37133713
* face without those groups, closed so a body that still carries one fails it.
3714+
*
3715+
* `requestedLocale` is the code the caller ASKED for, carried only when the
3716+
* door fell back to another one: `locale` is always the locale the body
3717+
* translates, and the pair is how a caller learns that `zh` was served as
3718+
* `zh-CN`. The runtime door has served it since that fallback existed while
3719+
* this face did not declare it (#25785) — declared ≠ enforced, Prime
3720+
* Directive #10: an undeclared field is one no generated client can read and
3721+
* no conformance suite can hold. Optional, because the exit that serves the
3722+
* locale asked for omits it.
37143723
*/
37153724
export const GetTranslationsResponseSchema = lazySchema(() => z.object({
37163725
locale: z.string().describe('Locale code'),
3726+
requestedLocale: z.string().optional().describe('The locale the caller asked for, when the served locale is a fallback from it'),
37173727
translations: ServedTranslationDataSchema.describe('Translation data'),
37183728
}));
37193729

‎packages/spec/src/system/served-translation-data.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ describe('#25785 — the served translation face', () => {
4848
expect(Object.keys(PlatformTranslationDataSchema.shape)).toContain(group);
4949
});
5050

51+
it('declares `requestedLocale`, optional, beside the locale it served', () => {
52+
const shape = GetTranslationsResponseSchema.shape;
53+
expect(Object.keys(shape).sort()).toEqual(['locale', 'requestedLocale', 'translations']);
54+
// The fallback exit's body: `zh` asked for, `zh-CN` served (runtime `domains/i18n.ts`).
55+
const fallback = { locale: 'zh-CN', requestedLocale: 'zh', translations: { messages: { save: '保存' } } };
56+
expect(GetTranslationsResponseSchema.safeParse(fallback).success).toBe(true);
57+
// Optional: the exit that serves the locale asked for omits it.
58+
expect(GetTranslationsResponseSchema.safeParse({ locale: 'zh-CN', translations: {} }).success).toBe(true);
59+
// Declared, so it is typed rather than merely tolerated: a non-string is refused.
60+
expect(GetTranslationsResponseSchema.safeParse({ ...fallback, requestedLocale: 7 }).success).toBe(false);
61+
});
62+
5163
it('accepts a document carrying the served groups', () => {
5264
const served = {
5365
objects: { lead: { label: '潜在客户', fields: { company: { label: '公司' } } } },

‎ui/packages/app-shell/src/views/metadata-admin/metadata-form-i18n.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@
3131
* (a hand-rolled walker would have had to re-derive `header.showTitle` and
3232
* would have got the section names wrong — they are slugged labels, not the
3333
* `label` text);
34-
* - when the environment's own translation bundle reaches this surface, it
35-
* drops in as a higher-precedence source with no call-site change.
34+
* - when the environment's own `metadataForms` translations reach this
35+
* surface, they drop in as a higher-precedence source with no call-site
36+
* change. Their channel is `/api/v1/meta/types`, which serves each form
37+
* already localized from the environment's bundle: the console's own
38+
* translation bundle (`/api/v1/i18n/translations/:locale`) does not carry
39+
* the group at all (objectstack#25785 — it was 75 KB of 221 KB on app-crm
40+
* zh-CN, read by nothing in the browser). So the higher-precedence source
41+
* for a form the SERVER renders is already in place; this overlay is for
42+
* the forms this console renders from its own copy of the spec, which no
43+
* server answer passes through.
3644
*
3745
* ## Scope: `en` + `zh`, matching this console's carve-out
3846
*

‎ui/packages/i18n/src/utils/spec-translations.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,28 @@ export interface SpecTranslationData {
6060
}
6161

6262
/**
63-
* The top-level groups of the translation document the server serves at
64-
* `/api/v1/i18n/translations/:locale` — the keys of the `translations` shape
65-
* of `@objectstack/spec`'s `GetTranslationsResponseSchema`: every per-app
63+
* The top-level groups this transform recognises in the translation document
64+
* the server serves at `/api/v1/i18n/translations/:locale` — every per-app
6665
* `TranslationData` group plus the platform-only `settings`, because the
6766
* served document is the merge of the app's bundle and the platform's.
6867
*
68+
* It is a SUPERSET of the keys of the `translations` shape of
69+
* `@objectstack/spec`'s `GetTranslationsResponseSchema`, deliberately: that
70+
* shape is the groups the server still SERVES, and a group can leave it while
71+
* authored bundles and older servers keep carrying it. `metadataForms` is the
72+
* first one to have left (objectstack#25785 — Studio's authoring forms arrive
73+
* already translated from `/api/v1/meta/types`, so the console bundle stopped
74+
* carrying their translations); it stays listed here, so a payload from a
75+
* server that still serves it is namespaced like any other rather than landing
76+
* untouched at the root. Nothing reads the group on this side.
77+
*
6978
* Written out rather than imported: `@object-ui/i18n` deliberately does not
7079
* depend on `@objectstack/spec`. The console does, so the pin lives beside
7180
* its loader — `apps/console/src/loadLanguage.test.tsx` walks the spec's own
7281
* key list and requires a payload carrying any one group, alone, to take the
73-
* transform branch. A group the spec adds and this list lacks turns that test
74-
* red instead of dropping the group's bundles silently (objectui#10235).
82+
* transform branch. A group the spec SERVES and this list lacks turns that
83+
* test red instead of dropping the group's bundles silently (objectui#10235);
84+
* a group listed here and no longer served is not red, by that direction.
7585
*/
7686
const SPEC_TRANSLATION_GROUPS = [
7787
'objects',

0 commit comments

Comments
 (0)