Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions .changeset/36809-console-flow-labels-fallback-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@objectstack/spec': minor
'@objectstack/runtime': minor
'@object-ui/i18n': minor
'@object-ui/app-shell': minor
'@object-ui/plugin-detail': minor
'@object-ui/console': minor
---

feat(i18n): console flow labels follow the server's declared fallback chain

Clause-②: yes (widening)
Metadata-protocol: added
Skills-docs: none — the new member is a response field the console reads, not something a metadata author writes; no skills/ page teaches `GET /i18n/locales` or how the console resolves flow labels

- **`GET /api/v1/i18n/locales` names the declared fallback chain.** `GetLocalesResponseSchema` (`@objectstack/spec/api`) gains an optional `fallbackChain: string[]`, and the runtime's `/i18n` domain fills it from the i18n service's `getFallbackLocale()` (the stack's `i18n.fallbackLocale`, else its `defaultLocale`), the same accessor the server's metadata translations hand the spec resolvers as `ResolveOptions.fallbackChain`. A service that declares no fallback (no accessor, or an empty answer, such as the core in-memory provider) serves no member. Nothing existing changes meaning.
- **The console loads the fallback locale's flow translations.** The console's language loader reads the chain and `sourceLocale` beside the active language's bundle and, unless the language is the authored one, fetches each fallback locale's bundle and keeps its `flows` group (`withDeclaredFlowsFallback`, `@object-ui/i18n`).
- **Flow labels walk the same locales as the server.** `activeFlowsBundle` returns the fallback locales' rows too, and the new `flowsResolveOptions` hands the spec resolvers `{ locale, fallbackChain, defaultLocale }`. The flow runner (flow name, field copy, option labels), the flow designer and docs viewer (`flowLabelTranslations`, `useFlowLabelTranslations`, which take the declared options) and the stage-change confirm now read a declared fallback locale's text for a label the active language lacks, before the authored label. A stack that declares no fallback keeps "requested locale, then the authored label".
1 change: 1 addition & 0 deletions content/docs/references/api/protocol.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ This schema accepts one of the following structures:
| :--- | :--- | :--- | :--- |
| **locales** | `{ code: string; label: string; isDefault?: boolean }[]` | ✅ | Available locales |
| **sourceLocale** | `string` | optional | The language the app's own text (a plain-string `label`) is written in: the declared `i18n.sourceLocale`, else the default locale. Absent when the server knows neither. Text typed in any other locale is a translation |
| **fallbackChain** | `string[]` | optional | The locales the server consults, in order, after the requested one and before the authored text: the deployment's declared fallback (`i18n.fallbackLocale`, else `defaultLocale`). Absent when the i18n service reports none; the requested locale alone is then consulted. A request tag is negotiated against `locales[].code` first, and the chain is not walked for a request that negotiates to `sourceLocale` |

### Nested Shape: `GetLocalesResponse.locales[number]`

Expand Down
14 changes: 12 additions & 2 deletions content/docs/ui/translations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ Resolved labels are served straight from the REST metadata endpoints (the
locale is part of the ETag), so the Console and any SDUI client get translated
metadata without doing lookups themselves.

Where the Console resolves a string itself (the `flows` group below), it walks
the same chain. `GET /api/v1/i18n/locales` names the declared chain as
`fallbackChain` (absent when the stack declares none) beside `sourceLocale`,
and the Console loads each fallback locale's `flows` group with the active
locale's bundle. It first matches its own language against the locales that
answer lists, as the server matches a request's locale, so a `zh-Hans` Console
on a stack authored in `zh-CN` reads the authored Chinese and walks no chain. A flow label the active locale lacks then reads the fallback
locale's text before the authored one, as the server's own reads do; with no
declared chain it reads the active locale, then the authored label.

### An edit beats the packaged catalog

A package's bundle translates the strings that package shipped, so it applies
Expand Down Expand Up @@ -497,8 +507,8 @@ Honest limits worth knowing before you plan around them:
console's screen-flow runner;
- the flow's own `label` names the flow in the runner's header, above the
step's heading, and in the completion toast. A locale the bundle does not
cover shows the label authored on the flow, and a backend that serves no
label shows the flow's API name.
cover reads the declared fallback locale's label, then the label authored
on the flow, and a backend that serves no label shows the flow's API name.

A `successMessage` authored on the flow replaces the completion sentence, so
the translated label appears in the toast only when the flow declares none.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.

/**
* objectstack#36809 — `GET /i18n/locales` names the deployment's DECLARED
* fallback chain (`fallbackChain`), produced from the i18n service's
* `getFallbackLocale()`: the accessor the server's own metadata translations
* read to hand the spec resolvers their `fallbackChain`
* (`metaTranslateOptions`, `@objectstack/rest`). The console reads it to walk
* the same locales for the strings it resolves itself (its flow labels).
*
* Pinned: the member is the accessor's answer, wrapped as a one-entry chain;
* a service that declares no fallback (no accessor, or one answering nothing)
* serves no member, never an invented `en` or default; the body still parses
* as `GetLocalesResponseSchema`.
*/

import { describe, it, expect, vi } from 'vitest';
import { createMemoryI18n } from '@objectstack/core';
import { GetLocalesResponseSchema } from '@objectstack/spec/api';

import { handleI18nRequest } from './i18n.js';
import { apiErrorResponse } from '../error-envelope.js';
import type { DomainHandlerDeps } from '../domain-handler-registry.js';
import type { HttpProtocolContext } from '../http-dispatcher.js';

const member = () => ({
request: { headers: {} },
executionContext: { userId: 'usr_member', isSystem: false, positions: [], permissions: [], systemPermissions: [] },
}) as unknown as HttpProtocolContext;

function makeDeps(service: unknown): DomainHandlerDeps {
return {
getService: vi.fn(async () => service),
resolveService: vi.fn(async () => service),
success: (data: any) => ({ status: 200, body: { success: true, data } }),
error: (message: string, httpStatus = 500, details?: any) => apiErrorResponse({ message, httpStatus, details }),
} as unknown as DomainHandlerDeps;
}

async function readLocales(service: unknown) {
const result: any = await handleI18nRequest(makeDeps(service), '/locales', 'GET', {}, member());
expect(result.handled).toBe(true);
expect(result.response.status).toBe(200);
const parsed = GetLocalesResponseSchema.safeParse(result.response.body.data);
expect(parsed.success, JSON.stringify(parsed.error?.issues)).toBe(true);
return result.response.body.data as Record<string, unknown>;
}

function serviceWith(extra: Record<string, unknown>) {
return {
getLocales: vi.fn(() => ['zh-CN', 'en']),
getDefaultLocale: vi.fn(() => 'zh-CN'),
getTranslations: vi.fn(() => ({})),
...extra,
};
}

describe('GET /i18n/locales names the declared fallback chain (objectstack#36809)', () => {
it('is produced from getFallbackLocale(): the declared fallback, as a one-entry chain', async () => {
const getFallbackLocale = vi.fn(() => 'en');
const data = await readLocales(serviceWith({ getFallbackLocale }));
expect(getFallbackLocale).toHaveBeenCalled();
expect(data.fallbackChain).toEqual(['en']);
// Beside the authored language the resolvers take as `defaultLocale`.
expect(data.sourceLocale).toBe('zh-CN');
});

it('follows the accessor, not a constant: another declared fallback is served as declared', async () => {
const data = await readLocales(serviceWith({ getFallbackLocale: () => 'ja-JP' }));
expect(data.fallbackChain).toEqual(['ja-JP']);
});

it.each([
['a service with no getFallbackLocale accessor', {}],
['an accessor answering undefined', { getFallbackLocale: () => undefined }],
['an accessor answering an empty string', { getFallbackLocale: () => '' }],
])('%s serves no fallbackChain member', async (_label, extra) => {
const data = await readLocales(serviceWith(extra));
expect('fallbackChain' in data).toBe(false);
});

it('the core in-memory provider, which declares no accessor, serves none even when told a fallback', async () => {
const i18n = createMemoryI18n();
i18n.setDefaultLocale?.('zh-CN');
i18n.setFallbackLocale?.('en');
const data = await readLocales(i18n);
expect('fallbackChain' in data).toBe(false);
});
});
19 changes: 18 additions & 1 deletion packages/runtime/src/domains/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,24 @@ export async function handleI18nRequest(
// the source text from a translation. Absent when neither is known.
const declaredSource = typeof i18nService.getSourceLocale === 'function' ? i18nService.getSourceLocale() : undefined;
const sourceLocale = declaredSource || defaultLocale || undefined;
return { handled: true, response: deps.success({ locales, ...(sourceLocale ? { sourceLocale } : {}) }) };
// [objectstack#36809] The deployment's DECLARED fallback chain — the
// `getFallbackLocale()` the server's own metadata translations hand
// the spec resolvers as `fallbackChain` (`metaTranslateOptions`,
// `@objectstack/rest`), read by the same feature-detected accessor
// under the same condition (a non-empty string), so a client that
// resolves translated metadata itself walks the locales the server
// walks. Absent when the service declares none: the server threads a
// declaration, it never invents one.
const declaredFallback = typeof i18nService.getFallbackLocale === 'function' ? i18nService.getFallbackLocale() : undefined;
const fallbackChain = typeof declaredFallback === 'string' && declaredFallback.length > 0 ? [declaredFallback] : undefined;
return {
handled: true,
response: deps.success({
locales,
...(sourceLocale ? { sourceLocale } : {}),
...(fallbackChain ? { fallbackChain } : {}),
}),
};
}

// GET /i18n/translations/:locale OR /i18n/translations?locale=xx
Expand Down
1 change: 1 addition & 0 deletions packages/spec/authorable-surface/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@
"api/GetInstalledPackageResponse:error",
"api/GetInstalledPackageResponse:meta",
"api/GetInstalledPackageResponse:success",
"api/GetLocalesResponse:fallbackChain",
"api/GetLocalesResponse:locales",
"api/GetLocalesResponse:sourceLocale",
"api/GetMetaDiagnosticsResponse:entries",
Expand Down
22 changes: 22 additions & 0 deletions packages/spec/src/api/protocol.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4817,6 +4817,22 @@ export const GetLocalesRequestSchema = lazySchema(() => z.object({}));
* menu rename made in any other language as that language's translation.
* Named after its config key, as `defaultLocale`'s `isDefault` mark is the
* config's `defaultLocale`.
*
* `fallbackChain` names the locales the server consults after the requested
* one and before the authored text, the deployment's DECLARED chain: the i18n
* service's `getFallbackLocale()` (the stack's `i18n.fallbackLocale`, else its
* `defaultLocale`, as the boot collapses them), which the server's own
* metadata translations already hand the spec resolvers as
* `ResolveOptions.fallbackChain`. It is absent when the i18n service reports
* no fallback (the file-backed service always reports one, collapsed from
* `fallbackLocale || defaultLocale || 'en'`), and a client then resolves the
* requested locale alone, as the server does. A client that resolves
* translated metadata itself (the console's flow labels) reads it beside
* `sourceLocale` (the resolvers' `defaultLocale`), after negotiating its
* request tag against `locales[].code` as the server negotiates a request's
* tag (`resolveLocaleAmong`), so its answer and the server's walk the same
* locales: a `zh-Hans` request on a deployment holding `zh-CN` is the
* `zh-CN` request, and walks no chain when `zh-CN` is the source locale.
*/
export const GetLocalesResponseSchema = lazySchema(() => z.object({
locales: z.array(z.object({
Expand All @@ -4830,6 +4846,12 @@ export const GetLocalesResponseSchema = lazySchema(() => z.object({
'The language the app\'s own text (a plain-string `label`) is written in: the declared `i18n.sourceLocale`, '
+ 'else the default locale. Absent when the server knows neither. Text typed in any other locale is a translation',
),
fallbackChain: z.array(z.string()).optional().describe(
'The locales the server consults, in order, after the requested one and before the authored text: the deployment\'s '
+ 'declared fallback (`i18n.fallbackLocale`, else `defaultLocale`). Absent when the i18n service reports none; the '
+ 'requested locale alone is then consulted. A request tag is negotiated against `locales[].code` first, and the chain '
+ 'is not walked for a request that negotiates to `sourceLocale`',
),
}));

/**
Expand Down
Loading
Loading