Skip to content
Closed
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5e4c993
perf(i18n): let a component carry only its own English strings
vjeux Oct 11, 2026
dcb9666
chore(i18n): declare the raw-context path's retirement
vjeux Oct 12, 2026
3a4142e
feat(cli): migrate a raw InternationalizationContext value to the pro…
vjeux Oct 12, 2026
0ac8edf
docs(i18n): scope the breaking entry to the hooks this revision moves…
vjeux Oct 12, 2026
7df8e75
fix(cli): the context codemod edits only what it can prove and rewrit…
vjeux Oct 12, 2026
e3f5f14
fix(cli): the context codemod resolves block scopes
vjeux Oct 12, 2026
58003b9
fix(cli): the context codemod imports the provider under a free name …
vjeux Oct 12, 2026
17e3421
fix(cli): the context codemod checks the provider name it writes; tri…
vjeux Oct 12, 2026
db49087
fix(cli): type the codemod's provider name as a string
vjeux Oct 12, 2026
80d6ebf
fix(cli): the context codemod maps only a variable's required fields;…
vjeux Oct 12, 2026
d99cf19
docs(cli): say what the context codemod maps for a variable
vjeux Oct 12, 2026
d359e1b
test(cli): the context codemod leaves the consumer shape in the wild …
vjeux Oct 12, 2026
011b8ae
fix(cli): the context codemod's TODO names the local that shadows the…
vjeux Oct 12, 2026
33cfa85
fix(cli): the context codemod leaves an empty literal behind the TODO…
vjeux Oct 12, 2026
ed99b8d
fix(cli): the context codemod sees private-method parameters, static …
vjeux Oct 12, 2026
fab7ed1
fix(cli): the context codemod sees an exported namespace member as a …
vjeux Oct 12, 2026
627acf0
fix(cli): the context codemod sees import-equals and ambient declarat…
vjeux Oct 12, 2026
c44090d
fix(cli): the context codemod counts a nested namespace as a binding
vjeux Oct 12, 2026
25a4e58
fix(cli): the context codemod sees a dotted namespace as binding its …
vjeux Oct 12, 2026
88c4340
docs: importing InternationalizationContext also carries the whole ca…
vjeux Oct 12, 2026
b0588ff
fix(cli): the context codemod declines a spread that follows value
vjeux Oct 22, 2026
df7c3f5
chore(cli): the context codemod moves to its own stacked pull request
vjeux Oct 23, 2026
8da012c
docs(i18n): the breaking entry carries the migration as the changelog…
vjeux Oct 23, 2026
0de5c8e
fix(build): the Vite locale alias takes one path segment, so a slice …
vjeux Oct 23, 2026
f9267e0
test(i18n): resolve the locale exports through the package's self-ref…
vjeux Oct 25, 2026
8500a50
feat(cli): migrate a raw InternationalizationContext value to the pro…
vjeux Oct 23, 2026
7833176
refactor(core): components render with useComponentTranslator and the…
vjeux Oct 10, 2026
d09aa31
perf(i18n): the whole English catalog is the spread of its slices; co…
vjeux Oct 11, 2026
3be050f
fix(cli): an ejected component reads its strings through the public u…
vjeux Oct 12, 2026
6aafdbc
fix(i18n): a caller-supplied i18nKey keeps the whole catalog as its f…
vjeux Oct 22, 2026
d576f18
docs(i18n): the [perf] entry states the measured sizes
vjeux Oct 25, 2026
df5d915
Merge main into perf/i18n-context-codemod
vjeux Oct 27, 2026
c904b68
Merge #7969 into perf/i18n-slices-sweep
vjeux Oct 27, 2026
12980ed
fix(i18n): Popover renders with its own English slice
vjeux Oct 27, 2026
fa9550d
test(cli): the search golden counts main's new match beside this sweep's
vjeux Oct 27, 2026
fa9e9e5
Merge main into perf/i18n-slices-sweep
vjeux Oct 27, 2026
f4f1f69
fix(i18n): Tokenizer's bottom sheet renders with its own English slice
vjeux Oct 27, 2026
37c215b
Merge main into #7358
vjeux Oct 28, 2026
9d495a7
fix(i18n): Kbd renders with its own English slice
vjeux Oct 28, 2026
f96ddb4
chore(i18n): the slices changeset names no slice count
vjeux Oct 28, 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
7 changes: 7 additions & 0 deletions .changeset/i18n-cli-guide-caller-facing.md
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
8 changes: 8 additions & 0 deletions .changeset/i18n-components-own-slices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
'@astryxdesign/core': patch
'@astryxdesign/cli': patch
---

