Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 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
df5d915
Merge main into perf/i18n-context-codemod
vjeux Oct 27, 2026
5b4e841
fix(codemod): a getter or a method in an inline context value stays b…
vjeux Oct 29, 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
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.

This says astryx upgrade runs the transform, but packages/cli/assets/codemods/transforms/next/index.mjs still exports [] and the codemod registry runs only manifest entries, so at this head the transform never runs. Restoring the manifest entry, dropped when the codemod moved out of #7357, 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 bb41827 — the split had dropped the manifest entry, which is exactly the kind of gap that ships silently. transforms/next/index.mjs now exports {name: 'migrate-internationalization-context', transform, meta}, and the fixture file opens with a test that the manifest lists the transform by name with the same transform and meta identities.


@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 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
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
37 changes: 26 additions & 11 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,39 @@ 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) 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` gains a slice-coverage rule with the component
sweep, failing a key read outside the file's slice. 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 a component inside `packages/core`
renders with its slice instead; packages that depend on core (`lab`,
`richtext`) use `useTranslator()`.

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 +362,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
Loading