Repository navigation
refactor(i18n): pre-build lookup map for translations - #4696
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for looking at this — walking the chain per key is genuinely repetitive and worth attacking.
The blocker is the lookup order. The file documents overrides (exact locale, then parent) as beating every shipped catalog entry; the new map fills per tag, overrides then messages, so a shipped pt-BR string now wins over a pt override. An app that overrides a string for Portuguese loses it silently the first time the shipped pt-BR catalog gains that key — nothing throws, the wording just reverts.
getResolve('pt-BR', {'pt-BR': {k: {defaultMessage: 'shipped'}}}, {pt: {k: 'override'}})('k')
// main: 'override' this branch: 'shipped'Two passes over the chain — every override first, then every catalog — restores it.
Separate and not blocking: the module-level getResolve('en', {}) builds all 305 en keys at import time, for every consumer of core whether they render a translated string or not.
If you'd rather talk it through with someone, we're in Discord.
[Reviewed by Robohands]
|
Checking in on locale lookup ordering: parent-locale overrides still need to beat exact shipped catalog strings. Would you like to continue, have us carry it, or close this for now? |
Yes. I will make a quick fix and continue. Thank you for the feedback. |
7d46b99 to
03f6e4a
Compare
Memoize the translation lookup map and expose it via context instead of resolving keys on each call. This removes per-call chain resolution and the `useCallback` wrapper, improving performance for frequent translations.
Thanks for the detailed review. Both issues are addressed. Issue 1 — Override precedence (order bug)
getResolve('pt-BR', {'pt-BR': {k: {defaultMessage: 'shipped'}}}, {pt: {k: 'override'}})('k')
// 'override' ✓
Issue 2 — eager en catalog build at import time
const result = lookup[key] ?? EN_CATALOG[key]?.defaultMessage;Thanks again for the thorough review — happy to discuss further if anything else comes up. |
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual RegressionStatus: Skipped — Broad stable scope is deferred to the daily release gate. It covers 1964 trusted baseline shots instead of recapturing them for this PR. View the report Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
* Improve DropdownMenu responsive fit and presentation guidance * fix DropdownMenu scroll region keyboard access * docs clarify compact submenu presentations * fix DropdownMenu anchor alignment and submenu examples * fix DropdownMenu submenu spacing * docs minimize DropdownMenu guidance diff * fix(DropdownMenu): preserve intrinsic width values * feat: add adaptive menu presentations * chore: version packages for v0.5.1 (#5661) * refactor(i18n): pre-build lookup map for translations (#4696) * fix(popover): improve responsive fit and focus * Preserve Popover compatibility when constraining overflow * Add real-viewport Popover overflow stories * Refine Popover overflow story * Restore Popover story dismissal behavior * docs clarify Popover presentation guidance * docs render Popover evidence in real viewports * fix(Popover): address accessibility review * fix DropdownMenu controlled close navigation * fix(Popover): observe overflow only while open * fix(Popover): align mobile presentation behavior * docs(Popover): tighten bottom sheet spacing * fix(menu): align mobile bottom sheets * fix(Popover): hide container focus outline * fix(ContextMenu): prevent touch selection * docs(ContextMenu): add bottom sheet example * fix(MoreMenu): preserve touch feedback * docs(MoreMenu): add bottom sheet example * fix(ContextMenu): reliably suppress touch selection * fix(ContextMenu): improve mobile doc examples * fix(MoreMenu): reduce bottom sheet padding * refactor(menu): share adaptive sheet infrastructure * fix(menu): preserve focus without touch rings * fix(BottomSheet): keep browser edge surface-colored * fix(ContextMenu): drill into sheet submenus * Add adaptive Selector and MultiSelector presentations (#5685) * feat: add adaptive selector presentations * fix: refine selector bottom sheet interactions * refactor(selector): use shared adaptive policy * fix(selector): preserve focus without touch rings * fix selectors bottom sheet focus target --------- Co-authored-by: Cindy Zhang <[email protected]> Co-authored-by: Li Hongzhang <[email protected]>
Resolved conflicts (upstream meta#4696 replaced resolve() with a getResolve(locale, messages, overrides) closure stored on the context as `translate`): - packages/core/src/i18n/resolve.ts: took upstream's getResolve/getLookup shape and moved the translator delegation into the returned closure; getResolve gains an optional fourth `translator` argument. - packages/core/src/i18n/InternationalizationProvider.tsx: build `translate: getResolve(locale, messages ?? {}, overrides, translator)` and keep `translator` in the context value and the useMemo deps. - packages/core/src/i18n/InternationalizationContext.ts: keep both the PR's `translator?` field and upstream's `translate` field. - packages/core/src/i18n/useTranslator.ts: took upstream's `return ctx.translate` (the PR's useCallback change no longer applies). Merge fallout: translator.test.tsx called the removed `resolve` export, so it now goes through a local getResolve shim like resolve.test.ts's, and the dep-array comments point at the provider memo instead of useCallback.
Memoize the translation lookup map and expose it via context instead of resolving keys on each call. This removes per-call chain resolution and the
useCallbackwrapper, improving performance for frequent translations.