[perf] A component carries only its own English strings. Every core component now renders with its own namespace slice of the English catalog instead of the whole catalog, so an app that renders components without mounting `InternationalizationProvider`, calling `useTranslator()` or importing `InternationalizationContext` (each of which carries the whole catalog), and that does not render `PowerSearch` (whose caller-supplied operator keys keep the whole catalog as their fallback), bundles only the strings of the components it renders: a page importing `Button`, `Dialog`, `DateInput` or `List` loads 6.2 to 6.8 KB (gzip) less JavaScript. An app that does mount the provider still carries the whole catalog, now assembled from the same slices so no string ships twice; such a page loads 1.2 to 1.9 KB (gzip) more, because the catalog spread over 83 slice modules compresses worse than one module (about 0.9 KB more when the provider is imported before the components). `useTranslator()` is unchanged. `astryx swizzle` points an ejected component's strings at the public `useTranslator()`: the internal translator import, the slice imports and a module-level merge of slices are rewritten, so the copy compiles in the app.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

en.json has 84 namespaces at this head and generate-i18n-runtime.mjs emits 84 English slices, so “spread over 83 slice modules” is stale. Dropping the count, as was done for the key count, keeps the entry from going stale again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f96ddb4: the entry says "its slice modules", with no count.


@vjeux
7 changes: 7 additions & 0 deletions .changeset/i18n-context-codemod.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@astryxdesign/cli': patch
---

[feat] `astryx upgrade` runs `migrate-internationalization-context`, which rewrites `<InternationalizationContext value={…}>` (or its `.Provider`) to `<InternationalizationProvider locale dir messages overrides>`: a variable maps `locale`, `direction` (as `dir`) and `messages` — the fields every context value has — and its TODO names `overrides` and `translate`, which the variable's type may lack and the provider has no input for; an inline object literal maps key by key, `overrides` included, with a TODO for `translate` (a literal's `translate` key is kept beside it). Any other value — a call, a spread into a literal, a conditional — is left unchanged behind a TODO saying why. It rewrites JSX whose name resolves, unshadowed, to an Astryx import (named, aliased, or namespace), reuses the file's own provider import name, and leaves a reader of the context alone.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astryx upgrade would not run this transform at this revision: packages/cli/assets/codemods/transforms/next/index.mjs still exports [], and release promotion copies that manifest into the version folder the upgrade registry loads. The original codemod commit added the manifest entry; the split into this stacked pull request dropped it. Importing the transform and its meta there, and exporting {name: 'migrate-internationalization-context', transform, meta}, with a test that the manifest lists it, makes this sentence true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registered in #7969's bb41827 (this branch is rebased on it): the manifest exports the transform, with a test that it is listed.


@vjeux
7 changes: 7 additions & 0 deletions .changeset/i18n-en-namespace-slices.md
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 configures Astryx: it drives neither `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), nor any core component's strings — every component now renders with its own English slice through an internal translator, and `DateTimeInput`'s touch field reads `useLocale()`. One deliberate exception: a `PowerSearch` operator `i18nKey` from outside PowerSearch's own namespace (a key of another Astryx component, or of the app's catalog) still resolves through the public context's `translate`, since a caller may supply any key there; the shipped default operators are PowerSearch's own and read the slice like the rest of the component. 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. The English catalog is also emitted one namespace at a time, the resolver takes its English fallback per call, and an internal `useComponentTranslator(slice)` is what a core component renders with. The slices are not importable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check:changesets refuses this entry while main declares 0.7.5 (AST-017 FR31). It can merge once an engineering owner accepts the raw-context retirement and the release owner declares 0.8.0 on main (FR48).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, there is nothing to change in the entry itself. It stays refused until an engineering owner rules on the raw-context retirement and the release owner declares 0.8.0 on main. The description's Authority section names both decisions. Checked at 144793f.


@vjeux
7 changes: 7 additions & 0 deletions .changeset/vite-locale-alias-one-segment.md
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
38 changes: 27 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,40 @@ export * from './MyComponent';

### User-facing strings and text direction

Components read user-facing strings with `useTranslator()` rather than
hardcoding them:
Components read user-facing strings with `useComponentTranslator(<slice>)`
rather than hardcoding them. The slice is the component's own namespace of the
English catalog, generated under `src/i18n/generated-locales/en/`, so an app
that neither mounts `InternationalizationProvider`, calls `useTranslator()` nor
imports `InternationalizationContext` (each carries the whole catalog), and does
not render `PowerSearch` (its caller-supplied operator keys keep the whole
catalog as their fallback, through the internal `useCatalogTranslator`), bundles
only the strings of the components it renders:

```tsx
import {useTranslator} from '@astryxdesign/core/i18n';
import {useComponentTranslator} from '../i18n/useComponentTranslator';
import saveButtonMessages from '../i18n/generated-locales/en/saveButton.generated';

