Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
01cd805
fix(i18n): a dependent package's fieldPatches text reads that package…
claude Nov 17, 2026
48a1438
docs(i18n): changeset and object-extensions note for translating fiel…
claude Nov 17, 2026
b558663
test(objectql): read the installed record's translations through an u…
claude Nov 17, 2026
7d860eb
test(objectql): the field-patch-bases engine double routes findOne th…
claude Nov 17, 2026
4a5cb99
test(metadata-protocol): pay the lint load at collection in the packa…
claude Nov 17, 2026
26d09ed
Merge branch 'main' of https://github.com/objectstack-ai/objectstack …
claude Nov 17, 2026
f5e963d
fix(metadata-protocol): the save door's inverse translates with the r…
claude Nov 17, 2026
6064e53
test(metadata-protocol): pin the inverse's patch-bundle sources
claude Nov 17, 2026
3d4d348
docs(i18n): declare the pair's locale-by-locale rank, the door's inve…
claude Nov 17, 2026
74ab926
Merge branch 'main' of https://github.com/objectstack-ai/objectstack …
claude Nov 17, 2026
70347ee
refactor(metadata-protocol): the two new reads' contracts live on the…
claude Nov 17, 2026
91ce466
fix(metadata-protocol): a patch entry answers only a slot its patch c…
claude Nov 17, 2026
ba1892c
test(metadata-protocol): pin the per-slot patch cut against a stored …
claude Nov 17, 2026
8510e0e
Merge remote-tracking branch 'origin/main' into claude/project-thread…
claude Nov 17, 2026
70e332e
fix(metadata-protocol): decide a patch entry's stored-slot guard by t…
claude Nov 17, 2026
6c57786
Merge origin/main into claude/project-thread-jkfy43 (K=15 before land…
claude Nov 17, 2026
c9c9a9a
style(metadata-protocol): keep protocol.ts at its facade line ceiling
claude Nov 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .changeset/33952-patch-bundles-translation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
'@objectstack/spec': minor
'@objectstack/objectql': minor
'@objectstack/metadata-protocol': minor
'@objectstack/rest': minor
---

feat(i18n): a dependent package's `fieldPatches` text is translated from that package's own translations

Clause-②: yes (widening) — `TranslateDocumentOptions` gains an exported member, `patchBundles`; nothing accepted before is refused
Metadata-protocol: semantic — a dependent package's translations of its own `fieldPatches` text now take effect on `/meta` and on the public form; on a patched slot the pair `.custom` translation is laid over the package's locale by locale, so a pair that translates the slot only in a fallback locale (`en`) no longer wins over the package's translation in the requested one (`zh-CN`)
Skills-docs: follow-up #34785

A code package that relabels a vendor's field with `fieldPatches` (ADR-0146 D10) can now translate the text it writes. Before this change, a patched label, help text, description or option label was served exactly as the patch wrote it in every locale: a patched slot read only the pair `.custom` package's catalog, and the deployment catalog merges every package's translations with the package ids dropped, so the patching package's own `zh-CN` rows for the slot never applied.

A patched slot now reads, in order:

1. the pair `.custom` package's translation of that key, as before, laid over the package's translations locale by locale along the fallback chain;
2. the translations of the code package whose patch wrote the served value: its shipped `translations` and its own active translation rows;
3. the served text.

The slots read this way are the field `label`, the help text (`inlineHelpText`, or `description` when the field has none), an option `label` on a field not bound to a shared picklist, and, through the same rule, `inlineTitle` and `relatedListTitle`. The owner's translation of the text the patch replaced never applies to a patched slot, as before. A slot the patch did not write (a tenant's rename on top of it) keeps its own text. When two packages patch the same slot, the slot reads the package whose text it serves. Nothing is stamped on the served document: which package wrote a slot is found by comparing the served value with the packaged base plus that one package's patches (ADR-0029 D9.2a).

