Skip to content

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

TypeScript

fix(core): localize remaining hardcoded assistive-tech strings (#4376)

Baraa Hamodibdc7cdee6d17
diff --git a/.changeset/a11y-i18n-at-strings.md b/.changeset/a11y-i18n-at-strings.md
new file mode 100644
index 0000000000..430346ce15
--- /dev/null
+++ b/.changeset/a11y-i18n-at-strings.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] i18n: localize remaining hardcoded assistive-tech strings (AvatarGroup overflow label, CodeBlock copy announcement, Button loading announcement, MetadataList show more/less, Table row-expansion context-menu actions, keyboard hint)
+@bhamodi
diff --git a/packages/core/locales/en.json b/packages/core/locales/en.json
index 4a3db3afd6..ac7f9c2610 100644
--- a/packages/core/locales/en.json
+++ b/packages/core/locales/en.json
@@ -247,6 +247,10 @@
"defaultMessage": "Use arrow keys to move between avatars",
"description": "Screen-reader-only instruction attached (via aria-describedby) to a group of interactive avatars that share a single Tab stop. Tells keyboard users the Left/Right arrow keys move focus between the avatars. Only announced when the group has interactive (link/button) avatars."
},
+ "@astryx.avatarGroup.overflow": {
+ "defaultMessage": "{count, number} more",
+ "description": "Accessible name for the \"+N\" overflow indicator at the end of an AvatarGroup — announces how many additional avatars are not shown. Example: `5 more`. The visible \"+N\" text is unaffected; this is the aria-label only."
+ },
"@astryx.banner.dismiss": {
"defaultMessage": "Dismiss",
"description": "\"Dismiss\" = close/hide this notification (not \"reject a person\"). Aria label AND tooltip on the small X button on a Banner."
@@ -687,6 +691,10 @@
"defaultMessage": "Expand",
"description": "\"Expand\" = reveal more, not grow physically. Aria label AND tooltip on the same toggle when currently collapsed. Pairs with `banner.collapse`."
},
+ "@astryx.button.loading": {
+ "defaultMessage": "Loading",
+ "description": "Screen-reader-only live-region announcement while a Button is in its loading state (spinner shown, action in flight). Progressive sense (\"work in progress\"), not a noun. Kept separate from `typeahead.loading` — translations may diverge."
+ },
"@astryx.chatComposerDrawer.expand": {
"defaultMessage": "Expand {label}",
"description": "Screen-reader-only label on the ChatComposerDrawer toggle when the drawer is collapsed. `{label}` is the drawer's visible name — example: `Expand Attachments`. Pairs with `collapse`."
@@ -763,10 +771,22 @@
"defaultMessage": "{label}, {fileNames}",
"description": "Accessible name for a FileInput trigger that has files attached, composing the field label with the selected filenames. Example: `Attachments, report.pdf, notes.txt`."
},
+ "@astryx.keyboardHint.toNavigate": {
+ "defaultMessage": "to navigate",
+ "description": "Trailing text in the keyboard-hint badge, shown after arrow-key icons — reads as `← → to navigate`. Lowercase sentence fragment completing the visual phrase; the badge is aria-hidden, so this is for sighted users only."
+ },
"@astryx.lightbox.mediaViewer": {
"defaultMessage": "Media viewer",
"description": "Screen-reader-only fallback name for the Lightbox dialog when the current media item has no alt text. Should rarely render — consumers should provide alt."
},
+ "@astryx.metadataList.showMore": {
+ "defaultMessage": "Show more",
+ "description": "Button label under a MetadataList that reveals items hidden beyond the configured maximum. Toggles with `metadataList.showLess` — keep the pair parallel in your language."
+ },
+ "@astryx.metadataList.showLess": {
+ "defaultMessage": "Show less",
+ "description": "Button label under a MetadataList that re-hides the extra items revealed by `metadataList.showMore`. Keep the pair parallel."
+ },
"@astryx.mobileNav.navigation": {
"defaultMessage": "Navigation",
"description": "Screen-reader-only fallback name for the MobileNav overlay dialog when no explicit label was passed."
diff --git a/packages/core/src/AvatarGroup/AvatarGroup.test.tsx b/packages/core/src/AvatarGroup/AvatarGroup.test.tsx
index 9162e26a37..e578895b22 100644
--- a/packages/core/src/AvatarGroup/AvatarGroup.test.tsx
+++ b/packages/core/src/AvatarGroup/AvatarGroup.test.tsx
@@ -5,6 +5,7 @@ import userEvent from '@testing-library/user-event';
import {AvatarGroup} from './AvatarGroup';
import {AvatarGroupOverflow} from './AvatarGroupOverflow';
import {Avatar, AvatarStatusDot} from '../Avatar';
+import {InternationalizationProvider} from '../i18n';
describe('AvatarGroup', () => {
it('renders all avatar children', () => {
@@ -238,7 +239,26 @@ describe('AvatarGroupOverflow — hardening', () => {
);
expect(screen.getByText('+4912')).toBeInTheDocument();
- expect(screen.getByLabelText('4912 more')).toBeInTheDocument();
+ // The aria-label routes through the catalog's `{count, number}` ICU
+ // argument, so the en locale adds a grouping separator.
+ expect(screen.getByLabelText('4,912 more')).toBeInTheDocument();
+ });
+
+ it('localizes the overflow label through the i18n catalog', () => {
+ render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{
+ fr: {'@astryx.avatarGroup.overflow': '{count, number} de plus'},
+ }}>
+ <AvatarGroup>
+ <Avatar name="Alice" />
+ <AvatarGroupOverflow count={3} />
+ </AvatarGroup>
+ </InternationalizationProvider>,
+ );
+
+ expect(screen.getByLabelText('3 de plus')).toBeInTheDocument();
});
});
diff --git a/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx b/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
index 920eaf7abe..ea57e106b9 100644
--- a/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
+++ b/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
@@ -3,7 +3,7 @@
/**
* @file AvatarGroupOverflow.tsx
- * @input Uses React, StyleX, AvatarGroupContext
+ * @input Uses React, StyleX, AvatarGroupContext, i18n (useTranslator)
* @output Exports AvatarGroupOverflow for overflow indicator
* @position Slot component used inside AvatarGroup
*
@@ -26,6 +26,7 @@ import {mergeProps} from '../utils';
import {useAvatarGroup} from './AvatarGroupContext';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
+import {useTranslator} from '../i18n';
const BORDER_WIDTH = 2;
const OVERFLOW_FONT_RATIO = 0.35;
@@ -150,11 +151,12 @@ export function AvatarGroupOverflow({
style,
...rest
}: AvatarGroupOverflowProps): ReactNode {
+ const t = useTranslator();
const group = useAvatarGroup();
const numericSize = group?.numericSize ?? 36;
const overlap = group?.overlap ?? 0;
- const label = `${count} more`;
+ const label = t('@astryx.avatarGroup.overflow', {count});
const content = children ?? `+${count}`;
if (onClick) {
diff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsx
index 7f02e2c50a..c4a1a1ea78 100644
--- a/packages/core/src/Button/Button.test.tsx
+++ b/packages/core/src/Button/Button.test.tsx
@@ -14,6 +14,7 @@ import {render, screen, fireEvent, act} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {Button} from './Button';
import {Badge} from '../Badge/Badge';
+import {InternationalizationProvider} from '../i18n';
describe('Button', () => {
it('renders label as visible text', () => {
@@ -446,6 +447,21 @@ describe('Button', () => {
expect(liveRegion).toHaveTextContent('Loading');
});
+ it('localizes the loading announcement through the i18n catalog', () => {
+ render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{fr: {'@astryx.button.loading': 'Chargement'}}}>
+ <Button label="Submit" isLoading />
+ </InternationalizationProvider>,
+ );
+ const button = screen.getByRole('button');
+ // The Spinner also has role="status", so grab the live region explicitly.
+ const regions = button.querySelectorAll('[role="status"]');
+ const liveRegion = regions[regions.length - 1];
+ expect(liveRegion).toHaveTextContent('Chargement');
+ });
+
describe('elevation', () => {
it('renders a distinct class for each elevation level', () => {
const classFor = (elevation: 'none' | 'low' | 'med' | 'high') => {
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index a8d185c1e8..b492e28783 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -4,7 +4,7 @@
/**
* @file Button.tsx
- * @input Uses React, ButtonHTMLAttributes, ReactNode
+ * @input Uses React, ButtonHTMLAttributes, ReactNode, i18n (useTranslator)
* @output Exports Button component, ButtonProps, ButtonVariant types
* @position Core implementation; consumed by index.ts, tested by Button.test.tsx
*
@@ -45,6 +45,7 @@ import {mergeProps, mergeRefs} from '../utils';
import {useLinkComponent} from '../Link/useLinkComponent';
import type {LinkComponentType} from '../Link/types';
import {themeProps} from '../utils/themeProps';
+import {useTranslator} from '../i18n';
/**
* Base button styles
@@ -611,6 +612,7 @@ export function Button({
ref,
...props
}: ButtonProps): ReactNode {
+ const t = useTranslator();
const size = useSize(sizeProp, 'md');
const buttonGroup = useButtonGroup();
@@ -760,7 +762,7 @@ export function Button({
</span>
{/* Live region for loading state announcements */}
<VisuallyHidden role="status" aria-live="polite">
- {isLoadingState ? 'Loading' : ''}
+ {isLoadingState ? t('@astryx.button.loading') : ''}
</VisuallyHidden>
</>
);
diff --git a/packages/core/src/CodeBlock/CodeBlock.test.tsx b/packages/core/src/CodeBlock/CodeBlock.test.tsx
index 9b14562f44..0f8e0027d3 100644
--- a/packages/core/src/CodeBlock/CodeBlock.test.tsx
+++ b/packages/core/src/CodeBlock/CodeBlock.test.tsx
@@ -14,6 +14,7 @@ import {act, render, screen, fireEvent, waitFor} from '@testing-library/react';
import {CodeBlock} from './CodeBlock';
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
import {dracula} from '../theme/syntax';
+import {InternationalizationProvider} from '../i18n';
function politeRegion(): HTMLElement | null {
return document.querySelector('[data-astryx-live-region="polite"]');
@@ -72,6 +73,22 @@ describe('CodeBlock', () => {
});
});
+ it('localizes the copy announcement through the i18n catalog', async () => {
+ render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{fr: {'@astryx.codeBlock.copied': 'Copié'}}}>
+ <CodeBlock code="const x = 1;" language="javascript" />
+ </InternationalizationProvider>,
+ );
+ // The button label and the live-region announcement share the same key.
+ fireEvent.click(screen.getByRole('button', {name: 'Copy code'}));
+ await waitFor(() => {
+ expect(politeRegion()).toHaveTextContent('Copié');
+ });
+ expect(screen.getByRole('button', {name: 'Copié'})).toBeInTheDocument();
+ });
+
it('keeps the copied indicator a full 2s after a rapid re-copy', async () => {
vi.useFakeTimers();
try {
diff --git a/packages/core/src/CodeBlock/CodeBlock.tsx b/packages/core/src/CodeBlock/CodeBlock.tsx
index a3f4e96e12..8d6ab69b78 100644
--- a/packages/core/src/CodeBlock/CodeBlock.tsx
+++ b/packages/core/src/CodeBlock/CodeBlock.tsx
@@ -786,7 +786,7 @@ export function CodeBlock({
setCopied(true);
// Swapping the button's aria-label alone isn't reliably announced by
// screen readers, so confirm the copy via a polite live region.
- announce('Copied');
+ announce(t('@astryx.codeBlock.copied'));
onCopy?.();
// Restart the reset timer on every copy — otherwise a rapid re-copy
// is reverted early by the previous click's timer.
@@ -800,7 +800,7 @@ export function CodeBlock({
} catch {
// Clipboard failures leave the copied state unchanged.
}
- }, [code, onCopy, announce]);
+ }, [code, onCopy, announce, t]);
const sizeStyle = size === 'sm' ? styles.sizeSm : styles.sizeMd;
// Digits in the largest line number — sizes the gutter column width.
diff --git a/packages/core/src/MetadataList/MetadataList.test.tsx b/packages/core/src/MetadataList/MetadataList.test.tsx
index 2d8b545df9..c2c23e6fc6 100644
--- a/packages/core/src/MetadataList/MetadataList.test.tsx
+++ b/packages/core/src/MetadataList/MetadataList.test.tsx
@@ -5,6 +5,7 @@ import {render, screen} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {MetadataList} from './MetadataList';
import {MetadataListItem} from './MetadataListItem';
+import {InternationalizationProvider} from '../i18n';
describe('MetadataList', () => {
it('renders a description list with items', () => {
@@ -87,6 +88,29 @@ describe('MetadataList', () => {
expect(screen.queryByText('B')).not.toBeInTheDocument();
});
+ it('localizes the show more / show less labels through the i18n catalog', async () => {
+ const user = userEvent.setup();
+
+ render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{
+ fr: {
+ '@astryx.metadataList.showMore': 'Afficher plus',
+ '@astryx.metadataList.showLess': 'Afficher moins',
+ },
+ }}>
+ <MetadataList maxNumOfItems={1}>
+ <MetadataListItem label="A">1</MetadataListItem>
+ <MetadataListItem label="B">2</MetadataListItem>
+ </MetadataList>
+ </InternationalizationProvider>,
+ );
+
+ await user.click(screen.getByText('Afficher plus'));
+ expect(screen.getByText('Afficher moins')).toBeInTheDocument();
+ });
+
it('does not show toggle in horizontal mode even with maxNumOfItems', () => {
render(
<MetadataList orientation="horizontal" maxNumOfItems={1}>
diff --git a/packages/core/src/MetadataList/MetadataList.tsx b/packages/core/src/MetadataList/MetadataList.tsx
index 2040dc22c4..49b66d610b 100644
--- a/packages/core/src/MetadataList/MetadataList.tsx
+++ b/packages/core/src/MetadataList/MetadataList.tsx
@@ -4,7 +4,7 @@
/**
* @file MetadataList.tsx
- * @input Uses React, ReactNode, StyleXStyles, theme tokens, MetadataListContext
+ * @input Uses React, ReactNode, StyleXStyles, theme tokens, MetadataListContext, i18n (useTranslator)
* @output Exports MetadataList component, MetadataListProps, MetadataListColumns types
* @position Core implementation; consumed by index.ts, tested by MetadataList.test.tsx
*
@@ -31,6 +31,7 @@ import {
import type {BaseProps} from '../BaseProps';
import {mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
+import {useTranslator} from '../i18n';
// =============================================================================
// Types
@@ -197,6 +198,7 @@ export function MetadataList({
const labelConfig = label ?? (isMultiColumn ? LABEL_TOP : LABEL_START);
const [isShowAll, setIsShowAll] = useState(false);
const contentId = useId();
+ const t = useTranslator();
const contextValue = useMemo(
() => ({
@@ -283,7 +285,9 @@ export function MetadataList({
aria-expanded={isShowAll}
onClick={() => setIsShowAll(prev => !prev)}
{...stylex.props(styles.toggleButton)}>
- {isShowAll ? 'Show less' : 'Show more'}
+ {isShowAll
+ ? t('@astryx.metadataList.showLess')
+ : t('@astryx.metadataList.showMore')}
</button>
)}
</div>
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
index 7c4b707f7f..2c040a8e28 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.test.tsx
@@ -9,6 +9,7 @@ import {
useTableRowExpansion,
useTableRowExpansionState,
} from './useTableRowExpansion';
+import {InternationalizationProvider} from '../../../i18n';
// popover mock for context-menu tests
beforeEach(() => {
@@ -118,6 +119,24 @@ describe('useTableRowExpansion', () => {
expect(items.length).toBeGreaterThan(0);
});
+ it('localizes the context-menu action label through the i18n catalog', () => {
+ render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{
+ fr: {'@astryx.tableRowExpansion.expandRow': 'Développer la ligne'},
+ }}>
+ <Harness />
+ </InternationalizationProvider>,
+ );
+ fireEvent.contextMenu(screen.getByText('Folder A'));
+ const items = screen.getAllByRole('menuitem', {
+ name: /Développer la ligne/,
+ hidden: true,
+ });
+ expect(items.length).toBeGreaterThan(0);
+ });
+
it('does not show chevron for leaf nodes', () => {
render(<Harness />);
// Leaf C has no children
diff --git a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
index a12939081e..2a24f50c73 100644
--- a/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
+++ b/packages/core/src/Table/plugins/rowExpansion/useTableRowExpansion.tsx
@@ -576,7 +576,9 @@ export function useTableRowExpansion<T extends Record<string, unknown>>(
{
id: 'row-expansion-toggle',
group: 'row-expansion',
- label: isExpanded ? 'Collapse row' : 'Expand row',
+ label: isExpanded
+ ? t('@astryx.tableRowExpansion.collapseRow')
+ : t('@astryx.tableRowExpansion.expandRow'),
icon: (
<span {...stylex.props(rtlStyles.mirror)}>
<Icon
diff --git a/packages/core/src/hooks/useKeyboardHint.test.tsx b/packages/core/src/hooks/useKeyboardHint.test.tsx
index 762647efe5..5ae0a6cc9a 100644
--- a/packages/core/src/hooks/useKeyboardHint.test.tsx
+++ b/packages/core/src/hooks/useKeyboardHint.test.tsx
@@ -9,6 +9,7 @@
import {render} from '@testing-library/react';
import {describe, expect, it} from 'vitest';
import {useKeyboardHint, type KeyboardHintOrientation} from './useKeyboardHint';
+import {InternationalizationProvider} from '../i18n';
function TestHint({orientation}: {orientation?: KeyboardHintOrientation}) {
const {hintElement} = useKeyboardHint({orientation});
@@ -67,4 +68,25 @@ describe('useKeyboardHint', () => {
expect(hint.className).toContain('useKeyboardHint__styles.hint');
});
+
+ it('renders the "to navigate" label from the i18n catalog', () => {
+ const {container} = render(<TestHint />);
+ const hint = container.querySelector('[popover="manual"]') as HTMLElement;
+
+ expect(hint.textContent).toContain('to navigate');
+ });
+
+ it('localizes the "to navigate" label through the i18n catalog', () => {
+ const {container} = render(
+ <InternationalizationProvider
+ locale="fr"
+ overrides={{fr: {'@astryx.keyboardHint.toNavigate': 'pour naviguer'}}}>
+ <TestHint />
+ </InternationalizationProvider>,
+ );
+ const hint = container.querySelector('[popover="manual"]') as HTMLElement;
+
+ expect(hint.textContent).toContain('pour naviguer');
+ expect(hint.textContent).not.toContain('to navigate');
+ });
});
diff --git a/packages/core/src/hooks/useKeyboardHint.tsx b/packages/core/src/hooks/useKeyboardHint.tsx
index 89cb85364c..1757539d38 100644
--- a/packages/core/src/hooks/useKeyboardHint.tsx
+++ b/packages/core/src/hooks/useKeyboardHint.tsx
@@ -4,7 +4,7 @@
/**
* @file useKeyboardHint.tsx
- * @input Uses React, StyleX, Kbd, useLayer
+ * @input Uses React, StyleX, Kbd, useLayer, i18n (useTranslator)
* @output Exports useKeyboardHint hook — ephemeral arrow-key navigation hint
* @position Core hook; shows sighted keyboard users how to navigate composite
* widgets that use roving tabindex (single Tab stop, arrows inside)
@@ -27,6 +27,7 @@ import {
} from '../theme/tokens.stylex';
import {Kbd} from '../Kbd';
import {useLayer} from '../Layer/useLayer';
+import {useTranslator} from '../i18n';
// ---------------------------------------------------------------------------
// Types
@@ -179,6 +180,7 @@ export function useKeyboardHint(
isEnabled = true,
} = options;
+ const t = useTranslator();
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const dismissedRef = useRef(false);
const isVisibleRef = useRef(false);
@@ -316,7 +318,9 @@ export function useKeyboardHint(
const hintElement = layer.render(
<span aria-hidden="true">
{arrowContent}
- <span {...stylex.props(styles.label)}>to navigate</span>
+ <span {...stylex.props(styles.label)}>
+ {t('@astryx.keyboardHint.toNavigate')}
+ </span>
</span>,
{
placement: 'below',