function SaveButton() {
const t = useTranslator();
return <button>{t('@astryx.actions.save')}</button>;
const t = useComponentTranslator(saveButtonMessages);
return <button>{t('@astryx.saveButton.save')}</button>;
}
```

Astryx's own strings live in `packages/core/locales/en.json`. The
`@astryx/no-hardcoded-i18n-string` ESLint rule rejects a hardcoded one. For a
prop whose default is a translated string, alias the prop and resolve it in the
body: destructure `label: labelFromProps`, then
A file that reads several namespaces merges their slices once at module level
(`const messages = {...aMessages, ...bMessages}`) and passes that. Astryx's own
strings live in `packages/core/locales/en.json`, keyed
`@astryx.<namespace>.<name>`; `pnpm generate:i18n-runtime` emits the slices, and
`pnpm check:i18n-catalog` fails a key read outside the file's slice, and any
import of `useTranslator` or `InternationalizationContext` inside core. The
`@astryx/no-hardcoded-i18n-string` ESLint rule rejects a hardcoded string. For
a prop whose default is a translated string, alias the prop and resolve it in
the body: destructure `label: labelFromProps`, then
`const label = labelFromProps ?? t('@astryx.<component>.<key>')`.

`useTranslator()` from `@astryxdesign/core/i18n` is the consumer-facing hook:
it carries the whole English catalog, so code inside `packages/core` does not
use it; packages that depend on core (`lab`, `richtext`) do.

A component that responds to text direction resolves it from the DOM, not from
a render-time JavaScript read. Reach for the lightest tool that works, in this
order:
Expand Down Expand Up @@ -347,8 +363,8 @@ order:
flip for free; don't pass them a direction flag.
4. **`useDirection()` context, as a last resort.** Use it only when you need
the direction value during render and nothing above fits. It is SSR-safe
and returns `'ltr'` outside a provider (like `useTranslator`'s silent
fallback), but it is the one path that can mismatch on hydration when the
and returns `'ltr'` outside a provider (like a translator's silent
English fallback), but it is the one path that can mismatch on hydration when the
provider's direction disagrees with `<html dir>`. No Astryx component reads
direction from context at render time.

Expand Down
6 changes: 3 additions & 3 deletions internal/eslint-plugin-astryx/no-hardcoded-i18n-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,21 @@ const rule = {
type: 'problem',
docs: {
description:
'Disallow hardcoded user-facing strings; route through useTranslator() instead',
'Disallow hardcoded user-facing strings; route through a translator (useComponentTranslator(<slice>) in core, useTranslator() elsewhere) instead',
category: 'Best Practices',
recommended: true,
},
messages: {
hardcodedString:
'Hardcoded user-facing string {{value}} in `{{name}}`. ' +
'Route through `t(\'<namespace>.<component>.<key>\')` via `useTranslator()` so it can be localized.',
'Route through `t(\'<namespace>.<component>.<key>\')` via `useComponentTranslator(<slice>)` (in core; `useTranslator()` elsewhere) so it can be localized.',
hardcodedDefault:
'Hardcoded default {{value}} for prop `{{name}}`. ' +
'Use the alias-and-resolve pattern: `{{name}}: {{name}}FromProps` in the destructure, then ' +
'`const {{name}} = {{name}}FromProps ?? t(\'<namespace>.<component>.<key>\');` inside the body.',
hardcodedCallArg:
'Hardcoded user-facing string {{value}} passed to `{{name}}()`. ' +
'Route through `t(\'<namespace>.<component>.<key>\')` via `useTranslator()` so it can be localized.',
'Route through `t(\'<namespace>.<component>.<key>\')` via `useComponentTranslator(<slice>)` (in core; `useTranslator()` elsewhere) so it can be localized.',
},
schema: [
{
Expand Down
21 changes: 21 additions & 0 deletions packages/build/src/vite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,27 @@ describe('astryxStylex locale aliases', () => {
path.join(corePackage, 'src/Button'),
);
});

it('does not route a per-namespace English slice to its source file', () => {
// `locales/en/<namespace>.generated.js` is the package's own: the exports
// map gives it a `null` target, and the alias for whole catalogs takes a
// single path segment, so the slice specifier never reaches
// `src/i18n/generated-locales/en/`.
const rootDir = path.join(tmpdir(), 'astryx-vite-alias');
const aliases = getInjectedConfig(rootDir).resolve.alias;
const corePackage = path.join(rootDir, 'node_modules/@astryxdesign/core');
const resolved = applyAlias(
aliases,
'@astryxdesign/core/locales/en/button.generated.js',
);
expect(resolved).not.toContain('generated-locales');
expect(resolved).not.toBe(
path.join(
corePackage,
'src/i18n/generated-locales/en/button.generated.ts',
),
);
});
});