New reads beside the option: `SchemaRegistry.getPackagedFieldPatchBases(name)` and `ObjectStackProtocolImplementation.getPackagedFieldPatchBases(name)` (one entry per patching code package, highest precedence first) and `ObjectStackProtocolImplementation.getPackageTranslationBundle(packageId)` (one package's own translations, locale-keyed). The `/meta` object item and list reads and `GET /forms/:slug` pass `patchBundles` to the translator. The public form reads no pair translation, before this change as after it, so there a patched slot reads the package's translation, then the text.

The save door's inverse of the read (the translated-echo restore that keeps a Studio save in another locale from storing the read's translation) translates with the same patch translations. A zh-CN read of a patched label, saved back whole, stores the patch text and not the patching package's translation, both over a stored row that carries the patch text and with no stored row; an `en` read after it serves the patch text.
8 changes: 8 additions & 0 deletions content/docs/data-modeling/object-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ reason.
- **Every read serves it.** The patch is applied in the same merge as the other keys,
after the additive ones, and the list, the by-name read and the layered view agree.
Uninstalling the extension serves the owner's text again.
- **Translate it in your own package.** A patched label, help text, description or
option label is translated from the `translations` of the package that ships the
patch, and from its translation rows, under the same keys as the owner's text:
`objects.crm_account.fields.industry.label`, `….help` for the help text (the
description when the field has none), `….options.customer` for an option. The owner's
translation of the text the patch replaced never applies to it. On the `/meta` reads
a pair `.custom` translation of that key still comes first, and a locale your package does not
translate serves the patch's text as written.
- **It reaches the owner's own fields only.** A field another extension adds — or one
your own extension adds in `fields` — is not a patch target, whatever the
priorities: set that field's text where it is declared. The install door and
Expand Down
110 changes: 108 additions & 2 deletions packages/metadata-protocol/src/protocol-discovery-and-bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import type { SysMetadataRepository } from './sys-metadata-repository.js';
import { PLURAL_TO_SINGULAR, SINGULAR_TO_PLURAL, unrecognisedMetaTypeRefusal } from '@objectstack/spec/shared';
import type { TranslationBundle } from '@objectstack/spec/system';
import { engineCanRollBack, isPackageScopedType, readAuthoredTranslationLayer } from '@objectstack/core';
import { deepMerge, engineCanRollBack, isPackageScopedType, readAuthoredTranslationLayer } from '@objectstack/core';
import { restoreTranslatedEchoes } from './protocol-translated-echo.js';
import type { RestoredTranslatedSlot } from './protocol-translated-echo.js';
import {
Expand Down Expand Up @@ -957,6 +957,101 @@ export class ProtocolDiscoveryAndBasesFacet {
return Object.keys(layer).length > 0 ? (layer as TranslationBundle) : undefined;
}

/**
* The body of `ObjectStackProtocolImplementation#getPackagedFieldPatchBases`.
*
* [#33952, ADR-0146 D10] For each CODE package that patches the fields of
* object `name` (`objectExtensions[].fieldPatches`), the packaged base
* (`getPackagedObjectBase`) with THAT package's patches applied and
* no other's, beside its package id; highest precedence first. The
* registry's `getPackagedFieldPatchBases`, whose docblock carries the
* rule. The serving layer pairs each entry with
* {@link getPackageTranslationBundle} for the translators' `patchBundles`
* (`@objectstack/spec/system`): a slot a code package's patch wrote reads
* that package's own translations, below the pair's (ruling 6942920667).
*
* `[]` — "no patching package known", which the translators read as
* before the option existed — for an object no code package owns, an
* unknown name, a registry without the read (a partial double) and a read
* that throws.
*/
static getPackagedFieldPatchBases(host: Pick<ProtocolHost, 'engine'>, name: string): Array<{ packageId: string; base: unknown }> {
if (typeof name !== 'string' || name === '') return [];
const registry = (host.engine as any)?.registry;
if (typeof registry?.getPackagedFieldPatchBases !== 'function') return [];
try {
const entries: unknown = registry.getPackagedFieldPatchBases(name);
return Array.isArray(entries) ? entries : [];
} catch {
// A read over in-memory contributors; a failure here must never
// turn a served schema into a 5xx. No entry is "no patching
// package known": a patched slot keeps its own text, as before.
return [];
}
}

/**
* The body of `ObjectStackProtocolImplementation#getPackageTranslationBundle`.
*
* [#33952] The translations package `packageId` ships itself,
* locale-keyed (`{ [locale]: data }`), for the translators' `patchBundles`
* (`@objectstack/spec/system`), paired with {@link getPackagedFieldPatchBases}.
*
* Needed for {@link getPairTranslationBundle}'s reason: the catalog the
* deployment serves deep-merges every package's translations with the
* package ids dropped, so a dependent package's translation of its own
* patch and the owner's translation of the text it replaced are one key,
* and which one the catalog holds is load order. This reads that one
* package's share: the `translations` its installed package record
* carries, then its own active `translation` rows over them.
*
* `undefined` when the package carries neither, and for an empty id.
*
* Two halves, laid on locale by locale in the order the i18n service lays
* the deployment catalog (`FileI18nAdapter.getTranslations`: the shipped
* bundles, then the authored layer over them), so the bundle is that
* package's share of the catalog with its package kept: the `translations`
* its installed package record carries (`registry.getPackage(id).manifest`,
* what `registerApp` installs, the body `AppPlugin.loadTranslations` hands
* the i18n service), then the environment's active `translation` rows
* bound to it, read as {@link getPairTranslationBundle} reads the pair's.
*/
static async getPackageTranslationBundle(host: Pick<ProtocolHost, 'engine' | 'findEnvironmentRows'>, packageId: string): Promise<TranslationBundle | undefined> {
if (typeof packageId !== 'string' || packageId === '') return undefined;
let byLocale: Record<string, Record<string, unknown>> = {};
const lay = (locale: string, data: unknown): void => {
if (!data || typeof data !== 'object' || Array.isArray(data)) return;
byLocale = { ...byLocale, [locale]: deepMerge(byLocale[locale] ?? {}, data as Record<string, unknown>) };
};
let shipped: unknown;
try {
shipped = (host.engine as any)?.registry?.getPackage?.(packageId)?.manifest?.translations;
} catch {
// An in-memory read; a failure leaves the shipped half empty.
shipped = undefined;
}
if (Array.isArray(shipped)) {
for (const bundle of shipped) {
if (!bundle || typeof bundle !== 'object' || Array.isArray(bundle)) continue;
for (const [locale, data] of Object.entries(bundle as Record<string, unknown>)) lay(locale, data);
}
}
let authored: Record<string, Record<string, unknown>> | null = null;
try {
authored = await readAuthoredTranslationLayer({
find: (table: string, opts: { where?: Record<string, unknown>; [key: string]: unknown } = {}) =>
host.findEnvironmentRows(table, { ...opts, where: { ...opts.where, package_id: packageId } }),
});
} catch {
// `null` is the layer's own "read failed": the shipped half stands.
authored = null;
}
if (authored !== null) {
for (const [locale, data] of Object.entries(authored)) lay(locale, data);
}
return Object.keys(byLocale).length > 0 ? (byLocale as TranslationBundle) : undefined;
}

/**
* The one body behind {@link getPackagedDashboardBase},
* {@link getPackagedViewBase}, {@link getPackagedReportBase} and
Expand Down Expand Up @@ -1036,7 +1131,7 @@ export class ProtocolDiscoveryAndBasesFacet {
* the packaged base is a registry lookup, so a degraded MetadataService
* fails nothing here.
*/
static async restoreTranslatedObjectEchoes(host: Pick<ProtocolHost, 'getPackagedObjectBase' | 'registeredTranslationBundle'>, request: SaveMetaItemRequest,
static async restoreTranslatedObjectEchoes(host: Pick<ProtocolHost, 'getPackageTranslationBundle' | 'getPackagedFieldPatchBases' | 'getPackagedObjectBase' | 'registeredTranslationBundle'>, request: SaveMetaItemRequest,
repo: SysMetadataRepository,
ref: Parameters<SysMetadataRepository['get']>[0],
mode: 'draft' | 'publish',): Promise<{ item: SaveMetaItemRequest['item']; restored: RestoredTranslatedSlot[] }> {
Expand All @@ -1061,10 +1156,21 @@ export class ProtocolDiscoveryAndBasesFacet {
packageId: request.packageId ?? null,
},
);
// [#33952] The read's `patchBundles` too: a slot a code package's
// `fieldPatches` wrote is served in that package's own translation, so
// the inverse translates with the same entries, read the way the REST
// exits read them (`patchTranslationBundlesOf`): one per patching
// package that carries a translation, highest precedence first.
const patchBundles: Array<{ patchedBase: unknown; bundle: TranslationBundle }> = [];
for (const entry of host.getPackagedFieldPatchBases(request.name)) {
const own = await host.getPackageTranslationBundle(entry.packageId);
if (own !== undefined) patchBundles.push({ patchedBase: entry.base, bundle: own });
}
return restoreTranslatedEchoes(request.item, {
source,
bundle: host.registeredTranslationBundle(),
packagedBase: packagedBase ?? undefined,
...(patchBundles.length > 0 ? { patchBundles } : {}),
});
}

Expand Down
2 changes: 2 additions & 0 deletions packages/metadata-protocol/src/protocol-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export interface ProtocolHost {
readonly getMetaItem: ObjectStackProtocolImplementation['getMetaItem'];
readonly getMetaItems: ObjectStackProtocolImplementation['getMetaItems'];
readonly getOverlayRepo: ObjectStackProtocolImplementation['getOverlayRepo'];
readonly getPackageTranslationBundle: ObjectStackProtocolImplementation['getPackageTranslationBundle'];
readonly getPackagedFieldPatchBases: ObjectStackProtocolImplementation['getPackagedFieldPatchBases'];
readonly getPackagedObjectBase: ObjectStackProtocolImplementation['getPackagedObjectBase'];
readonly getServicesRegistry: ObjectStackProtocolImplementation['getServicesRegistry'];
readonly governServedObject: ObjectStackProtocolImplementation['governServedObject'];
Expand Down
87 changes: 87 additions & 0 deletions packages/metadata-protocol/src/protocol-translated-echo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,90 @@ describe('[#29673] restoreTranslatedEchoes', () => {
expect(restored.map((r) => r.path)).toEqual(['fields.renewed_from.relatedListTitle']);
});
});

