@astryxdesign/cli 0.1.6-canary.eb23da7 → 0.1.6-canary.eb549c8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/cli",
3
- "version": "0.1.6-canary.eb23da7",
3
+ "version": "0.1.6-canary.eb549c8",
4
4
  "displayName": "CLI",
5
5
  "description": "Scaffold projects, browse templates, generate themes, and get agent-ready docs from the command line.",
6
6
  "author": "Meta Open Source",
@@ -47,10 +47,6 @@
47
47
  "types": "./src/types/integration.d.ts",
48
48
  "import": "./src/integration.mjs"
49
49
  },
50
- "./doc": {
51
- "types": "./src/types/doc.d.ts",
52
- "import": "./src/doc.mjs"
53
- },
54
50
  "./template": {
55
51
  "types": "./src/types/template-api.d.ts",
56
52
  "import": "./src/template.mjs"
@@ -79,10 +75,10 @@
79
75
  "zod": "^4.4.3"
80
76
  },
81
77
  "peerDependencies": {
82
- "@astryxdesign/charts": "0.1.6-canary.eb23da7",
83
- "@astryxdesign/core": "0.1.6-canary.eb23da7",
84
- "@astryxdesign/lab": "0.1.6-canary.eb23da7",
85
- "@astryxdesign/theme-neutral": "0.1.6-canary.eb23da7",
78
+ "@astryxdesign/charts": "0.1.6-canary.eb549c8",
79
+ "@astryxdesign/core": "0.1.6-canary.eb549c8",
80
+ "@astryxdesign/lab": "0.1.6-canary.eb549c8",
81
+ "@astryxdesign/theme-neutral": "0.1.6-canary.eb549c8",
86
82
  "gpt-tokenizer": "^3.4.0"
87
83
  },
88
84
  "peerDependenciesMeta": {
@@ -100,10 +96,10 @@
100
96
  }
101
97
  },
102
98
  "devDependencies": {
103
- "@astryxdesign/charts": "0.1.6-canary.eb23da7",
104
- "@astryxdesign/core": "0.1.6-canary.eb23da7",
105
- "@astryxdesign/lab": "0.1.6-canary.eb23da7",
106
- "@astryxdesign/theme-neutral": "0.1.6-canary.eb23da7",
99
+ "@astryxdesign/charts": "0.1.6-canary.eb549c8",
100
+ "@astryxdesign/core": "0.1.6-canary.eb549c8",
101
+ "@astryxdesign/lab": "0.1.6-canary.eb549c8",
102
+ "@astryxdesign/theme-neutral": "0.1.6-canary.eb549c8",
107
103
  "gpt-tokenizer": "^3.4.0"
108
104
  },
