Repository navigation
perf(i18n): let a component carry only its own English strings #7357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
5e4c993
perf(i18n): let a component carry only its own English strings
vjeux dcb9666
chore(i18n): declare the raw-context path's retirement
vjeux 3a4142e
feat(cli): migrate a raw InternationalizationContext value to the pro…
vjeux 0ac8edf
docs(i18n): scope the breaking entry to the hooks this revision moves…
vjeux 7df8e75
fix(cli): the context codemod edits only what it can prove and rewrit…
vjeux e3f5f14
fix(cli): the context codemod resolves block scopes
vjeux 58003b9
fix(cli): the context codemod imports the provider under a free name …
vjeux 17e3421
fix(cli): the context codemod checks the provider name it writes; tri…
vjeux db49087
fix(cli): type the codemod's provider name as a string
vjeux 80d6ebf
fix(cli): the context codemod maps only a variable's required fields;…
vjeux d99cf19
docs(cli): say what the context codemod maps for a variable
vjeux d359e1b
test(cli): the context codemod leaves the consumer shape in the wild …
vjeux 011b8ae
fix(cli): the context codemod's TODO names the local that shadows the…
vjeux 33cfa85
fix(cli): the context codemod leaves an empty literal behind the TODO…
vjeux ed99b8d
fix(cli): the context codemod sees private-method parameters, static …
vjeux fab7ed1
fix(cli): the context codemod sees an exported namespace member as a …
vjeux 627acf0
fix(cli): the context codemod sees import-equals and ambient declarat…
vjeux c44090d
fix(cli): the context codemod counts a nested namespace as a binding
vjeux 25a4e58
fix(cli): the context codemod sees a dotted namespace as binding its …
vjeux 88c4340
docs: importing InternationalizationContext also carries the whole ca…
vjeux b0588ff
fix(cli): the context codemod declines a spread that follows value
vjeux df7c3f5
chore(cli): the context codemod moves to its own stacked pull request
vjeux 8da012c
docs(i18n): the breaking entry carries the migration as the changelog…
vjeux 0de5c8e
fix(build): the Vite locale alias takes one path segment, so a slice …
vjeux f9267e0
test(i18n): resolve the locale exports through the package's self-ref…
vjeux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [docs] The i18n, RTL and testing guide keeps to what holds for a caller: `useTranslator()` resolves every `@astryx.*` key; how a core component reads its strings moves to the contributing guide. | ||
|
|
||
| @vjeux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': minor | ||
| --- | ||
|
|
||
| [breaking] An app that sets `InternationalizationContext` directly — rendering `<InternationalizationContext value={…}>` (or its `.Provider`) instead of `InternationalizationProvider` — no longer drives `useLocale`, `useDirection` and `useCollator`, nor the components that read the locale or direction through them (the date, date-time, date-range and number inputs, Calendar, Chat, PowerSearch, Table sorting and filtering, Timestamp). Its strings still follow such a value through `useTranslator()`, as does the locale of `DateTimeInput`'s touch field, until the components move to their own slices, which stops that too. Migration: mount `InternationalizationProvider`; its `locale`, `messages` and `overrides` take the value's fields of the same name, and its `dir` takes the value's `direction`. The provider has no `translate` input: an app that supplied its own `translate` expresses those strings as `messages` (a catalog per locale) or `overrides` (sparse, per locale) and the provider resolves them in the documented order. Run `astryx upgrade`: its `migrate-internationalization-context` transform rewrites a variable value to the provider's `locale`, `dir` and `messages` with a TODO for its `overrides` and `translate`, and an inline object literal key by key with a TODO for `translate`; any other value, and any element that spreads props, is left as written behind a TODO saying why. The provider now writes an internal runtime context that those hooks read. Reading the public context is unchanged, so a component that reads it with `useContext` and re-mounts `InternationalizationProvider` with a derived value keeps working: `locale`, `direction`, `messages`, `overrides` and `translate`, which still resolves every `@astryx.*` key against the whole shipped English catalog, with or without a provider; `useTranslator()` is unchanged. Groundwork for components carrying only their own English strings: the English catalog is also emitted one namespace at a time, the resolver takes its English fallback per call, and an internal `useComponentTranslator(slice)` lets a core component render with its own slice. The slices are not importable. | ||
|
|
||
| @vjeux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/build': patch | ||
| --- | ||
|
|
||
| [fix] `astryxStylex()`'s alias for `@astryxdesign/core/locales/<locale>.generated.js` takes one path segment, so the per-namespace English slices under `locales/en/` — which the package's exports map keeps out of reach — no longer resolve through the source tree in a Vite app either. | ||
|
|
||
| @vjeux |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| 'use client'; | ||
|
|
||
| /** | ||
| * @file TranslationRuntimeContext.ts | ||
| * @input React createContext; getResolve | ||
| * @output Exports TranslationRuntimeContext — the locale, direction, catalogs | ||
| * and the message resolver that the components inside this package read — | ||
| * and its value type | ||
| * @position Internal to the i18n runtime. The public InternationalizationContext | ||
| * is this value plus a `translate` bound to the whole English catalog; the | ||
| * provider writes both. This module imports no catalog, so a component that | ||
| * reads it (useComponentTranslator, useLocale, useDirection, useCollator) | ||
| * bundles none; the whole catalog rides only with the public context, the | ||
| * provider and useTranslator. | ||
| * | ||
| * SYNC: When modified, update these files to stay in sync: | ||
| * - /packages/core/src/i18n/InternationalizationContext.ts | ||
| * - /packages/core/src/i18n/InternationalizationProvider.tsx | ||
| * - /packages/core/src/i18n/useComponentTranslator.ts | ||
| */ | ||
|
|
||
| import {createContext} from 'react'; | ||
| import {getResolve} from './resolve'; | ||
| import type {Locale, MessagesByLocale, Overrides} from './types'; | ||
|
|
||
| /** Resolves a key against the provider's catalogs, then the caller's English. */ | ||
| export type MessageResolver = ReturnType<typeof getResolve>; | ||
|
|
||
| export interface TranslationRuntimeContextValue { | ||
| locale: Locale; | ||
| direction: 'ltr' | 'rtl'; | ||
| messages: MessagesByLocale; | ||
| overrides?: Overrides; | ||
| resolve: MessageResolver; | ||
| } | ||
|
|
||
| export const TranslationRuntimeContext = | ||
| createContext<TranslationRuntimeContextValue>({ | ||
| locale: 'en', | ||
| direction: 'ltr', | ||
| messages: {}, | ||
| resolve: getResolve('en', {}), | ||
| }); | ||
| TranslationRuntimeContext.displayName = 'TranslationRuntimeContext'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
nullkeeps Node (and any resolver that honours the exports map) away from the slices, butastryxStylex()from@astryxdesign/build/vitealiases/^@astryxdesign\/core\/locales\/(.+)\.generated\.js$/straight tosrc/i18n/generated-locales/$1.generated.ts(packages/build/src/vite.tsline 228), so@astryxdesign/core/locales/en/button.generated.jsstill resolves to the slice in a Vite app. Suggest narrowing that capture to([^/]+)and adding avite.test.tscase for a slice specifier.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — a Vite app reaching the slices would have undone the
nullexport quietly. Fixed in ef84cea:astryxStylex()'s whole-catalog alias now captures one path segment (locales/([^/]+).generated.js), solocales/en/button.generated.jsno longer routes tosrc/i18n/generated-locales/; a newvite.test.tscase asserts the slice specifier resolves to nothing undergenerated-locales(it fails with the old(.+)). A[fix]changeset names@astryxdesign/build. The two test reds on 383b13c were a 30 s timeout in the PowerShell package-manager shim test, unrelated to this PR's files.