describe('[#33952] restoreTranslatedEchoes with the read\'s patchBundles', () => {
const catalog = { 'zh-CN': { objects: { crm_account: { fields: { name: { label: '名称' }, registration_number: { label: '注册号' } } } } } } as unknown as TranslationBundle;
const packagedBase = {
name: 'crm_account',
fields: { name: { type: 'text', label: 'Name' }, registration_number: { type: 'text', label: 'Registration No.' } },
};
const patchedBase = { ...packagedBase, fields: { ...packagedBase.fields, registration_number: { type: 'text', label: 'Tax ID' } } };
const patchBundles = [{
patchedBase,
bundle: { 'zh-CN': { objects: { crm_account: { fields: { registration_number: { label: '税号' } } } } } } as unknown as TranslationBundle,
}];
const body = (name: string, reg: string) => ({ name: 'crm_account', fields: { name: { type: 'text', label: name }, registration_number: { type: 'text', label: reg } } });

it('the patching package\'s translation of a patched slot is put back to the patch text, with or without a stored row carrying it', () => {
for (const source of [body('Name', 'Tax ID'), packagedBase]) {
const { item, restored } = restoreTranslatedEchoes(body('名称', '税号'), { source, bundle: catalog, packagedBase, patchBundles }) as any;
expect([item.fields.name.label, item.fields.registration_number.label]).toEqual(['Name', 'Tax ID']);
expect(restored.map((r: any) => r.path)).toContain('fields.registration_number.label');
}
});

it('a field the patch left as packaged is no patch source: a tenant\'s rename typed as the catalog string is kept', () => {
// The stored row renamed `name` to `Customer`; the read serves that untranslated, so `名称` is the author's.
const { item } = restoreTranslatedEchoes(body('名称', 'Tax ID'), { source: body('Customer', 'Tax ID'), bundle: catalog, packagedBase, patchBundles }) as any;
expect(item.fields.name.label).toBe('名称');
});

it('without patchBundles the patched slot\'s translation is no echo (the read before #33952 never served it)', () => {
const { item } = restoreTranslatedEchoes(body('Name', '税号'), { source: body('Name', 'Tax ID'), bundle: catalog, packagedBase }) as any;
expect(item.fields.registration_number.label).toBe('税号');
});
});

