Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): Table, Chat, CommandPalette and the date and time inputs carry only their own English (#9452)

Cindy Zhang16fe5f199322
diff --git a/.changeset/smaller-english-fallback-remaining.md b/.changeset/smaller-english-fallback-remaining.md
new file mode 100644
index 0000000000..07d73b1ece
--- /dev/null
+++ b/.changeset/smaller-english-fallback-remaining.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Table, Markdown, Chat, CommandPalette and the date and time inputs are smaller too. Each now carries only the English for its own strings instead of every Core string, about 7 KB less (gzip) each. PowerSearch still carries every Core string, because a custom operator's `i18nKey` can name any Astryx key. Nothing you see changes: every built-in string shows the same English, and translations and overrides resolve as before.
+
+@cixzhang
diff --git a/docs/architecture/internationalization.md b/docs/architecture/internationalization.md
index fef6a45735..9b4731dfe5 100644
--- a/docs/architecture/internationalization.md
+++ b/docs/architecture/internationalization.md
@@ -317,12 +317,7 @@ for all 30 shipped locales plus `pseudo`.
generated English module: each Core module that names catalog keys registers
a derived map of exactly those keys, and public paths that resolve any Astryx
key register the whole module. Neither path, shape, nor export of the rich
- catalogs changes because generated modules exist. Table, Chat, PowerSearch,
- CommandPalette, and the date and time input modules do not yet conform: they
- register no map of their own and resolve their keys through the public
- `useTranslator`, so every component that renders one still carries the whole
- catalog. That is a known conformance gap, and the wiring check accepts it
- until those modules register their own maps.
+ catalogs changes because generated modules exist.
- **INV16 — Standard build integration resolves both catalog forms.** The Astryx
Vite plugin resolves `@astryxdesign/core/locales/<tag>.json` to the rich
authored file and `@astryxdesign/core/locales/<tag>.generated.js` to the
@@ -400,10 +395,9 @@ inferred from an implementation pull request.
English map into `packages/core/src/i18n/generated-english/` (ignored,
internal, not exported), check that every module naming catalog keys
registers its own map, and name the public paths that register the whole
- catalog, such as the public `useTranslator` and the public
- `InternationalizationContext` export. Until the INV15 conformance gap closes,
- the check also accepts a module that names keys and imports the public
- `useTranslator` instead of its own map.
+ catalog: the public `useTranslator`, the public `InternationalizationContext`
+ export, and PowerSearch operator labels. No other Core module imports the
+ public `useTranslator` or the public context export.
- `packages/core/package.json` `exports` — publishes both `./locales/*.json` and
`./locales/*.generated.js`.
- `packages/build/src/vite.ts` — resolves both catalog import forms in source
@@ -444,7 +438,7 @@ callers remain conformance work and do not relax INV1a, INV8, INV9, or INV10.
| INV3–INV5 | resolver and provider rerender tests | no-provider output depends on the host, locale swaps stay stale, fallback order changes, or malformed-locale behavior is described as graceful |
| INV3a | factory unit tests: a flat option or `labels` key replaces its message, including under a provider, and outside a provider its absence announces or shows shipped English; wrapper tests: under a non-English provider its absence gives the translation. Evidence gap: no factory test covers a flat option or `labels` key yet | a factory announces or shows Astryx text that no option or `labels` key can replace, groups more than one string outside one `labels` object, takes a translator, ignores a given string, or gives something other than the catalog message when it is absent |
| INV6 | `check:i18n-catalog`, key-format lint, and focused mutation tests | stale/malformed keys, malformed ICU, or source/translation runtime-contract drift passes CI |
-| INV15 | generator tests, `check:i18n-runtime`, package-export drift check, provider/resolver runtime-catalog tests; per-module English resolution-parity test (every key each Core module names, in every shipped locale’s fallback path, its own map versus the whole catalog); import-cost check (component bundles carry only the English they name; public paths keep the whole catalog). Known gap: Table, Chat, PowerSearch, CommandPalette, and the date and time input modules still resolve through the public `useTranslator` | a generated module carries descriptions or is committed, a malformed entry projects instead of failing, a rich export path changes, or a `RuntimeCatalog` input is rejected or leaks a non-rich context shape, a key a module names resolves differently from the whole catalog, a component bundle carries the whole catalog, or a public path stops resolving a shipped key |
+| INV15 | generator tests, `check:i18n-runtime`, package-export drift check, provider/resolver runtime-catalog tests; per-module English resolution-parity test (every key each Core module names, in every shipped locale’s fallback path, its own map versus the whole catalog); import-cost check (component bundles carry only the English they name; public paths keep the whole catalog) | a generated module carries descriptions or is committed, a malformed entry projects instead of failing, a rich export path changes, or a `RuntimeCatalog` input is rejected or leaks a non-rich context shape, a key a module names resolves differently from the whole catalog, a component bundle carries the whole catalog, or a public path stops resolving a shipped key |
| INV16 | build-plugin unit and real-build tests | a rich or generated locale import fails to resolve through the standard plugin |
| INV8, INV9 | raw-Intl-locale lint (module allowlist plus date-helper locale-argument check) and provider-locale regression tests, including a server/client render pair | Astryx output follows the host locale, raw `Intl` appears outside a named formatter module, an owned call omits the locale argument, or server and client output differ for the same provider locale |
| INV10 | PlainDate and built-in date formatter tests, including locales with non-Gregorian defaults | locale selects a non-Gregorian built-in date display, changes PlainDate calendar semantics, or loses the explicit low-level display override |
diff --git a/packages/core/src/Chat/ChatComposer.tsx b/packages/core/src/Chat/ChatComposer.tsx
index cb218a5306..f95a6918e7 100644
--- a/packages/core/src/Chat/ChatComposer.tsx
+++ b/packages/core/src/Chat/ChatComposer.tsx
@@ -52,13 +52,19 @@ import {ChatComposerContext} from './ChatContext';
import type {ChatComposerInputControl} from './ChatContext';
import {ChatSendButton} from './ChatSendButton';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
import {useAnnounceRenderedText} from '../hooks/useAnnounceRenderedText';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {innermostInteractive} from '../hooks/useClickableContainer';
import {isLayerSurface} from '../Layer/layerSurfacePress';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
import {useInteractionModalityTracking} from '../utils/interactionModality';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatComposer.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -362,7 +368,7 @@ function isComposerEditor(target: EventTarget | null): target is HTMLElement {
* ```
*/
export function ChatComposer(props: ChatComposerProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {
ref,
onSubmit,
diff --git a/packages/core/src/Chat/ChatComposerDrawer.tsx b/packages/core/src/Chat/ChatComposerDrawer.tsx
index 50d039efc7..991a4c165b 100644
--- a/packages/core/src/Chat/ChatComposerDrawer.tsx
+++ b/packages/core/src/Chat/ChatComposerDrawer.tsx
@@ -37,7 +37,13 @@ import {mergeProps} from '../utils';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatComposerDrawer.generated';
+
+registerEnglishFallback(english);
export interface ChatComposerDrawerProps extends BaseProps<HTMLDivElement> {
ref?: React.Ref<HTMLDivElement>;
@@ -253,7 +259,7 @@ export function ChatComposerDrawer({
'data-testid': testId,
...htmlProps
}: ChatComposerDrawerProps): React.ReactElement {
- const t = useTranslator();
+ const t = useComponentTranslator();
const label = labelFromProps ?? t('@astryx.chat.composerDrawer.label');
const [internalCollapsed, setInternalCollapsed] =
useState(defaultIsCollapsed);
diff --git a/packages/core/src/Chat/ChatComposerInput.tsx b/packages/core/src/Chat/ChatComposerInput.tsx
index 69ba3cdc71..7e9f5a413f 100644
--- a/packages/core/src/Chat/ChatComposerInput.tsx
+++ b/packages/core/src/Chat/ChatComposerInput.tsx
@@ -68,7 +68,13 @@ import {
import {Badge, type BadgeProps} from '../Badge';
import {useChatComposerContext} from './ChatContext';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatComposerInput.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -346,7 +352,7 @@ function serialize(node: Node): string {
// =============================================================================
export function ChatComposerInput(props: ChatComposerInputProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const composerCtx = useChatComposerContext();
const hasControlledValueProp = props.value !== undefined;
diff --git a/packages/core/src/Chat/ChatDictationButton.tsx b/packages/core/src/Chat/ChatDictationButton.tsx
index 364247f542..a5948f176d 100644
--- a/packages/core/src/Chat/ChatDictationButton.tsx
+++ b/packages/core/src/Chat/ChatDictationButton.tsx
@@ -28,7 +28,13 @@ import {Icon} from '../Icon';
import {mergeProps} from '../utils';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatDictationButton.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -113,7 +119,7 @@ export function ChatDictationButton({
style,
...rest
}: ChatDictationButtonProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
if (isHiddenWhenUnsupported && !dictation.isSupported) {
return null;
diff --git a/packages/core/src/Chat/ChatLayout.tsx b/packages/core/src/Chat/ChatLayout.tsx
index 5f6f3a0807..af8b18fed0 100644
--- a/packages/core/src/Chat/ChatLayout.tsx
+++ b/packages/core/src/Chat/ChatLayout.tsx
@@ -39,9 +39,15 @@ import {useChatNewMessages} from './useChatNewMessages';
import {ChatLayoutScrollButton} from './ChatLayoutScrollButton';
import {ChatLayoutContext} from './ChatContext';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
import {useMergedRefs} from '../hooks/useMergedRefs';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatLayout.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
// =============================================================================
@@ -296,7 +302,7 @@ export function ChatLayout({
ref,
...rest
}: ChatLayoutProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const rootRef = useRef<HTMLDivElement>(null);
const scrollContainerRef = externalScrollRef ?? rootRef;
diff --git a/packages/core/src/Chat/ChatLayoutScrollButton.tsx b/packages/core/src/Chat/ChatLayoutScrollButton.tsx
index 70d7b9afd1..e8c3818d9b 100644
--- a/packages/core/src/Chat/ChatLayoutScrollButton.tsx
+++ b/packages/core/src/Chat/ChatLayoutScrollButton.tsx
@@ -32,7 +32,13 @@ import {Button} from '../Button';
import type {BaseProps} from '../BaseProps';
import {mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatLayoutScrollButton.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -138,7 +144,7 @@ export function ChatLayoutScrollButton({
style,
...rest
}: ChatLayoutScrollButtonProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
return (
// Two elements, two responsibilities. The outer one centres the pill and
// holds the gap above the composer — spacing outside the pill's border
diff --git a/packages/core/src/Chat/ChatMessage.tsx b/packages/core/src/Chat/ChatMessage.tsx
index 06c76a1b43..56e7015a4e 100644
--- a/packages/core/src/Chat/ChatMessage.tsx
+++ b/packages/core/src/Chat/ChatMessage.tsx
@@ -38,7 +38,13 @@ import {isRenderable, mergeProps} from '../utils';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {chatMessageVars} from './chatMessage.vars.stylex';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatMessage.generated';
+
+registerEnglishFallback(english);
export interface ChatMessageProps extends BaseProps<HTMLElement> {
ref?: React.Ref<HTMLElement>;
@@ -205,7 +211,7 @@ export function ChatMessage({
ref,
...rest
}: ChatMessageProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const listContext = useChatListContext();
const density = densityProp ?? listContext?.density ?? 'balanced';
diff --git a/packages/core/src/Chat/ChatMessageList.tsx b/packages/core/src/Chat/ChatMessageList.tsx
index 655f35369a..a160762849 100644
--- a/packages/core/src/Chat/ChatMessageList.tsx
+++ b/packages/core/src/Chat/ChatMessageList.tsx
@@ -37,8 +37,14 @@ import {Spinner} from '../Spinner';
import type {BaseProps} from '../BaseProps';
import type {SpacingStep} from '../utils/types';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatMessageList.generated';
+
+registerEnglishFallback(english);
export interface ChatMessageListProps extends BaseProps<HTMLDivElement> {
/** Ref forwarded to the root element */
@@ -240,7 +246,7 @@ export function ChatMessageList({
const sentinelRef = useRef<HTMLDivElement>(null);
const innerRef = useRef<HTMLDivElement>(null);
const [isLoadingTop, startTransition] = useTransition();
- const t = useTranslator();
+ const t = useComponentTranslator();
// The top loading Spinner sits inside the log and is silent; the list
// announces its loading through the channel (spec:AST-086 FR4, FR8).
useBusyAnnouncement(isLoadingTop, t('@astryx.spinner.loading'), innerRef);
diff --git a/packages/core/src/Chat/ChatMessageMetadata.tsx b/packages/core/src/Chat/ChatMessageMetadata.tsx
index 86ba588d81..35b1a4a85d 100644
--- a/packages/core/src/Chat/ChatMessageMetadata.tsx
+++ b/packages/core/src/Chat/ChatMessageMetadata.tsx
@@ -26,7 +26,13 @@ import type {IconName} from '../Icon/globalIconRegistry';
import {isRenderable, mergeProps} from '../utils';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatMessageMetadata.generated';
+
+registerEnglishFallback(english);
export type ChatMessageStatus =
'sending' | 'sent' | 'delivered' | 'read' | 'error';
@@ -118,7 +124,7 @@ export function ChatMessageMetadata({
style,
...rest
}: ChatMessageMetadataProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const msgContext = useChatMessageContext();
const sender = msgContext?.sender ?? 'assistant';
diff --git a/packages/core/src/Chat/ChatPastedTextToken.tsx b/packages/core/src/Chat/ChatPastedTextToken.tsx
index db3c44f1f3..a7e95e8f15 100644
--- a/packages/core/src/Chat/ChatPastedTextToken.tsx
+++ b/packages/core/src/Chat/ChatPastedTextToken.tsx
@@ -27,8 +27,15 @@ import {
import {Badge} from '../Badge';
import {Button} from '../Button';
import {HoverCard} from '../HoverCard';
-import {useTranslator, type TranslatorFn} from '../i18n';
+import type {TranslatorFn} from '../i18n';
import {useTapStop} from '../Layer/useTouchTrigger';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatPastedTextToken.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -93,7 +100,7 @@ export function ChatPastedTextToken({
text,
onExpand,
}: ChatPastedTextTokenProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const label = formatLabel(text, t);
// A tap on the token, by finger or pen, asks for its preview, so it stops
// there: cancelling the mouse press the browser makes of it keeps the
diff --git a/packages/core/src/Chat/ChatSendButton.tsx b/packages/core/src/Chat/ChatSendButton.tsx
index 53a7705d1b..5eb063911b 100644
--- a/packages/core/src/Chat/ChatSendButton.tsx
+++ b/packages/core/src/Chat/ChatSendButton.tsx
@@ -27,7 +27,13 @@ import {useChatComposerContext} from './ChatContext';
import type {BaseProps} from '../BaseProps';
import {composeEventHandlers, mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatSendButton.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -78,7 +84,7 @@ const styles = stylex.create({
* ```
*/
export function ChatSendButton(props: ChatSendButtonProps): ReactNode {
- const t = useTranslator();
+ const t = useComponentTranslator();
const context = useChatComposerContext();
const {
diff --git a/packages/core/src/Chat/ChatToolCalls.tsx b/packages/core/src/Chat/ChatToolCalls.tsx
index ccff909967..c6135f8d0b 100644
--- a/packages/core/src/Chat/ChatToolCalls.tsx
+++ b/packages/core/src/Chat/ChatToolCalls.tsx
@@ -39,7 +39,13 @@ import {Spinner} from '../Spinner';
import {VisuallyHidden} from '../VisuallyHidden';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/ChatToolCalls.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -363,7 +369,7 @@ const STATUS_STYLES: Record<
};
function getStatusAnnouncement(
- t: ReturnType<typeof useTranslator>,
+ t: ReturnType<typeof useComponentTranslator>,
status: ChatToolCallStatus,
errorMessage?: string,
): string {
@@ -408,7 +414,7 @@ function CallRow({
call: ChatToolCallItem;
hasClippedFocusRing?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const status = call.status ?? 'complete';
const hasDetail = call.resultDetail != null;
const [isDetailOpen, setIsDetailOpen] = useState(false);
@@ -548,7 +554,7 @@ function CallRow({
* ```
*/
export function ChatToolCalls(props: ChatToolCallsProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {
calls,
label: customLabel,
diff --git a/packages/core/src/Chat/useSpeechRecognition.ts b/packages/core/src/Chat/useSpeechRecognition.ts
index 20c6e568e4..741588d05f 100644
--- a/packages/core/src/Chat/useSpeechRecognition.ts
+++ b/packages/core/src/Chat/useSpeechRecognition.ts
@@ -14,7 +14,14 @@
*/
import {useState, useCallback, useEffect, useMemo, useRef} from 'react';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/useSpeechRecognition.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -259,7 +266,7 @@ function getDefaultAudioContext(): AudioContext {
export function useSpeechRecognition(
options: UseSpeechRecognitionOptions = {},
): UseSpeechRecognitionReturn {
- const t = useTranslator();
+ const t = useComponentTranslator();
const providerLocale = useLocale();
const {
lang,
diff --git a/packages/core/src/Chat/useTriggerMenu.tsx b/packages/core/src/Chat/useTriggerMenu.tsx
index 0d0fee3af2..f743c7bd8f 100644
--- a/packages/core/src/Chat/useTriggerMenu.tsx
+++ b/packages/core/src/Chat/useTriggerMenu.tsx
@@ -44,8 +44,14 @@ import {
import {mergeProps, groupItems, isImeKeyEvent} from '../utils';
import type {SearchableItem} from '../Typeahead/types';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
import type {ChatComposerTrigger, ChatComposerToken} from './ChatComposerInput';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Chat/useTriggerMenu.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -333,7 +339,7 @@ function deleteTriggerText(
export function useTriggerMenu(
options: UseTriggerMenuOptions,
): UseTriggerMenuReturn {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {
triggers,
editableRef,
diff --git a/packages/core/src/CommandPalette/CommandPalette.tsx b/packages/core/src/CommandPalette/CommandPalette.tsx
index a1bdb5d400..e1dbcc3e90 100644
--- a/packages/core/src/CommandPalette/CommandPalette.tsx
+++ b/packages/core/src/CommandPalette/CommandPalette.tsx
@@ -40,7 +40,13 @@ import {CommandPaletteEmpty} from './CommandPaletteEmpty';
import type {BaseProps} from '../BaseProps';
import {useAnnounce} from '../hooks/useAnnounce';
import {useAnnounceRenderedText} from '../hooks/useAnnounceRenderedText';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/CommandPalette/CommandPalette.generated';
+
+registerEnglishFallback(english);
export interface CommandPaletteProps<
T extends SearchableItem = SearchableItem,
@@ -297,7 +303,7 @@ export function CommandPalette<T extends SearchableItem = SearchableItem>({
maxHeight = 480,
...rest
}: CommandPaletteProps<T>) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const label = labelFromProps ?? t('@astryx.commandPalette.label');
const emptySearchText =
emptySearchTextFromProps ?? t('@astryx.commandPalette.emptySearch');
diff --git a/packages/core/src/CommandPalette/CommandPaletteFooter.tsx b/packages/core/src/CommandPalette/CommandPaletteFooter.tsx
index dce71a3b4f..1baab71855 100644
--- a/packages/core/src/CommandPalette/CommandPaletteFooter.tsx
+++ b/packages/core/src/CommandPalette/CommandPaletteFooter.tsx
@@ -24,7 +24,13 @@ import {
} from '../theme/tokens.stylex';
import {Kbd} from '../Kbd';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/CommandPalette/CommandPaletteFooter.generated';
+
+registerEnglishFallback(english);
const styles = stylex.create({
footer: {
@@ -90,7 +96,7 @@ export function CommandPaletteFooter({
style,
...props
}: CommandPaletteFooterProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
return (
<div
diff --git a/packages/core/src/CommandPalette/CommandPaletteInput.tsx b/packages/core/src/CommandPalette/CommandPaletteInput.tsx
index 6267a96563..080a354fab 100644
--- a/packages/core/src/CommandPalette/CommandPaletteInput.tsx
+++ b/packages/core/src/CommandPalette/CommandPaletteInput.tsx
@@ -38,10 +38,16 @@ import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
import {useInteractionModalityTracking} from '../utils/interactionModality';
-import {useTranslator} from '../i18n';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/CommandPalette/CommandPaletteInput.generated';
+
+registerEnglishFallback(english);
const styles = stylex.create({
wrapper: {
display: 'flex',
@@ -187,7 +193,7 @@ export function CommandPaletteInput({
style,
...props
}: CommandPaletteInputProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const placeholder =
placeholderFromProps ?? t('@astryx.commandPalette.input.placeholder');
const ctx = useCommandPaletteContext();
diff --git a/packages/core/src/CommandPalette/CommandPaletteList.tsx b/packages/core/src/CommandPalette/CommandPaletteList.tsx
index be3ba74c75..eb335986a9 100644
--- a/packages/core/src/CommandPalette/CommandPaletteList.tsx
+++ b/packages/core/src/CommandPalette/CommandPaletteList.tsx
@@ -20,7 +20,13 @@ import {mergeProps} from '../utils';
import {spacingVars} from '../theme/tokens.stylex';
import {useCommandPaletteContext} from './CommandPaletteContext';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/CommandPalette/CommandPaletteList.generated';
+
+registerEnglishFallback(english);
const styles = stylex.create({
list: {
@@ -83,7 +89,7 @@ export function CommandPaletteList({
style,
...props
}: CommandPaletteListProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const label = labelFromProps ?? t('@astryx.commandPalette.list.label');
const ctx = useCommandPaletteContext();
// Inside CommandPalette the list is a listbox only while it holds selectable
diff --git a/packages/core/src/DateInput/DateInput.tsx b/packages/core/src/DateInput/DateInput.tsx
index 1d040e2053..dbcad609f5 100644
--- a/packages/core/src/DateInput/DateInput.tsx
+++ b/packages/core/src/DateInput/DateInput.tsx
@@ -199,10 +199,17 @@ import {
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {useMergedRefs} from '../hooks/useMergedRefs';
import type {FieldStatusPlacement} from '../Field/fieldStatusPlacement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateInput/DateInput.generated';
+
+registerEnglishFallback(english);
export interface DateInputProps extends Omit<
FieldInputBaseProps<HTMLInputElement>,
'onChange' | 'defaultValue'
@@ -521,7 +528,7 @@ function PointerDateField({
onKeyDown: onKeyDownProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/DateInput/NativeDateField.tsx b/packages/core/src/DateInput/NativeDateField.tsx
index ed68702b93..0de2b5988f 100644
--- a/packages/core/src/DateInput/NativeDateField.tsx
+++ b/packages/core/src/DateInput/NativeDateField.tsx
@@ -53,7 +53,7 @@ import {useMediaQuery} from '../hooks/useMediaQuery';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {Icon} from '../Icon';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {useInputGroup} from '../InputGroup';
import {useFieldInputStyling} from '../Field/fieldParts';
import {joinAriaIDs} from '../utils/inputAria';
@@ -82,6 +82,13 @@ import {
type ISODateString,
} from '../utils';
import {chainEventHandlers} from '../utils/chainEventHandlers';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateInput/NativeDateField.generated';
+
+registerEnglishFallback(english);
const styles = stylex.create({
wrapper: {
@@ -297,7 +304,7 @@ export function NativeDateField({
onBlur: onBlurProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/DateInput/TouchDateField.tsx b/packages/core/src/DateInput/TouchDateField.tsx
index f0cc9a427e..772b6c92c3 100644
--- a/packages/core/src/DateInput/TouchDateField.tsx
+++ b/packages/core/src/DateInput/TouchDateField.tsx
@@ -77,7 +77,7 @@ import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {Icon} from '../Icon';
import {IconButton} from '../IconButton';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {useInputGroup} from '../InputGroup';
import {useFieldInputStyling} from '../Field/fieldParts';
import {joinAriaIDs} from '../utils/inputAria';
@@ -126,6 +126,13 @@ import {
monthIndexOf,
} from './monthGeometry';
import {dateInputTouchSizes, dateInputTouchGeometry} from './tokens.stylex';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateInput/TouchDateField.generated';
+
+registerEnglishFallback(english);
/**
* The comfortable minimum tap target on both iOS and Android, honoured by
@@ -599,7 +606,7 @@ export function TouchDateField({
...controlProps
} = rest;
const pressable = usePressFeedback();
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/DateRangeInput/DateRangeInput.tsx b/packages/core/src/DateRangeInput/DateRangeInput.tsx
index aac978255b..80021c5f8e 100644
--- a/packages/core/src/DateRangeInput/DateRangeInput.tsx
+++ b/packages/core/src/DateRangeInput/DateRangeInput.tsx
@@ -80,9 +80,16 @@ import {useMergedRefs} from '../hooks/useMergedRefs';
import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import type {Locale} from '../i18n/types';
import type {FieldStatusPlacement} from '../Field/fieldStatusPlacement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateRangeInput/DateRangeInput.generated';
+
+registerEnglishFallback(english);
export type {DateRange} from '../Calendar';
@@ -530,7 +537,7 @@ export function DateRangeInput({
onClick: onClickProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 546cb0ff0d..8474c7996f 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -99,7 +99,7 @@ import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {useSize} from '../SizeContext/SizeContext';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {
formatLocaleTime,
parseLocaleTime,
@@ -117,6 +117,13 @@ import {
type PickerPresentation,
} from '../utils/inputPresentation';
import {useDevWarning} from '../hooks/useDevWarning';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateTimeInput/DateTimeInput.generated';
+
+registerEnglishFallback(english);
export type ISODateTimeString = string & {
readonly __brand: 'ISODateTimeString';
};
@@ -657,7 +664,7 @@ function PointerDateTimeField({
onKeyDown: onKeyDownProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const usesNativePicker = nativeMode !== 'off';
// `forced` (`presentation="native"`, FR2): no Astryx fallback. `adaptive`
diff --git a/packages/core/src/DateTimeInput/NativeDateSegment.tsx b/packages/core/src/DateTimeInput/NativeDateSegment.tsx
index bee10c4879..7f11e15d78 100644
--- a/packages/core/src/DateTimeInput/NativeDateSegment.tsx
+++ b/packages/core/src/DateTimeInput/NativeDateSegment.tsx
@@ -33,7 +33,7 @@ import {hasEditableDateSegments} from '../DateInput/nativeDateSegments';
import {useMediaQuery} from '../hooks/useMediaQuery';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {Icon} from '../Icon';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {VisuallyHidden} from '../VisuallyHidden';
import {
focusOutlineStyles,
@@ -47,6 +47,13 @@ import {
import {chainEventHandlers} from '../utils/chainEventHandlers';
import type {InputStatusType} from '../Field';
import {nativePickerSegmentStyles as styles} from './nativePickerSegmentStyles';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateTimeInput/NativeDateSegment.generated';
+
+registerEnglishFallback(english);
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
@@ -100,7 +107,7 @@ export function NativeDateSegment({
onBlur: onBlurProp,
...inputProps
} = controlProps ?? {};
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isTouchPointer = useMediaQuery('(pointer: coarse)');
const internalInputRef = useRef<HTMLInputElement | null>(null);
diff --git a/packages/core/src/DateTimeInput/NativeTimeSegment.tsx b/packages/core/src/DateTimeInput/NativeTimeSegment.tsx
index 4344e49628..a0456fded3 100644
--- a/packages/core/src/DateTimeInput/NativeTimeSegment.tsx
+++ b/packages/core/src/DateTimeInput/NativeTimeSegment.tsx
@@ -34,7 +34,7 @@ import type {InputStatusType} from '../Field';
import {useMediaQuery} from '../hooks/useMediaQuery';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {Icon} from '../Icon';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {formatLocaleTime} from '../utils/timeFormat';
import type {ThemeProps} from '../utils/themeProps';
import {VisuallyHidden} from '../VisuallyHidden';
@@ -47,6 +47,13 @@ import {
} from '../utils';
import {chainEventHandlers} from '../utils/chainEventHandlers';
import {nativePickerSegmentStyles as styles} from './nativePickerSegmentStyles';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/DateTimeInput/NativeTimeSegment.generated';
+
+registerEnglishFallback(english);
const FRACTIONAL_SECONDS = /\.\d+$/;
@@ -124,7 +131,7 @@ export function NativeTimeSegment({
onBlur: onBlurProp,
...inputProps
} = controlProps ?? {};
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isTouchPointer = useMediaQuery('(pointer: coarse)');
const internalInputRef = useRef<HTMLInputElement | null>(null);
diff --git a/packages/core/src/DateTimeInput/TouchDateTimeField.tsx b/packages/core/src/DateTimeInput/TouchDateTimeField.tsx
index 69dac46bae..00c8248bb2 100644
--- a/packages/core/src/DateTimeInput/TouchDateTimeField.tsx
+++ b/packages/core/src/DateTimeInput/TouchDateTimeField.tsx
@@ -51,7 +51,6 @@ import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {Icon} from '../Icon';
import {IconButton} from '../IconButton';
-import {useTranslator, InternationalizationContext} from '../i18n';
import {SegmentedControl, SegmentedControlItem} from '../SegmentedControl';
import {useSize} from '../SizeContext/SizeContext';
import {Spinner} from '../Spinner';
@@ -109,6 +108,14 @@ import {
monthIndexOf,
} from '../DateInput/monthGeometry';
import type {DateTimeInputProps, ISODateTimeString} from './DateTimeInput';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import {InternationalizationContext} from '../i18n/InternationalizationContext';
+import english from '../i18n/generated-english/DateTimeInput/TouchDateTimeField.generated';
+
+registerEnglishFallback(english);
function splitDateTime(dt: ISODateTimeString | undefined): {
date: ISODateString | undefined;
@@ -493,7 +500,7 @@ export function TouchDateTimeField({
onKeyDown: onKeyDownProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const {locale} = use(InternationalizationContext);
const placeholder =
diff --git a/packages/core/src/PowerSearch/PowerSearch.tsx b/packages/core/src/PowerSearch/PowerSearch.tsx
index 932f7af6b8..55a7c57175 100644
--- a/packages/core/src/PowerSearch/PowerSearch.tsx
+++ b/packages/core/src/PowerSearch/PowerSearch.tsx
@@ -59,7 +59,6 @@ import {PowerSearchEditPopover} from './PowerSearchEditPopover';
import {resolveOperatorLabel} from './resolveOperatorLabel';
import {themeProps} from '../utils/themeProps';
import {truncateCharacters} from '../utils/characters';
-import {useTranslator} from '../i18n';
import {useLocale} from '../i18n/useLocale';
import type {Locale} from '../i18n/types';
import type {
@@ -78,6 +77,13 @@ import type {
import {useMergedRefs} from '../hooks/useMergedRefs';
import type {FieldStatusPlacement} from '../Field/fieldStatusPlacement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/PowerSearch/PowerSearch.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Icon mapping for typeahead entries
// =============================================================================
@@ -587,7 +593,7 @@ export function PowerSearch({
const size = useSize(sizeProp, 'md');
const config = useInternalConfig(configProp);
const searchSource = usePowerSearchSource(config, maxSearchResults);
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const label = labelFromProps ?? t('@astryx.powersearch.label');
const placeholder =
diff --git a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
index 156e7a87fd..124e0d1296 100644
--- a/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchEditPopover.tsx
@@ -19,7 +19,6 @@ import {Selector} from '../Selector';
import {HStack, VStack} from '../Stack';
import {Icon} from '../Icon';
import {TreeList, type TreeListItemData} from '../TreeList';
-import {useTranslator} from '../i18n';
import {isImeKeyEvent} from '../utils/ime';
import {spacingVars, typeScaleVars} from '../theme/tokens.stylex';
import {
@@ -35,6 +34,13 @@ import type {
OperatorValue,
PowerSearchOperator,
} from './types';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/PowerSearch/PowerSearchEditPopover.generated';
+
+registerEnglishFallback(english);
// Below the popover layer's 400px floor (see popoverLayerStyles in
// PowerSearch.tsx) the chip rows collapse from one line to wrapped lines.
@@ -264,7 +270,7 @@ function NestedSubFilterRow({
maxMenuItems,
isReadOnly,
}: NestedSubFilterRowProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const fieldOptions = useMemo(
() =>
config.getVisibleFields().map(field => ({
@@ -397,7 +403,7 @@ function NestedEditor({
maxMenuItems,
isReadOnly,
}: NestedEditorProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const [subFilters, setSubFilters] = useState<EditablePartialFilter[]>(() => {
if (partialFilter.value && partialFilter.value.type === 'nested') {
return partialFilter.value.value.map(f => initEditableFilter(config, f));
@@ -661,7 +667,7 @@ export function PowerSearchEditPopover({
maxMenuItems,
isReadOnly = false,
}: PowerSearchEditPopoverProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const saveButtonLabel =
saveButtonLabelFromProps ?? t('@astryx.powersearch.editor.apply');
const [partialFilter, setPartialFilter] =
diff --git a/packages/core/src/PowerSearch/PowerSearchToken.tsx b/packages/core/src/PowerSearch/PowerSearchToken.tsx
index cd55ba5a80..9d21dfd06d 100644
--- a/packages/core/src/PowerSearch/PowerSearchToken.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchToken.tsx
@@ -12,13 +12,13 @@
import React from 'react';
import * as stylex from '@stylexjs/stylex';
import {Token} from '../Token';
-import {useTranslator} from '../i18n';
import {useLocale} from '../i18n/useLocale';
import {fontWeightVars} from '../theme/tokens.stylex';
import {formatFilterValue} from './formatFilterValue';
import {resolveOperatorLabel} from './resolveOperatorLabel';
import {useInternalConfig} from './useInternalConfig';
import type {PowerSearchTokenProps} from './types';
+import {useComponentTranslator} from '../i18n/useComponentTranslator';
const tokenValueStyles = stylex.create({
value: {
@@ -44,7 +44,7 @@ export function PowerSearchToken({
isDisabled,
}: PowerSearchTokenProps) {
const config = useInternalConfig(configProp);
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const fieldLabel = field.label;
diff --git a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx
index 894c9ac713..55194a672e 100644
--- a/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx
+++ b/packages/core/src/PowerSearch/PowerSearchValueEditor.tsx
@@ -45,7 +45,14 @@ import {TimeInput} from '../TimeInput';
import {Selector} from '../Selector';
import {Tokenizer} from '../Tokenizer';
import {Typeahead} from '../Typeahead';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/PowerSearch/PowerSearchValueEditor.generated';
+
+registerEnglishFallback(english);
export interface PowerSearchValueEditorProps {
operatorValue: OperatorValue;
@@ -114,7 +121,7 @@ function StringEditor({
maxMenuItems?: number;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue = filterValue?.type === 'string' ? filterValue.value : '';
// When a searchSource is provided, render a typeahead instead of a plain
@@ -172,7 +179,7 @@ function StringListEditor({
maxMenuItems?: number;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue: SearchableItem[] = useMemo(() => {
if (filterValue?.type !== 'string_list') {
return [];
@@ -293,7 +300,7 @@ function IntegerEditor({
onEnter?: () => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'integer' ? filterValue.value : undefined;
const handlers = useNumberEditorHandlers({
@@ -338,7 +345,7 @@ function FloatEditor({
onEnter?: () => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'float' ? filterValue.value : undefined;
const handlers = useNumberEditorHandlers({
@@ -380,7 +387,7 @@ function TimeEditor({
onChange: (value: FilterValue) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'time'
? (filterValue.value as ISOTimeString)
@@ -413,7 +420,7 @@ function DateAbsoluteEditor({
onChange: (value: FilterValue) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
// Convert unixSeconds to ISO date string for the date input
const currentValue = useMemo(() => {
if (filterValue?.type !== 'date_absolute') {
@@ -450,7 +457,7 @@ function DateRelativeEditor({
onChange: (value: FilterValue, shouldSave?: boolean) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'date_relative' ? filterValue.value : undefined;
@@ -510,7 +517,7 @@ function DateRangeEditor({
onChange: (value: FilterValue) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue = useMemo<DateRange | null>(() => {
if (filterValue?.type !== 'date_range') {
return null;
@@ -578,7 +585,7 @@ function EnumEditor({
onChange: (value: FilterValue, shouldSave?: boolean) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'enum' ? filterValue.value : undefined;
@@ -616,7 +623,7 @@ function EnumListEditor({
onChange: (value: FilterValue) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const items = useMemo(
() => enumItemsToSearchableItems(operatorValue.values),
[operatorValue.values],
@@ -671,7 +678,7 @@ function EntityListEditor({
maxMenuItems?: number;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const source = useMemo<SearchSource<SearchableItem>>(() => {
if (operatorValue.searchSource) {
return operatorValue.searchSource;
@@ -734,7 +741,7 @@ function CustomEditor({
onChange: (value: FilterValue) => void;
isDisabled?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const currentValue =
filterValue?.type === 'custom' ? filterValue.value : null;
const EditorComponent = operatorValue.Editor;
diff --git a/packages/core/src/PowerSearch/resolveOperatorLabel.ts b/packages/core/src/PowerSearch/resolveOperatorLabel.ts
index 957b344120..d9f48ea5f7 100644
--- a/packages/core/src/PowerSearch/resolveOperatorLabel.ts
+++ b/packages/core/src/PowerSearch/resolveOperatorLabel.ts
@@ -15,14 +15,20 @@
* Astryx's shipped default operators use the i18nKey variant; consumers
* writing custom operators typically use the label variant.
*
+ * A custom operator may name any Astryx key in `i18nKey`, so this module
+ * registers the whole English catalog rather than only the keys Core names.
+ *
* SYNC: When modified, update:
* - /packages/core/src/PowerSearch/types.ts (PowerSearchOperator type)
* - /packages/core/src/PowerSearch/index.ts (re-export)
*/
-import type {TranslatorFn} from '../i18n';
+import type {TranslatorFn} from '../i18n/useTranslator';
+import {registerFullEnglishFallback} from '../i18n/fullEnglishFallback';
import type {PowerSearchOperator} from './types';
+registerFullEnglishFallback();
+
export function resolveOperatorLabel(
operator: PowerSearchOperator,
t: TranslatorFn,
diff --git a/packages/core/src/PowerSearch/usePowerSearchSource.ts b/packages/core/src/PowerSearch/usePowerSearchSource.ts
index df6b0d6d6d..de6e362097 100644
--- a/packages/core/src/PowerSearch/usePowerSearchSource.ts
+++ b/packages/core/src/PowerSearch/usePowerSearchSource.ts
@@ -15,10 +15,10 @@
import {useMemo} from 'react';
import type {SearchSource} from '../Typeahead/types';
import {groupItems} from '../utils';
-import {useTranslator} from '../i18n';
import {resolveOperatorLabel} from './resolveOperatorLabel';
import type {InternalConfig} from './useInternalConfig';
import type {PowerSearchItem, PowerSearchOperator, FilterValue} from './types';
+import {useComponentTranslator} from '../i18n/useComponentTranslator';
/**
* @param maxTypedResults Cap applied to ranked results for a non-empty query.
@@ -29,7 +29,7 @@ export function usePowerSearchSource(
config: InternalConfig,
maxTypedResults: number,
): SearchSource<PowerSearchItem> {
- const t = useTranslator();
+ const t = useComponentTranslator();
return useMemo(() => {
const allItems = buildFieldItems(config);
// Resolver stays inline — `t()` internally memoizes both catalog
diff --git a/packages/core/src/Table/BaseTable.tsx b/packages/core/src/Table/BaseTable.tsx
index f25939f60c..0152c40dfa 100644
--- a/packages/core/src/Table/BaseTable.tsx
+++ b/packages/core/src/Table/BaseTable.tsx
@@ -48,7 +48,13 @@ import {devError} from '../utils/devWarning';
import {EmptyState} from '../EmptyState';
import {Text} from '../Text';
import {themeProps} from '../utils/themeProps';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Table/BaseTable.generated';
+
+registerEnglishFallback(english);
const styles = stylex.create({
table: {
@@ -361,7 +367,7 @@ function BaseTableInner<T extends Record<string, unknown>>({
ref,
...rest
}: BaseTableProps<T> & {ref?: Ref<HTMLTableElement>}): ReactElement {
- const t = useTranslator();
+ const t = useComponentTranslator();
// Use stable empty array when no plugins provided
const plugins = pluginsProp ?? (EMPTY_PLUGINS as TablePlugin<T>[]);
diff --git a/packages/core/src/Table/Table.tsx b/packages/core/src/Table/Table.tsx
index d77d045ac8..a6f5ad67bc 100644
--- a/packages/core/src/Table/Table.tsx
+++ b/packages/core/src/Table/Table.tsx
@@ -33,7 +33,13 @@ import type {
TableRenderProps,
} from './types';
import type {StyleXStyles} from '../theme/types';
-import {useTranslator} from '../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Table/Table.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Table Types
@@ -161,7 +167,7 @@ function TableScrollWrapper({
beforeTable?: React.ReactNode;
afterTable?: React.ReactNode;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const tableName = use(TableNameContext);
// The focusable scroll region takes the table's own name (spec:AST-025
// FR12), so two tables are not two groups both named "Table". It is named
diff --git a/packages/core/src/Table/TableSelectionToolbar.tsx b/packages/core/src/Table/TableSelectionToolbar.tsx
index f884beb859..eb0af2a9b8 100644
--- a/packages/core/src/Table/TableSelectionToolbar.tsx
+++ b/packages/core/src/Table/TableSelectionToolbar.tsx
@@ -13,8 +13,14 @@ import type {ReactNode} from 'react';
import {Button} from '../Button';
import {Toolbar} from '../Toolbar';
import type {ToolbarProps} from '../Toolbar';
-import {useTranslator} from '../i18n';
import type {TableSelectionState} from './plugins/selection/useTableSelectionState';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/Table/TableSelectionToolbar.generated';
+
+registerEnglishFallback(english);
export interface TableSelectionToolbarProps extends Omit<
ToolbarProps,
@@ -45,7 +51,7 @@ export function TableSelectionToolbar({
variant = 'muted',
...toolbarProps
}: TableSelectionToolbarProps): ReactNode {
- const t = useTranslator();
+ const t = useComponentTranslator();
const label = labelFromProps ?? t('@astryx.table.selection.bulkActionsLabel');
const clearLabel =
clearLabelFromProps ?? t('@astryx.table.selection.clearAll');
diff --git a/packages/core/src/Table/plugins/columnResize/useTableColumnResize.tsx b/packages/core/src/Table/plugins/columnResize/useTableColumnResize.tsx
index 5d380c82fc..47b78f6872 100644
--- a/packages/core/src/Table/plugins/columnResize/useTableColumnResize.tsx
+++ b/packages/core/src/Table/plugins/columnResize/useTableColumnResize.tsx
@@ -30,7 +30,13 @@ import {
} from '../../columnUtils';
import {observeResize} from '../../../utils/sharedResizeObserver';
import {getNodeText} from '../../../utils/getNodeText';
-import {useTranslator} from '../../../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/columnResize/useTableColumnResize.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Config Type
@@ -386,7 +392,7 @@ function ResizeHandle({
isDraggingRef,
tableRef,
}: ResizeHandleProps) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const setTableDragging = useCallback(
(dragging: boolean) => {
const table = tableRef.current;
diff --git a/packages/core/src/Table/plugins/filtering/useTableFiltering.tsx b/packages/core/src/Table/plugins/filtering/useTableFiltering.tsx
index 92b652f9b8..b27ea3680d 100644
--- a/packages/core/src/Table/plugins/filtering/useTableFiltering.tsx
+++ b/packages/core/src/Table/plugins/filtering/useTableFiltering.tsx
@@ -49,7 +49,7 @@ import type {
HeaderCellRenderProps,
} from '../../types';
import {proportional} from '../../columnUtils';
-import {useLocale, useTranslator} from '../../../i18n';
+import {useLocale} from '../../../i18n';
import type {
PowerSearchConfig,
PowerSearchField,
@@ -64,6 +64,13 @@ import type {
StringListOperatorValue,
EntityListOperatorValue,
} from '../../../PowerSearch/types';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/filtering/useTableFiltering.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Filter Value Types
@@ -430,7 +437,7 @@ function TextFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const config = store.getConfig();
const value = config.filters[columnKey];
@@ -540,7 +547,7 @@ function NumberFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const config = store.getConfig();
const value = config.filters[columnKey];
@@ -615,7 +622,7 @@ function SelectorFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const config = store.getConfig();
const value = config.filters[columnKey];
@@ -679,7 +686,7 @@ function MultiSelectorFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const config = store.getConfig();
const value = config.filters[columnKey];
@@ -721,7 +728,7 @@ function DateFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const value = store.getConfig().filters[columnKey] as string | undefined;
@@ -750,7 +757,7 @@ function TimeFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const value = store.getConfig().filters[columnKey] as string | undefined;
@@ -781,7 +788,7 @@ function StringListFilterControl({
size: 'sm' | 'md';
hasClear?: boolean;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const value =
(store.getConfig().filters[columnKey] as string[] | undefined) ?? [];
@@ -923,7 +930,7 @@ function PopoverFilterTrigger({
header: string;
operatorValue: OperatorValue;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const store = useFilterStore();
const config = store.getConfig();
const value = config.filters[columnKey];
diff --git a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx
index 0d96ccfa42..ddd422689c 100644
--- a/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx
+++ b/packages/core/src/Table/plugins/groupedRows/useTableGroupedRows.tsx
@@ -21,7 +21,13 @@ import {
} from '../../../theme/tokens.stylex';
import {Icon} from '../../../Icon';
import type {TablePlugin} from '../../types';
-import {useTranslator} from '../../../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/groupedRows/useTableGroupedRows.generated';
+
+registerEnglishFallback(english);
// A synthetic group-header row injected into the flattened data. Real rows
// never carry this marker.
@@ -272,7 +278,7 @@ const styles = stylex.create({
export function useTableGroupedRows<T extends Record<string, unknown>>(
config: UseTableGroupedRowsConfig<T>,
): UseTableGroupedRowsResult<T> {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {
data,
groupBy,
diff --git a/packages/core/src/Table/plugins/pagination/useTablePagination.tsx b/packages/core/src/Table/plugins/pagination/useTablePagination.tsx
index fcc2994043..930d4ca0fa 100644
--- a/packages/core/src/Table/plugins/pagination/useTablePagination.tsx
+++ b/packages/core/src/Table/plugins/pagination/useTablePagination.tsx
@@ -22,7 +22,13 @@ import {spacingVars} from '../../../theme/tokens.stylex';
import {Pagination} from '../../../Pagination';
import type {PaginationProps} from '../../../Pagination';
import type {TablePlugin} from '../../types';
-import {useTranslator} from '../../../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/pagination/useTablePagination.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Styles
@@ -197,7 +203,7 @@ export interface UseTablePaginationConfig {
export function useTablePagination<T extends Record<string, unknown>>(
config: UseTablePaginationConfig,
): TablePlugin<T> {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {
page,
onPageChange,
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
index 3b31b162ce..0d0f76d2c8 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
@@ -5,7 +5,7 @@
/**
* @file useTableRowExpansion.tsx
* @input React, StyleX, Icon, Table types, table context (density), i18n
- * (useTranslator)
+ * (useComponentTranslator)
* @output Exports useTableRowExpansion hook + config type
* @position Row-expansion plugin (detail panel); consumed by Table via plugins prop
*
@@ -42,7 +42,6 @@ import {Icon} from '../../../Icon';
import {VisuallyHidden} from '../../../VisuallyHidden';
import {resolveContextActions} from '../../tableContextMenu';
import {useTableContext} from '../../useTableCellStyles';
-import {useTranslator} from '../../../i18n';
import {rtlStyles} from '../../../utils';
import {
hasInteractiveAncestor,
@@ -72,6 +71,13 @@ import {
rowEdge,
type BottomEdge,
} from '../../glidingDivider';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/rowExpansion/useTableRowExpansion.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Config
@@ -345,7 +351,7 @@ function ExpansionChevron({
isExpanded: boolean;
onToggle: () => void;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const ctx = useTableContext();
return (
<button
@@ -595,7 +601,7 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
animatedLayout,
} = config;
- const t = useTranslator();
+ const t = useComponentTranslator();
// Final rendered column count, captured in transformColumns (pipeline step
// 1) and read in transformBodyRow for the detail panel's colSpan.
diff --git a/packages/core/src/Table/plugins/rowStatus/useTableRowStatus.tsx b/packages/core/src/Table/plugins/rowStatus/useTableRowStatus.tsx
index a62a4d6ebc..14c3e76fd4 100644
--- a/packages/core/src/Table/plugins/rowStatus/useTableRowStatus.tsx
+++ b/packages/core/src/Table/plugins/rowStatus/useTableRowStatus.tsx
@@ -20,11 +20,17 @@ import {useMemo} from 'react';
import * as stylex from '@stylexjs/stylex';
import {Icon, type IconColor, type IconName} from '../../../Icon';
import {Tooltip} from '../../../Tooltip';
-import {useTranslator} from '../../../i18n';
import {warnOnce} from '../../../utils/devWarning';
import {VisuallyHidden} from '../../../VisuallyHidden';
import type {TableRowStatus, TableSemanticRowStatus} from '../../index';
import type {TableColumn, TablePlugin} from '../../types';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/rowStatus/useTableRowStatus.generated';
+
+registerEnglishFallback(english);
/**
* Named colors supported by the custom row-status marker. These resolve to the
@@ -201,7 +207,7 @@ const styles = stylex.create({
export function useTableRowStatus<T extends Record<string, unknown>>(
config: UseTableRowStatusConfig<T>,
): TablePlugin<T> {
- const t = useTranslator();
+ const t = useComponentTranslator();
const {getStatus} = config;
return useMemo((): TablePlugin<T> => {
diff --git a/packages/core/src/Table/plugins/selection/useTableSelection.tsx b/packages/core/src/Table/plugins/selection/useTableSelection.tsx
index f628763e2c..b92dcf8fc5 100644
--- a/packages/core/src/Table/plugins/selection/useTableSelection.tsx
+++ b/packages/core/src/Table/plugins/selection/useTableSelection.tsx
@@ -53,7 +53,13 @@ import {CheckboxInput} from '../../../CheckboxInput';
import {mergeRefs} from '../../../utils';
import type {TablePlugin, TableColumn, BodyRowRenderProps} from '../../types';
import {pixel} from '../../columnUtils';
-import {useTranslator} from '../../../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/selection/useTableSelection.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Config Type
@@ -235,7 +241,7 @@ function SelectAllCheckboxInner<T extends Record<string, unknown>>({
}: {
store: SelectionStore<T>;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const getSnapshot = useCallback(() => {
const config = store.getConfig();
const allSelected = config.getIsAllSelected();
@@ -287,7 +293,7 @@ function SelectionCellContentInner<T extends Record<string, unknown>>({
store: SelectionStore<T>;
item: T;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const config = store.getConfig();
const isSelected = useIsItemSelected(store, item);
const selectable = config.getIsItemSelectable?.(item) ?? true;
diff --git a/packages/core/src/Table/plugins/sortable/useTableSortable.tsx b/packages/core/src/Table/plugins/sortable/useTableSortable.tsx
index 3c4547dd99..ca23e27e8f 100644
--- a/packages/core/src/Table/plugins/sortable/useTableSortable.tsx
+++ b/packages/core/src/Table/plugins/sortable/useTableSortable.tsx
@@ -4,7 +4,7 @@
/**
* @file useTableSortable.tsx
- * @input React, types, Icon, theme tokens, i18n (useTranslator)
+ * @input React, types, Icon, theme tokens, i18n (useComponentTranslator)
* @output Exports useTableSortable hook and sort-related types
* @position Sortable plugin; consumed by Table via plugins prop
*
@@ -19,13 +19,19 @@ import {colorVars, spacingVars, radiusVars} from '../../../theme/tokens.stylex';
import {focusOutlineProps} from '../../../utils/focusOutline.stylex';
import {Icon} from '../../../Icon';
import {resolveContextActions} from '../../tableContextMenu';
-import {useTranslator} from '../../../i18n';
import type {
TablePlugin,
HeaderCellRenderProps,
TableColumn,
TableContextAction,
} from '../../types';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/sortable/useTableSortable.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Sort Types
@@ -210,7 +216,7 @@ function SortHeaderButton<T extends Record<string, unknown>>({
children: ReactNode;
configRef: React.RefObject<UseTableSortableConfig>;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const config = configRef.current;
const sortKey = resolveSortKey(column) ?? '';
const entryIndex = config.sort.findIndex(e => e.sortKey === sortKey);
@@ -351,7 +357,7 @@ export function useTableSortable<
T extends Record<string, unknown>,
TSortKey extends string = string,
>(config: UseTableSortableConfig<TSortKey>): TablePlugin<T> {
- const t = useTranslator();
+ const t = useComponentTranslator();
const configRef = useRef(config);
configRef.current = config;
diff --git a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx b/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
index c23d5e5f0f..21b67b100b 100644
--- a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
+++ b/packages/core/src/Table/plugins/tree/useTableTreeData.tsx
@@ -4,7 +4,7 @@
/**
* @file useTableTreeData.tsx
- * @input React, StyleX, Icon, Table types, theme tokens, i18n (useTranslator)
+ * @input React, StyleX, Icon, Table types, theme tokens, i18n (useComponentTranslator)
* @output Exports useTableTreeData hook + config/meta types
* @position Tree plugin; consumed by Table via plugins prop.
* Pairs with useTableTreeState (owns expansion state + flattening).
@@ -53,7 +53,13 @@ import type {
BodyRowRenderProps,
HeaderCellRenderProps,
} from '../../types';
-import {useTranslator} from '../../../i18n';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../../../i18n/useComponentTranslator';
+import english from '../../../i18n/generated-english/Table/plugins/tree/useTableTreeData.generated';
+
+registerEnglishFallback(english);
// =============================================================================
// Types
@@ -322,7 +328,7 @@ function TreeExpander({
isExpanded: boolean;
onToggle: () => void;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
return (
<button
type="button"
@@ -370,7 +376,7 @@ function TreeExpandAllToggle({
onExpandAll: () => void;
onCollapseAll: () => void;
}) {
- const t = useTranslator();
+ const t = useComponentTranslator();
const allExpanded = isAllExpanded === true;
return (
<button
diff --git a/packages/core/src/TimeInput/TimeInput.tsx b/packages/core/src/TimeInput/TimeInput.tsx
index ac85d43132..1ba2ead139 100644
--- a/packages/core/src/TimeInput/TimeInput.tsx
+++ b/packages/core/src/TimeInput/TimeInput.tsx
@@ -78,7 +78,7 @@ import {InputGroupInternalContext} from '../InputGroup/InputGroupInternalContext
import {groupStyles, inputGroupItemProps} from '../InputGroup/groupStyles';
import {useTooltip} from '../Tooltip';
import {themeProps} from '../utils/themeProps';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {
formatLocaleTime,
parseLocaleTime,
@@ -95,6 +95,13 @@ import {
} from '../utils/inputPresentation';
import {useDevWarning} from '../hooks/useDevWarning';
import type {FieldStatusPlacement} from '../Field/fieldStatusPlacement';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/TimeInput/TimeInput.generated';
+
+registerEnglishFallback(english);
const TOUCH_POINTER_QUERY = '(pointer: coarse)';
@@ -443,7 +450,7 @@ function TimeField({
onKeyDown: onKeyDownProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/TimeInput/TouchTimeField.tsx b/packages/core/src/TimeInput/TouchTimeField.tsx
index 0c120430a5..ea6e970a0b 100644
--- a/packages/core/src/TimeInput/TouchTimeField.tsx
+++ b/packages/core/src/TimeInput/TouchTimeField.tsx
@@ -47,7 +47,7 @@ import {useBusyAnnouncement} from '../hooks/useBusyAnnouncement';
import {useMergedRefs} from '../hooks/useMergedRefs';
import {useResolvedRequired} from '../hooks/useResolvedRequired';
import {Icon} from '../Icon';
-import {useLocale, useTranslator} from '../i18n';
+import {useLocale} from '../i18n';
import {formatLocaleTime} from '../utils/timeFormat';
import {sizeVars, spacingVars} from '../theme/tokens.stylex';
import {useSize} from '../SizeContext/SizeContext';
@@ -68,6 +68,13 @@ import {
} from '../utils';
import {chainEventHandlers} from '../utils/chainEventHandlers';
import type {TimeInputProps} from './TimeInput';
+import {
+ registerEnglishFallback,
+ useComponentTranslator,
+} from '../i18n/useComponentTranslator';
+import english from '../i18n/generated-english/TimeInput/TouchTimeField.generated';
+
+registerEnglishFallback(english);
const sizeStyles = stylex.create({
sm: {height: sizeVars['--size-element-sm'], minWidth: 120},
@@ -226,7 +233,7 @@ export function TouchTimeField({
onClick: onClickProp,
...controlProps
} = rest;
- const t = useTranslator();
+ const t = useComponentTranslator();
const locale = useLocale();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const placeholder =
diff --git a/packages/core/src/i18n/fullEnglishFallback.ts b/packages/core/src/i18n/fullEnglishFallback.ts
index 38f00ef62d..31f4b68f43 100644
--- a/packages/core/src/i18n/fullEnglishFallback.ts
+++ b/packages/core/src/i18n/fullEnglishFallback.ts
@@ -7,8 +7,8 @@
* @position The only Core module that imports the whole English catalog.
*
* Called at module scope by the public paths that resolve arbitrary Astryx
- * keys: the public `useTranslator` and the public `InternationalizationContext`
- * export.
+ * keys: the public `useTranslator`, the public `InternationalizationContext`
+ * export, and PowerSearch operator labels, whose `i18nKey` callers supply.
* Component modules register only their own keys (englishFallback.ts).
* scripts/i18n-english-fallback.mjs rejects any other caller.
*
diff --git a/scripts/i18n-english-fallback.mjs b/scripts/i18n-english-fallback.mjs
index 9f64afbc39..37f503cea9 100644
--- a/scripts/i18n-english-fallback.mjs
+++ b/scripts/i18n-english-fallback.mjs
@@ -20,11 +20,11 @@
* key resolves wherever the module that names it is loaded, including a key a
* helper module looks up with a translator another module created.
*
- * Public paths that resolve any Astryx key (the public `useTranslator` and
- * the public context export) register the whole catalog through
- * `registerFullEnglishFallback()`. Only the modules in FULL_FALLBACK_MODULES
- * may do that. A Core module that names keys and has not moved to its own map
- * still uses the public `useTranslator`, so it carries the whole catalog.
+ * Public paths that resolve any Astryx key (the public `useTranslator`, the
+ * public context export, and operator labels whose keys callers supply)
+ * register the whole catalog through `registerFullEnglishFallback()`. Only the
+ * modules in FULL_FALLBACK_MODULES may do that, and no other Core module may
+ * import the public `useTranslator` or the public context export.
*
* A key reference is any string literal in a module that equals a catalog key.
* That is wider than the translator call sites check-i18n-catalog verifies, so
@@ -62,6 +62,8 @@ export const FULL_FALLBACK_MODULES = Object.freeze([
'i18n/useTranslator.ts',
// The public context export: application code may read `translate` from it.
'i18n/publicContext.ts',
+ // A caller-defined PowerSearch operator may name any Astryx key in `i18nKey`.
+ 'PowerSearch/resolveOperatorLabel.ts',
]);
/**
@@ -183,9 +185,12 @@ const SLICE_IMPORT_PATTERN = new RegExp(
);
const FULL_CATALOG_IMPORT_PATTERN = /generated-locales\/en\.generated['"]/;
const FULL_FALLBACK_CALL_PATTERN = /^registerFullEnglishFallback\(\);$/m;
-// A value import of the public hook, from the i18n barrel or its module.
+// A value import of the public hook or the public context export, from the
+// i18n barrel or their modules. Both carry the whole catalog.
const PUBLIC_TRANSLATOR_IMPORT_PATTERN =
/^import\s*\{[^}]*\buseTranslator\b[^}]*\}\s*from\s*'(?:\.\.?\/)+i18n(?:\/index|\/useTranslator)?';/m;
+const PUBLIC_CONTEXT_IMPORT_PATTERN =
+ /^import\s*\{[^}]*\bInternationalizationContext\b[^}]*\}\s*from\s*'(?:\.\.?\/)+i18n(?:\/index|\/publicContext)?';/m;
/**
* Wiring problems: a module that names keys without importing and registering
@@ -198,22 +203,26 @@ export function findWiringProblems(slices, srcDir = CORE_SRC_DIR) {
const text = fs.readFileSync(path.join(srcDir, rel), 'utf8');
const imports = [...text.matchAll(SLICE_IMPORT_PATTERN)];
const expected = getSliceImportSpecifier(rel);
- const usesPublicTranslator = PUBLIC_TRANSLATOR_IMPORT_PATTERN.test(text);
+ if (!rel.startsWith('i18n/')) {
+ if (PUBLIC_TRANSLATOR_IMPORT_PATTERN.test(text)) {
+ problems.push(
+ `${rel}: imports the public useTranslator, which carries the whole ` +
+ `catalog; use useComponentTranslator`,
+ );
+ }
+ if (PUBLIC_CONTEXT_IMPORT_PATTERN.test(text)) {
+ problems.push(
+ `${rel}: imports the public InternationalizationContext export, which ` +
+ `carries the whole catalog; import i18n/InternationalizationContext`,
+ );
+ }
+ }
if (slices.has(rel)) {
const own = imports.find(([, , specifier]) => specifier === expected);
if (own === undefined) {
- // A module not yet moved to its own map still resolves its keys
- // through the public hook, which registers the whole catalog.
- if (!usesPublicTranslator) {
- problems.push(
- `${rel}: names catalog keys but does not import its English fallback ` +
- `(import english from '${expected}';)`,
- );
- }
- } else if (usesPublicTranslator) {
problems.push(
- `${rel}: registers its English fallback but also imports the public ` +
- `useTranslator, which carries the whole catalog; use useComponentTranslator`,
+ `${rel}: names catalog keys but does not import its English fallback ` +
+ `(import english from '${expected}';)`,
);
} else if (
!new RegExp(
diff --git a/scripts/i18n-english-fallback.test.mjs b/scripts/i18n-english-fallback.test.mjs
index ba82b2159f..bfcacf1535 100644
--- a/scripts/i18n-english-fallback.test.mjs
+++ b/scripts/i18n-english-fallback.test.mjs
@@ -56,6 +56,7 @@ afterEach(() => {
const FULL_FALLBACK_FILES = {
'i18n/useTranslator.ts': 'registerFullEnglishFallback();\n',
'i18n/publicContext.ts': 'registerFullEnglishFallback();\n',
+ 'PowerSearch/resolveOperatorLabel.ts': 'registerFullEnglishFallback();\n',
};
describe('collectCatalogKeys', () => {
@@ -180,7 +181,7 @@ describe('findWiringProblems', () => {
]);
});
- it('accepts a module that still resolves its keys through the public useTranslator', () => {
+ it('rejects a Core module that imports the public useTranslator or context export', () => {
const dir = fixture({
...FULL_FALLBACK_FILES,
'Table/Table.tsx': [
@@ -188,21 +189,24 @@ describe('findWiringProblems', () => {
`t('@astryx.pagination.next');`,
'',
].join('\n'),
- });
- expect(
- findWiringProblems(collectEnglishFallbackSlices(CATALOG, dir), dir),
- ).toEqual([]);
- });
-
- it('rejects a module that registers its map but also imports the public useTranslator', () => {
- const dir = fixture({
- ...FULL_FALLBACK_FILES,
'Button/Button.tsx': `import {useTranslator} from '../i18n/useTranslator';\n${WIRED}`,
+ 'Link/Link.tsx': `import {InternationalizationContext} from '../i18n';\n`,
});
expect(
findWiringProblems(collectEnglishFallbackSlices(CATALOG, dir), dir),
).toEqual([
- expect.stringMatching(/^Button\/Button\.tsx: .*also imports the public/),
+ expect.stringMatching(
+ /^Button\/Button\.tsx: imports the public useTranslator/,
+ ),
+ expect.stringMatching(
+ /^Link\/Link\.tsx: imports the public InternationalizationContext/,
+ ),
+ expect.stringMatching(
+ /^Table\/Table\.tsx: imports the public useTranslator/,
+ ),
+ expect.stringMatching(
+ /^Table\/Table\.tsx: .*does not import its English/,
+ ),
]);
});
@@ -241,7 +245,14 @@ describe('import cost', () => {
it('bundles only the English a component names, not the whole catalog', () => {
const keys = loadCatalogKeys();
expect(keys.length).toBeGreaterThan(100);
- for (const name of ['Button', 'TreeList', 'SideNav', 'Selector']) {
+ for (const name of [
+ 'Button',
+ 'TreeList',
+ 'SideNav',
+ 'Selector',
+ 'Table',
+ 'DateInput',
+ ]) {
const text = bundleImport(path.join(CORE_DIST, name, `${name}.js`));
expect(text, name).not.toBeNull();
const bundled = catalogKeysIn(text, keys);