109
105
  "scripts": {
@@ -67,6 +67,11 @@ function error(code, message) {
67
67
  return {code, severity: 'error', message};
68
68
  }
69
69
 
70
+ /** @param {string} code @param {string} message @returns {Issue} */
71
+ function warning(code, message) {
72
+ return {code, severity: 'warning', message};
73
+ }
74
+
70
75
  /**
71
76
  * Verify each declared contribution root exists on disk. A declared-but-missing
72
77
  * root is a `missing_root` error.
@@ -360,3 +365,6 @@ export function summarizeIssues(issues) {
360
365
  }
361
366
  return {errors, warnings};
362
367
  }
368
+
369
+ // Re-export issue constructors for callers/tests that want them.
370
+ export {error as integrationError, warning as integrationWarning};
@@ -273,24 +273,14 @@ export function findComponentReadme(coreDir, name) {
273
273
  * For "Button" finds src/Button/XDSButton.tsx
274
274
  * For "Layout" finds src/Layout/XDSLayout/XDSLayout.tsx
275
275
  * For "Card" finds src/Layout/Container/XDSCard.tsx (deep search fallback)
276
- *
277
- * Hooks and other functions are authored as `.ts` (e.g. `useMediaQuery.ts`,
278
- * `useResizable.ts`), so `.ts` candidates are searched alongside `.tsx`. Without
279
- * this, deriving the import path for a `.ts`-authored function falls back to the
280
- * bare `@astryxdesign/core` root instead of its tree-shakeable subpath.
281
276
  */
282
277
  export function findComponentSource(coreDir, name) {
283
278
  const srcDir = path.join(coreDir, 'src');
284
- // Try the prefixed forms (`XDSButton.tsx`) first since that is the current
285
- // on-disk convention, then the bare forms (`Button.tsx`) that the Astryx-prefix
286
- // migration (P4) renames to. `.tsx` before `.ts` within each so a component's
287
- // `.tsx` wins over a same-named `.ts` helper; `.ts` covers hooks/functions.
288
- const candidateFiles = [
289
- `XDS${name}.tsx`,
290
- `${name}.tsx`,
291
- `XDS${name}.ts`,
292
- `${name}.ts`,
293
- ];
279
+ // Try the prefixed form (`XDSButton.tsx`) first since that is the current
280
+ // on-disk convention, then the bare form (`Button.tsx`) that the Astryx-prefix
281
+ // migration (P4) renames to. Listing the prefixed name first keeps behavior
282
+ // identical until files are actually renamed.
283
+ const candidateFiles = [`XDS${name}.tsx`, `${name}.tsx`];
294
284
 
295
285
  function searchDir(dirPath) {
296
286
  if (!fs.existsSync(dirPath)) return null;
@@ -5,59 +5,6 @@
5
5
  */
6
6
 
7
7
  import {pathToFileURL} from 'node:url';
8
- import {importUserModule} from './module-loader.mjs';
9
- import {formatZodError} from './config-schema.mjs';
10
- import {ComponentDocSchema} from '../doc.mjs';
11
-
12
- /**
13
- * Load a component doc through the shared load/validation boundary.
14
- *
15
- * This is the typed counterpart to {@link loadDocs}: it loads `.doc.ts` via
16
- * jiti (and `.doc.mjs`/`.doc.js` via native import) and validates against
17
- * {@link ComponentDocSchema}. That schema accepts BOTH formats, so this loader
18
- * reads whichever the file uses:
19
- * - NEW: the factory default export
20
- * (`export default createComponentDoc({...})` / `createFunctionDoc` /
21
- * `createDoc`) — the same single-export convention
22
- * {@link loadModuleWithSchema} uses for config/integration/template. These
23
- * carry a stamped `type` and validate against the matching per-kind schema.
24
- * - OLD: the legacy loose `export const docs = {...}` (no `type`), validated
25
- * against the permissive legacy union.
26
- * The default export wins when both are present. Throws a readable
27
- * `formatZodError`-style message on failure. Translations (`docsZh`/
28
- * `docsDense`) are merged exactly as {@link loadDocs} does so callers see
29
- * identical output.
30
- *
31
- * @param {string} docPath absolute path to a `.doc.{ts,mjs,js}` file
32
- * @param {{zh?: boolean, dense?: boolean, lang?: string}} [opts]
33
- * @returns {Promise<object>} the validated (and optionally translated) doc
34
- */
35
- export async function loadComponentDoc(
36
- docPath,
37
- {zh = false, dense = false, lang} = {},
38
- ) {
39
- const mod = await importUserModule(docPath);
40
- const authored = mod?.default ?? mod?.docs;
41
-
42
- const result = ComponentDocSchema.safeParse(authored);
43
- if (!result.success) {
44
- throw new Error(formatZodError(docPath, result.error));
45
- }
46
- const docs = authored;
47
-
48
- const locale = lang || (dense ? 'dense' : zh ? 'zh' : null);
49
- if (!locale) return docs;
50
-
51
- const translationKey =
52
- locale === 'zh' ? 'docsZh' : locale === 'dense' ? 'docsDense' : null;
53
- if (!translationKey || !mod[translationKey]) return docs;
54
-
55
- const translation = mod[translationKey];
56
- if (translation.props || translation.components?.some(c => c.props)) {
57
- return translation;
58
- }
59
- return mergeTranslation(docs, translation);
60
- }
61
8
 
62
9
  export function mergeTranslation(docs, translation) {
63
10
  if (!translation) return docs;
@@ -73,3 +73,33 @@ export function formatZodError(label, error) {
73
73
  .join('; ');
74
74
  return `${label} is invalid: ${issues}`;
75
75
  }
76
+
77
+ /**
78
+ * @param {unknown} config
79
+ * @returns {import('../types/config').AstryxConfig}
80
+ */
81
+ export function validateConfig(config) {
82
+ const result = AstryxConfigSchema.safeParse(config);
83
+ if (!result.success) {
84
+ throw new Error(
85
+ formatZodError('astryx.config default export', result.error),
86
+ );
87
+ }
88
+ return result.data;
89
+ }
90
+
91
+ /**
92
+ * @param {unknown} integration
93
+ * @param {string} [label]
94
+ * @returns {import('../types/integration').AstryxIntegration}
95
+ */
96
+ export function validateIntegration(
97
+ integration,
98
+ label = 'integration manifest',
99
+ ) {
100
+ const result = AstryxIntegrationSchema.safeParse(integration);
101
+ if (!result.success) {
102
+ throw new Error(formatZodError(label, result.error));
103
+ }
104
+ return result.data;
105
+ }
@@ -230,3 +230,8 @@ export async function buildRegistry({cwd = process.cwd()} = {}) {
230
230
  };
231
231
  return cachedRegistry;
232
232
  }
233
+
234
+ /** Test seam — drop the module-level cache. */
235
+ export function resetRegistryCache() {
236
+ cachedRegistry = null;
237
+ }
@@ -39,19 +39,19 @@ import {neutralIconRegistry} from './icons';
39
39
  const neutralSyntax = defineSyntaxTheme({
40
40
  name: 'xds-neutral',
41
41
  tokens: {
42
- keyword: ['#700084', '#efa8ff'], // purple T30/T80
43
- string: ['#005600', '#a6d2a2'], // green (sat T30 / pastel T80)
44
- comment: ['#737373', '#a3a3a3'], // neutral
45
- number: ['#6e3500', '#ffb37f'], // orange
46
- function: ['#00458c', '#a0caff'], // blue T30/T80 H=255
47
- type: ['#700084', '#efa8ff'], // purple
48
- variable: ['#171717', '#e5e5e5'], // near-black / near-white
49
- operator: ['#737373', '#a3a3a3'], // neutral
50
- constant: ['#6e3500', '#ffb37f'], // orange
51
- tag: ['#89001a', '#ffaeaa'], // red
52
- attribute: ['#584400', '#eec12f'], // yellow
53
- property: ['#005348', '#83dac9'], // teal
54
- punctuation: ['#a3a3a3', '#525252'], // neutral
42
+ keyword: ['#700084', '#efa8ff'], // purple T30/T80
43
+ string: ['#005600', '#a6d2a2'], // green (sat T30 / pastel T80)
44
+ comment: ['#737373', '#a3a3a3'], // neutral
45
+ number: ['#6e3500', '#ffb37f'], // orange
46
+ function: ['#00458c', '#a0caff'], // blue T30/T80 H=255
47
+ type: ['#700084', '#efa8ff'], // purple
48
+ variable: ['#171717', '#e5e5e5'], // near-black / near-white
49
+ operator: ['#737373', '#a3a3a3'], // neutral
50
+ constant: ['#6e3500', '#ffb37f'], // orange
51
+ tag: ['#89001a', '#ffaeaa'], // red
52
+ attribute: ['#584400', '#eec12f'], // yellow
53
+ property: ['#005348', '#83dac9'], // teal
54
+ punctuation: ['#a3a3a3', '#525252'],// neutral
55
55
  background: ['#fafafa', '#0a0a0a'],
56
56
  },
57
57
  });
@@ -127,39 +127,39 @@ export const neutralTheme = defineTheme({
127
127
  // All values use the OKLCH Neutral tonal palette (chroma=0).
128
128
  // =========================================================================
129
129
  '--color-background-surface': ['#ffffff', '#262626'],
130
- '--color-background-body': ['#f1f1f1', '#1b1b1b'],
131
- '--color-background-card': ['#ffffff', '#1b1b1b'],
130
+ '--color-background-body': ['#f1f1f1', '#1b1b1b'],
131
+ '--color-background-card': ['#ffffff', '#1b1b1b'],
132
132
  '--color-background-popover': ['#ffffff', '#1b1b1b'],
133
- '--color-background-muted': ['#f1f1f1', '#1b1b1b'],
133
+ '--color-background-muted': ['#f1f1f1', '#1b1b1b'],
134
134
 
135
135
  // Accent + neutral surface tints (sit alongside backgrounds)
136
- '--color-accent': ['#262626', '#ebebeb'],
136
+ '--color-accent': ['#262626', '#ebebeb'],
137
137
  '--color-accent-muted': ['#f1f1f1', '#262626'],
138
- '--color-neutral': ['#0000000F', '#FFFFFF1A'],
138
+ '--color-neutral': ['#0000000F', '#FFFFFF1A'],
139
139
 
140
140
  // Overlays (modal scrims, hover/pressed tints)
141
- '--color-overlay': ['#00000080', '#000000CC'],
142
- '--color-overlay-hover': ['#0000000D', '#FFFFFF0D'],
141
+ '--color-overlay': ['#00000080', '#000000CC'],
142
+ '--color-overlay-hover': ['#0000000D', '#FFFFFF0D'],
143
143
  '--color-overlay-pressed': ['#0000001A', '#FFFFFF1A'],
144
144
 
145
145
  // Text
146
- '--color-text-primary': ['#171717', '#fafafa'],
146
+ '--color-text-primary': ['#171717', '#fafafa'],
147
147
  '--color-text-secondary': ['#737373', '#a3a3a3'],
148
- '--color-text-disabled': ['#a3a3a3', '#525252'],
149
- '--color-text-accent': ['#262626', '#ebebeb'],
150
- '--color-on-dark': '#ffffff',
151
- '--color-on-light': '#171717',
148
+ '--color-text-disabled': ['#a3a3a3', '#525252'],
149
+ '--color-text-accent': ['#262626', '#ebebeb'],
150
+ '--color-on-dark': '#ffffff',
151
+ '--color-on-light': '#171717',
152
152
  // Contrast: neutral accent is near-black (L) / near-white (D)
153
- '--color-on-accent': ['#ffffff', '#171717'],
153
+ '--color-on-accent': ['#ffffff', '#171717'],
154
154
  '--color-on-success': ['#ffffff', '#171717'],
155
- '--color-on-error': ['#ffffff', '#171717'],
155
+ '--color-on-error': ['#ffffff', '#171717'],
156
156
  '--color-on-warning': '#171717',
157
157
 
158
158
  // Icon
159
- '--color-icon-accent': ['#262626', '#ebebeb'],
160
- '--color-icon-primary': ['#171717', '#fafafa'],
159
+ '--color-icon-accent': ['#262626', '#ebebeb'],
160
+ '--color-icon-primary': ['#171717', '#fafafa'],
161
161
  '--color-icon-secondary': ['#737373', '#a3a3a3'],
162
- '--color-icon-disabled': ['#a3a3a3', '#525252'],
162
+ '--color-icon-disabled': ['#a3a3a3', '#525252'],
163
163
 
164
164
  // Status / Sentiment — dark mode follows the issue #2150 rubric:
165
165
  //
@@ -372,8 +372,8 @@ export const neutralTheme = defineTheme({
372
372
  // =========================================================================
373
373
  button: {
374
374
  'variant:destructive': {
375
- backgroundColor: 'var(--color-error-muted)', // locked pastel red bg
376
- color: 'var(--color-error)', // locked T30 red — matches banner/input error text
375
+ backgroundColor: 'var(--color-error-muted)', // locked pastel red bg
376
+ color: 'var(--color-error)', // locked T30 red — matches banner/input error text
377
377
  },
378
378
  },
379
379
 
@@ -482,37 +482,6 @@ export const neutralTheme = defineTheme({
482
482
  },
483
483
  },
484
484
 
485
- // =========================================================================
486
- // StatusDot — fill uses the SAME vivid stops as the filled semantic Badge
487
- // (and ProgressBar), so a dot and its badge read as one status language.
488
- //
489
- // The default component maps each variant to a raw semantic token
490
- // (--color-success / --color-error / --color-warning / --color-icon-
491
- // secondary), which in light mode are the dark T30/T40 stops meant to
492
- // sit as TEXT on a pastel surface — as a solid dot they read muddy
493
- // (dark green / maroon / brown). Redirect them to the badge fills.
494
- //
495
- // success → badge success bg (green T45 / dark-ramp T60)
496
- // warning → badge warning bg (yellow T85, same hex both modes)
497
- // error → badge error bg (red T55 / dark-ramp T60)
498
- // accent → badge info bg (blue T50 / dark-ramp T60) — the
499
- // StatusDot "accent" is the info/attention color, so it
500
- // pairs with the info badge rather than --color-accent
501
- // (near-black #262626, the darkest offender).
502
- //
503
- // `neutral` is intentionally NOT overridden: the neutral badge bg is a
504
- // near-invisible light gray (--color-background-gray #e5e5e5 / 10% white
505
- // wash), fine as a large pill but unreadable as an 8px dot. It keeps the
506
- // component default's visible mid-gray (--color-icon-secondary), which is
507
- // not among the "too dark" cases.
508
- // =========================================================================
509
- statusdot: {
510
- 'variant:success': {backgroundColor: 'light-dark(#198100, #64af4c)'},
511
- 'variant:warning': {backgroundColor: '#ffce2f'},
512
- 'variant:error': {backgroundColor: 'light-dark(#e33f4a, #ff705d)'},
513
- 'variant:accent': {backgroundColor: 'light-dark(#0074e2, #6d9cfe)'},
514
- },
515
-
516
485
  // =========================================================================
517
486
  // Banner — sits on a hue-tinted surface with colored text/icon:
518
487
  // Light: pastel T90 bg (pulled from --color-{X}-muted / --color-background-blue)
@@ -1,243 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /** @type {import('../../core/src/docs-types').ReferenceDoc} */
4
-
5
- export const docs = {
6
- name: 'internationalization',
7
- title: 'Internationalization',
8
- category: 'guide',
9
- description:
10
- 'Localize astryx component strings, provide translation catalogs, override default text, coexist with your own i18n library, swap languages at runtime, and test translations with the pseudo locale.',
11
-
12
- sections: [
13
- {
14
- title: 'Quick Start',
15
- category: 'guide',
16
- content: [
17
- {
18
- type: 'prose',
19
- text: 'Internationalization ships with `@astryxdesign/core`. There is nothing to install. Wrap your app in `<InternationalizationProvider>` and set a `locale` — astryx components pick up localized strings automatically.',
20
- },
21
- {
22
- type: 'code',
23
- lang: 'tsx',
24
- label: 'Wrap your app',
25
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
26
-
27
- function App() {
28
- return (
29
- <InternationalizationProvider locale="en">
30
- <YourApp />
31
- </InternationalizationProvider>
32
- );
33
- }`,
34
- },
35
- {
36
- type: 'code',
37
- lang: 'tsx',
38
- label: 'Read strings inside a component',
39
- code: `import {useTranslator} from '@astryxdesign/core';
40
-
41
- function SaveButton() {
42
- const t = useTranslator();
43
- return <button>{t('@myapp.actions.save')}</button>;
44
- }`,
45
- },
46
- {
47
- type: 'prose',
48
- text: 'The hook is available to consumer components too, but using it is entirely optional — many teams keep their app strings on their existing i18n library (react-intl, i18next, next-intl, LinguiJS) and only use `useTranslator` when reading astryx keys. If you do route your own strings through it, we recommend namespacing them (`@myapp.*` or your npm scope) to keep them separated from `@astryx.*`, but this is a convention, not a requirement — the resolver treats every key as an opaque string.',
49
- },
50
- {
51
- type: 'prose',
52
- text: "Astryx ships translations only for English today. First-party translations for other locales are on the roadmap and coming soon — track https://github.com/facebook/astryx/issues/3641. In the meantime, if you want astryx UI translated into another locale, you can ship your own catalog through the `messages` prop (covered in the next section). If you're using `useTranslator` for your own strings, you'll want to ship your own catalog either way — astryx only carries the fallback for `@astryx.*` keys, not the ones you author.",
53
- },
54
- ],
55
- },
56
- {
57
- title: 'Providing locale catalogs',
58
- category: 'guide',
59
- content: [
60
- {
61
- type: 'prose',
62
- text: 'Astryx bundles only the English catalog today. To render in any other locale, provide a translation catalog through the `messages` prop and set `locale` accordingly. This matches how MUI, Ant Design, and AG Grid work — the consumer app supplies the catalogs it actually needs so unused translations stay out of the bundle.',
63
- },
64
- {
65
- type: 'code',
66
- lang: 'tsx',
67
- label: 'Add French',
68
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
69
- import fr from './locales/astryx/fr.json';
70
-
71
- <InternationalizationProvider locale="fr" messages={{fr}}>
72
- <App />
73
- </InternationalizationProvider>;`,
74
- },
75
- {
76
- type: 'prose',
77
- text: "See `@astryxdesign/core/locales/en.json` for the full inventory of keys to translate. Copy it as the starting point — every key you translate replaces the English default; anything you omit falls back through the locale chain to English (e.g. `pt-BR` walks to `pt` then to shipped `en`), so a partial translation renders as a mix rather than empty text or raw key names.",
78
- },
79
- {
80
- type: 'prose',
81
- text: 'A community-maintained set of astryx translations is on the roadmap but not shipped yet. For now, consumer apps that ship in multiple languages own their astryx catalogs alongside their app catalogs. Contributions to a first-party set are welcome — track discussion at https://github.com/facebook/astryx/issues/3641.',
82
- },
83
- ],
84
- },
85
- {
86
- title: "Overriding astryx's default text",
87
- category: 'guide',
88
- content: [
89
- {
90
- type: 'prose',
91
- text: 'Use `overrides` to change individual strings without shipping a full catalog. Overrides are keyed by locale and merged on top of the built-in and user-supplied catalogs.',
92
- },
93
- {
94
- type: 'code',
95
- lang: 'tsx',
96
- label: 'Change one string in English',
97
- code: `<InternationalizationProvider
98
- locale="en"
99
- overrides={{en: {'@astryx.pagination.next': 'Next →'}}}
100
- >
101
- <App />
102
- </InternationalizationProvider>`,
103
- },
104
- {
105
- type: 'prose',
106
- text: 'Overrides win over both bundled English and any `messages` catalog for the same key. Use them for brand voice tweaks or one-off wording changes.',
107
- },
108
- ],
109
- },
110
- {
111
- title: 'Using astryx with your own i18n library',
112
- category: 'guide',
113
- content: [
114
- {
115
- type: 'prose',
116
- text: "Astryx components render astryx strings through astryx's provider. Consumer components render consumer strings through whatever i18n library you already use — react-intl, i18next, next-intl, LinguiJS, and so on. The two systems coexist and read from the same source of truth for the active locale.",
117
- },
118
- {
119
- type: 'code',
120
- lang: 'tsx',
121
- label: 'Astryx + react-intl side by side',
122
- code: `import {InternationalizationProvider} from '@astryxdesign/core';
123
- import {Selector} from '@astryxdesign/core/Selector';
124
- import {Button} from '@astryxdesign/core/Button';
125
- import {FormattedMessage, IntlProvider, useIntl} from 'react-intl';
126
- import astryxFr from './locales/astryx/fr.json'; // astryx's UI, in French
127
- import appFr from './locales/app/fr.json'; // your app strings, in French
128
-
129
- function Pricing() {
130
- // Consumer strings — resolved by react-intl.
131
- const intl = useIntl();
132
-
133
- return (
134
- <section>
135
- <h1><FormattedMessage id="pricing.heading" /></h1>
136
-
137
- {/* Astryx Selector — trigger placeholder, search-box placeholder,
138
- clear-button aria-label all resolved by
139
- <InternationalizationProvider>. Options come from react-intl. */}
140
- <Selector
141
- label={intl.formatMessage({id: 'pricing.region.label'})}
142
- options={[
143
- {value: 'na', label: intl.formatMessage({id: 'pricing.region.na'})},
144
- {value: 'eu', label: intl.formatMessage({id: 'pricing.region.eu'})},
145
- ]}
146
- hasSearch
147
- hasClear
148
- />
149
-
150
- <Button label={intl.formatMessage({id: 'pricing.cta.subscribe'})} />
151
- </section>
152
- );
153
- }
154
-
155
- export default function App() {
156
- return (
157
- // Same locale, two providers reading their own catalogs.
158
- <IntlProvider locale="fr" messages={appFr}>
159
- <InternationalizationProvider locale="fr" messages={{fr: astryxFr}}>
160
- <Pricing />
161
- </InternationalizationProvider>
162
- </IntlProvider>
163
- );
164
- }`,
165
- },
166
- {
167
- type: 'prose',
168
- text: 'Keep the two providers in sync on locale, and each library owns its own catalog. Astryx never sees your app strings, and your i18n library never sees astryx internals. Runtime locale swap works the same way — re-render both providers with a new `locale` prop and the whole tree updates live.',
169
- },
170
- {
171
- type: 'prose',
172
- text: "Single-catalog usage — where an external i18n runtime like react-intl or i18next resolves both your app strings AND astryx's strings through one provider — is on the roadmap via a `Translator` adapter. Track https://github.com/facebook/astryx/issues/4029. For now, run the two providers side by side as shown above.",
173
- },
174
- ],
175
- },
176
- {
177
- title: 'Runtime language swap',
178
- category: 'guide',
179
- content: [
180
- {
181
- type: 'prose',
182
- text: 'Re-render `<InternationalizationProvider>` with a new `locale` prop and every astryx string updates live. No reload, no separate API call.',
183
- },
184
- {
185
- type: 'code',
186
- lang: 'tsx',
187
- label: 'Toggle between locales',
188
- code: `const [locale, setLocale] = useState<'en' | 'fr'>('en');
189
-
190
- <InternationalizationProvider locale={locale} messages={{fr}}>
191
- <Button
192
- label={locale === 'en' ? 'Français' : 'English'}
193
- onClick={() => setLocale(l => (l === 'en' ? 'fr' : 'en'))}
194
- />
195
- <App />
196
- </InternationalizationProvider>;`,
197
- },
198
- {
199
- type: 'prose',
200
- text: "Persisting the user's choice (localStorage, cookie, URL segment, account setting) is up to the consumer. Astryx reads whatever `locale` you pass in.",
201
- },
202
- ],
203
- },
204
- {
205
- title: 'Testing your translations',
206
- category: 'guide',
207
- content: [
208
- {
209
- type: 'prose',
210
- text: 'Astryx generates a `pseudo` locale that wraps every string in `⟦…⟧` and replaces letters with accented look-alikes. Switching to it in development instantly reveals any astryx string that isn\'t going through the translator, plus any layout that breaks under longer text.',
211
- },
212
- {
213
- type: 'code',
214
- lang: 'tsx',
215
- label: 'Turn on pseudo-localization',
216
- code: `import pseudo from '@astryxdesign/core/locales/pseudo.json';
217
-
218
- <InternationalizationProvider locale="pseudo" messages={{pseudo}}>
219
- <App />
220
- </InternationalizationProvider>;`,
221
- },
222
- {
223
- type: 'prose',
224
- text: 'Any bare English text you still see on screen is a hardcoded string that needs to be routed through `useTranslator`.',
225
- },
226
- {
227
- type: 'prose',
228
- text: "Pseudoloc also has a subtle caveat worth knowing: the pseudo catalog is complete (astryx generates it from every shipped key), so a component using an astryx-shipped key will always render its pseudo version. Your handwritten translation catalogs, on the other hand, only cover the keys you translated — anything missing falls back to English. That means \"looks perfect in pseudo\" is not the same guarantee as \"looks perfect in French.\" Check each real locale by hand for coverage gaps.",
229
- },
230
- ],
231
- },
232
- {
233
- title: 'For contributors',
234
- category: 'guide',
235
- content: [
236
- {
237
- type: 'prose',
238
- text: "Astryx's own strings live in `packages/core/locales/en.json`. New user-facing strings must go through `useTranslator` — this is enforced by the `@astryx/no-hardcoded-i18n-string` ESLint rule. See the AI contribution guide for the alias-and-resolve pattern used when adding new keys.",
239
- },
240
- ],
241
- },
242
- ],
243
- };