describe('[#34836] a patch entry answers a slot its patch changed, and only where the stored row has no text of its own there', () => {
const catalog = {
'zh-CN': { objects: { crm_account: { fields: { name: { label: '名称' }, registration_number: { label: '注册号', help: '注册号说明' } } } } },
} as unknown as TranslationBundle;
const regField = { type: 'text', label: 'Registration No.', description: 'Registration number' };
const packagedBase = { name: 'crm_account', fields: { name: { type: 'text', label: 'Name' }, registration_number: regField } };
// The patch changes the label only; the description stays the packaged text.
const patchedBase = { ...packagedBase, fields: { ...packagedBase.fields, registration_number: { ...regField, label: 'Tax ID' } } };
const patchBundles = [{
patchedBase,
bundle: { 'zh-CN': { objects: { crm_account: { fields: { registration_number: { label: '税号' } } } } } } as unknown as TranslationBundle,
}];
const row = (reg: Record<string, unknown>) => ({ name: 'crm_account', fields: { name: { type: 'text', label: 'Name' }, registration_number: { type: 'text', ...reg } } });
const read = (doc: unknown, locale: string) =>
structuredClone(translateObject(doc as any, catalog, { locale, packagedBase, patchBundles } as any)) as any;

it('a stored `税号` typed over the patched slot survives a whole-body save in another locale with an unrelated edit', () => {
const source = row({ label: '税号', description: 'Registration number' });
const echo = read(source, 'en');
// The precondition: the read serves the tenant's text as written.
expect(echo.fields.registration_number.label).toBe('税号');
echo.fields.name.label = 'Account Name';
const { item, restored } = restoreTranslatedEchoes(echo, { source, bundle: catalog, packagedBase, patchBundles }) as any;
expect(item.fields.registration_number.label).toBe('税号');
expect(item.fields.name.label).toBe('Account Name');
expect(restored).toEqual([]);
});

it('the catalog\'s translation of a packaged slot the patch left alone, typed over a tenant\'s rename, is the author\'s', () => {
const source = row({ label: 'Tax ID', description: 'Our own note' });
const echo = read(source, 'zh-CN');
expect(echo.fields.registration_number.description).toBe('Our own note');
echo.fields.registration_number.description = '注册号说明';
const { item } = restoreTranslatedEchoes(echo, { source, bundle: catalog, packagedBase, patchBundles }) as any;
expect(item.fields.registration_number.description).toBe('注册号说明');
});

it('a stored empty string on the patched slot is no text of its own: the patch text the fold serves over it is put back', () => {
// The fold applies the patch over `''` (scalarOverridesPackagedBase is false for it), so the read serves `Tax ID`.
const source = row({ label: '', description: 'Registration number' });
const echo = read(row({ label: 'Tax ID', description: 'Registration number' }), 'zh-CN');
expect(echo.fields.registration_number.label).toBe('税号');
const { item } = restoreTranslatedEchoes(echo, { source, bundle: catalog, packagedBase, patchBundles }) as any;
expect(item.fields.registration_number.label).toBe('Tax ID');
});

it('a slot the patch left alone is no patch source even where the stored row does not declare the field', () => {
const source = { name: 'crm_account', fields: { name: { type: 'text', label: 'Name' } } };
const { item, restored } = restoreTranslatedEchoes(row({ label: 'Tax ID', description: '注册号说明' }), { source, bundle: catalog, packagedBase, patchBundles }) as any;
expect(item.fields.registration_number.description).toBe('注册号说明');
expect(restored).toEqual([]);
});
});
Loading
Loading