Skip to content

Commit f198d32

Browse files
committed
fix(app-shell): pick a stored locale on the platform's one locale ladder
pickRenderableLocale now calls resolveLocaleAmong from @objectstack/spec/system, the ladder the server's resolveLocale runs, instead of keeping a copy of it with its own table step. The table's read aliases already name the script-subtag spellings, so a zh-Hant-TW row still renders Traditional; a variant the table reads as the language itself (es-ES) is now taken ahead of the first offered variant, as the server takes it. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L9qibyWSiXh6B2sMVHfXYC
1 parent db9b349 commit f198d32

2 files changed

Lines changed: 29 additions & 38 deletions

File tree

‎ui/packages/app-shell/src/hooks/__tests__/userLocale-10059.test.tsx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,11 @@ describe('pickRenderableLocale', () => {
248248
});
249249

250250
/**
251-
* The console resolves a stored tag in the server's `resolveLocale` order
252-
* (exact → case → base language → variant), so a legacy mis-cased row and a
253-
* tag the deployment offers only as a variant no longer render English.
251+
* The console resolves a stored tag on the platform's one locale ladder,
252+
* `resolveLocaleAmong` (exact → case → platform table language → base
253+
* language → variant), the server's `resolveLocale` order, so a legacy
254+
* mis-cased row and a tag the deployment offers only as a variant no longer
255+
* render English.
254256
*/
255257
/**
256258
* objectstack#30511: before the base-language step, the platform locale
@@ -315,7 +317,13 @@ describe('pickRenderableLocale follows the server resolveLocale order', () => {
315317
});
316318

317319
it('takes the first offered variant when several share a base', () => {
318-
expect(pickRenderableLocale('es', ['en', 'es-MX', 'es-ES'])).toBe('es-MX');
320+
expect(pickRenderableLocale('es', ['en', 'es-MX', 'es-AR'])).toBe('es-MX');
321+
});
322+
323+
it('takes the variant the platform locale table reads as the language before the first variant', () => {
324+
// `es-ES` is a read alias of the table's `es`, so the table step answers
325+
// it ahead of the variant step, as the server's ladder does.
326+
expect(pickRenderableLocale('es', ['en', 'es-MX', 'es-ES'])).toBe('es-ES');
319327
});
320328

321329
it('still matches nothing for a language nobody offers', () => {

‎ui/packages/app-shell/src/hooks/useUserLocale.ts‎

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ import {
8383
LOCALE_STORAGE_KEY,
8484
readStoredLanguage,
8585
resolveBootstrapLanguage,
86-
resolveBuiltInLanguage,
8786
useObjectTranslation,
8887
} from '@object-ui/i18n';
88+
import { resolveLocaleAmong } from '@objectstack/spec/system';
8989
import { useAdapter, useDataInvalidation, extractWriteErrorMessage } from '@object-ui/react';
9090
import { ObjectStackAdapter } from '@object-ui/data-objectstack';
9191
import { useAfterFirstPaint } from './sharedUserFeeds.js';
@@ -373,24 +373,26 @@ const LOCALE_FIELD = 'locale';
373373
* locales ∩ what this renderer can resolve) — the same list the globe menu and
374374
* the profile card render, deliberately not a second opinion about what ships.
375375
*
376-
* The match order is the server's `resolveLocale` (`packages/core`
377-
* `fallbacks/memory-i18n.ts`), the one the platform's i18n routes already
378-
* resolve a requested locale with, so the console and the server agree on
379-
* which language a stored tag means:
376+
* The match order IS the platform's one locale ladder, `resolveLocaleAmong`
377+
* (`@objectstack/spec/system`), which the server's `resolveLocale` and every
378+
* i18n route run too, so the console and the server agree on which language a
379+
* stored tag means:
380380
*
381381
* 1. exact tag (`pt-BR` → `pt-BR`; a real `pt-BR` still beats `pt`);
382382
* 2. the same tag in any case (`zh-cn` → `zh-CN`) — a row written before the
383383
* server door folded case is served as stored, never migrated;
384-
* 3. the first offered code the platform locale table reads as the same
385-
* language (`zh-TW` → `zh-Hant`, `zh-HK` → `zh-TW`, `zh` → `zh-CN`,
386-
* `pt` → `pt-BR`; objectstack#30511). The table's read aliases are how a
387-
* row stored before the table keeps its meaning, and the one step the
388-
* server's order lacks: without it a base-language match hands a
389-
* Traditional row (`zh-TW`) the first `zh` variant offered, which is the
390-
* Simplified pack;
384+
* 3. the same platform locale table language, through the table's read
385+
* aliases (`zh-TW` → `zh-Hant`, `zh-HK` → `zh-TW`, `zh` → `zh-CN`,
386+
* `pt` → `pt-BR`): a row stored before the table keeps its meaning, and a
387+
* Traditional row is never handed the first Simplified variant offered;
391388
* 4. the base language (`zh-CN` → `zh`, `en-GB` → `en`), case-insensitively;
392-
* 5. the first offered variant of that base language (`es` → `es-MX`,
393-
* `zh-Hans-CN` → `zh-CN`), in the order the list offers them.
389+
* 5. the first offered variant of that base language (`es` → `es-MX`), in
390+
* the order the list offers them — after step 3, so a variant the table
391+
* reads as the language itself (`es-ES`) is taken first.
392+
*
393+
* The table's read aliases name the script-subtag spellings too
394+
* (`zh-Hant-TW`, `zh-Hans-CN`), so step 3 reads them by script; a code the
395+
* table does not name is not guessed at, here as on the server.
394396
*
395397
* A match answers the OFFERED spelling, never the stored one: the list is what
396398
* the provider can switch to.
@@ -404,26 +406,7 @@ export function pickRenderableLocale(
404406
offerable: readonly string[] | null,
405407
): string | null {
406408
if (!offerable || offerable.length === 0) return null;
407-
// 1. Exact.
408-
if (offerable.includes(tag)) return tag;
409-
// 2. Case-insensitive.
410-
const lower = tag.toLowerCase();
411-
const caseMatch = offerable.find((code) => code.toLowerCase() === lower);
412-
if (caseMatch) return caseMatch;
413-
// 3. The same language, as the platform locale table reads both tags.
414-
const pack = resolveBuiltInLanguage(tag);
415-
if (pack !== null) {
416-
const sameLanguage = offerable.find((code) => resolveBuiltInLanguage(code) === pack);
417-
if (sameLanguage) return sameLanguage;
418-
}
419-
// 4. Base language.
420-
const base = lower.split('-')[0];
421-
if (!base) return null;
422-
const baseMatch = offerable.find((code) => code.toLowerCase() === base);
423-
if (baseMatch) return baseMatch;
424-
// 5. Variant of the base language — first offered wins.
425-
const variantMatch = offerable.find((code) => code.split('-')[0].toLowerCase() === base);
426-
return variantMatch ?? null;
409+
return resolveLocaleAmong(tag, offerable) ?? null;
427410
}
428411

429412
/**

0 commit comments

Comments
 (0)