describe('astryxStylex optimizeDeps package discovery', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/build/src/vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,12 @@ export function astryxStylex(
resolve: {
alias: [
{
find: /^@astryxdesign\/core\/locales\/(.+)\.generated\.js$/,
// A whole catalog, `locales/<locale>.generated.js`. The capture
// takes one path segment only: the per-namespace English slices
// under `locales/en/<namespace>.generated.js` are the package's
// own (the exports map gives them a `null` target), and this
// alias must not reach them either.
find: /^@astryxdesign\/core\/locales\/([^/]+)\.generated\.js$/,
replacement: path.join(
coreSourceDir,
'i18n/generated-locales/$1.generated.ts',
Expand Down
92 changes: 89 additions & 3 deletions packages/cli/api/swizzle/copy/copy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import {resolveComponentReplacement, resolveCore} from '../_adapter.mjs';
import {assertWithin, sanitizeName, PathSafetyError} from '../../../foundation/fs/path-safety.mjs';
import {
assertWithin,
sanitizeName,
PathSafetyError,
} from '../../../foundation/fs/path-safety.mjs';
import {checkGhCli} from '../_github.mjs';
import {Project} from '../../../foundation/config/project.mjs';
import {
Expand All @@ -32,6 +36,81 @@ import {AstryxError, writeFailed} from '../../error.mjs';
/** Default issue tracker for maintainer feedback after swizzling. */
const DEFAULT_ISSUES_URL = 'https://github.com/facebook/astryx/issues/new';

/**
* A core component reads its strings with the internal
* `useComponentTranslator(<its English slice>)`; neither the hook nor the
* slices are public (the slices are `null` in the exports map). An ejected
* copy lives in the app, whose public translator is `useTranslator()` — it
* resolves every `@astryx.*` key against the whole English catalog — so the
* copy reads through that instead: the hook import becomes the public one,
* the slice imports and a module-level merge of slices go, and each call
* becomes `useTranslator()`. A type-only `TranslatorFn` import rides along.
* The internal `useCatalogTranslator` (caller-supplied keys) is the public
* `useTranslator` under another name, so its import becomes an alias of it.
*
* @param {string} content
* @param {string} ownerPackage
*/
export function rewriteComponentTranslator(content, ownerPackage) {
if (
!content.includes('useComponentTranslator') &&
!content.includes('useCatalogTranslator')
) {
return content;
}
const i18n = `${ownerPackage}/i18n`;
return (
content
// import {useCatalogTranslator} from '../i18n/useCatalogTranslator';
// The internal whole-catalog translator for caller-supplied keys is the
// public `useTranslator` under another name; the alias keeps both call
// sites (`t` and `tCaller`) as written.
.replace(
/import\s*\{([^}]*)\}\s*from\s+['"](?:\.\.\/)+i18n\/useCatalogTranslator['"];?/g,
(_m, names) => {
const kept = names
.split(',')
.map((/** @type {string} */ n) => n.trim())
.filter(Boolean)
.map((/** @type {string} */ n) =>
n === 'useCatalogTranslator'
? 'useTranslator as useCatalogTranslator'
: n,
);
return `import {${kept.join(', ')}} from '${i18n}';`;
},
)
// import {useComponentTranslator[, type TranslatorFn]} from '../i18n/useComponentTranslator';
.replace(
/import\s*\{([^}]*)\}\s*from\s+['"](?:\.\.\/)+i18n\/useComponentTranslator['"];?/g,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles useComponentTranslator, but PowerSearch's four files also import useCatalogTranslator from ../i18n/useCatalogTranslator. The generic rewrite below turns that into import {useCatalogTranslator} from '@astryxdesign/core/i18n', which packages/core/src/i18n/index.ts does not export, so astryx swizzle PowerSearch produces a copy that does not compile. useCatalogTranslator() and useTranslator() both return use(InternationalizationContext).translate, so rewriting it to the public useTranslator here, plus a barrel-membership test over PowerSearch like the Button one, keeps the ejected copy on public imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed at this head (8a08a54): the copy step rewrites useCatalogTranslator to the public useTranslator under the same local name (useTranslator as useCatalogTranslator), so an ejected PowerSearch compiles. A swizzle test covers it.

(_m, names) => {
const kept = names
.split(',')
.map((/** @type {string} */ n) => n.trim())
.filter(Boolean)
.map((/** @type {string} */ n) =>
n === 'useComponentTranslator' ? 'useTranslator' : n,
);
return `import {${kept.join(', ')}} from '${i18n}';`;
},
)
// import xMessages from '../i18n/generated-locales/en/x.generated';
.replace(
/^import\s+\w+\s+from\s+['"](?:\.\.\/)+i18n\/generated-locales\/[^'"]+['"];?\r?\n/gm,
'',
)
// const messages = {...aMessages, ...bMessages};
.replace(
/^const\s+\w+\s*=\s*\{(?:\s*\.\.\.\w+Messages\s*,?)+\s*\};?\r?\n/gm,
'',
)
// useComponentTranslator(xMessages) -> useTranslator()
.replace(/\buseComponentTranslator\(\s*[\w.]+\s*\)/g, 'useTranslator()')
// The file header's `@input … i18n (useComponentTranslator)` note.
.replace(/\buseComponentTranslator\b/g, 'useTranslator')
);
}

/**
* Rewrite relative imports that point outside the component directory to use
* the OWNER package's subpaths. Imports within the copied directory (./x) are
Expand All @@ -58,6 +137,7 @@ const DEFAULT_ISSUES_URL = 'https://github.com/facebook/astryx/issues/new';
* @param {string} [ownerPackage]
*/
export function rewriteImports(content, ownerPackage = CORE_PACKAGE) {
content = rewriteComponentTranslator(content, ownerPackage);
/** @param {string} importPath */
const mapTarget = importPath => {
// Strip ALL leading `../` so a two-levels-up path never yields `<pkg>/..`.
Expand Down Expand Up @@ -270,14 +350,20 @@ export async function swizzleCopy(component, options = {}) {
if (!owner) {
throw new AstryxError(
`Component "${dirName}" is not provided by package "${pkg}".`,
allOwners.map(o => ({name: o.package, reason: 'provides this component'})),
allOwners.map(o => ({
name: o.package,
reason: 'provides this component',
})),
ERROR_CODES.ERR_UNKNOWN_COMPONENT,
);
}
} else if (allOwners.length > 1) {
throw new AstryxError(
`Component "${dirName}" is provided by multiple packages. Re-run with --package <pkg> to choose one.`,
allOwners.map(o => ({name: o.package, reason: 'provides this component'})),
allOwners.map(o => ({
name: o.package,
reason: 'provides this component',
})),
ERROR_CODES.ERR_AMBIGUOUS_COMPONENT,
);
} else {
Expand Down
Loading
Loading