Layout & primitives
LocaleProvider
Free9.9 KB gzippedSets the language of every component inside: built-in labels and screen-reader text, date and number formats, plurals, and writing direction. Wraps its children in an element with lang and dir (display: contents, so layout is unaffected); overlays opened inside keep the language.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report
Import
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
Importing only LocaleProvider adds about 9.9 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Wrap any part of your app in LocaleProvider with a locale and its messages. Every component inside uses that language for its built-in text, dates and numbers.
No hay resultados para «zapatillas»
Prueba con otra búsqueda o borra los filtros.
import {
EmptyState,
LocaleProvider,
Pagination,
Stack,
} from "@vjdesigns/vjdesigns-ui";
import es from "@vjdesigns/vjdesigns-ui/locales/es";
export function Basic() {
return (
<LocaleProvider locale="es" messages={es}>
<Stack gap={4} align="center">
<EmptyState kind="no-results" query="zapatillas" />
<Pagination pageCount={8} defaultPage={3} />
</Stack>
</LocaleProvider>
);
}
Override strings
Pass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top), and per-component props such as clearLabel still win.
import { LocaleProvider, Pagination } from "@vjdesigns/vjdesigns-ui";
export function OverrideStrings() {
return (
<LocaleProvider locale="en-GB" messages={{ pagination: { next: "Onwards", previous: "Back" } }}>
<Pagination pageCount={8} defaultPage={3} />
</LocaleProvider>
);
}
Nested
Providers nest: an inner provider switches the language for its part of the page, and sets lang there so screen readers switch pronunciation too.
Cette partie est en français :
import {
LocaleProvider,
SearchInput,
Stack,
Text,
} from "@vjdesigns/vjdesigns-ui";
import fr from "@vjdesigns/vjdesigns-ui/locales/fr";
export function Nested() {
return (
<Stack gap={4} style={{ width: "100%", maxWidth: "22rem" }}>
<SearchInput aria-label="Search" placeholder="Search in English" clearable defaultValue="shoes" />
<LocaleProvider locale="fr" messages={fr}>
<Stack gap={2}>
<Text size="sm" tone="muted">
Cette partie est en français :
</Text>
<SearchInput aria-label="Rechercher" placeholder="Rechercher" clearable defaultValue="chaussures" />
</Stack>
</LocaleProvider>
</Stack>
);
}
Right to left
Arabic, Hebrew, Persian and Urdu set dir="rtl" automatically: layouts mirror, the calendar starts on the locale's first weekday, and arrow keys follow the reading direction. Pass dir to override it.
أكتوبر 2026
| السبت | الأحد | الاثنين | الثلاثاء | الأربعاء | الخميس | الجمعة |
|---|---|---|---|---|---|---|
import { Calendar, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function RightToLeft() {
return (
<LocaleProvider locale="ar" messages={ar}>
<Calendar aria-label="اختر تاريخًا" defaultValue="2026-10-14" />
</LocaleProvider>
);
}
Usage notes
import es from "@vjdesigns/vjdesigns-ui/locales/es";
<LocaleProvider locale="es" messages={es}>
<App />
</LocaleProvider>
Providers nest: an inner provider changes the locale for its subtree and merges its messages over the outer ones.
API reference
LocaleProvider
New in 1.3.0| Prop | Type | Default |
|---|---|---|
localeRequiredBCP 47 language tag, e.g. | string | — |
messagesBuilt-in strings for the language, e.g. | PartialMessages | — |
dirWriting direction. Defaults to the locale's: | "ltr""rtl" | — |
children | ReactNode | — |
See what changed in each version in the Changelog.
Accessibility report
LocaleProvider targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
Not focusable, so there's no keyboard interaction of its own.
Roles and states
| Element | Role | States and properties |
|---|---|---|
Wrapper <div> | none (generic) | lang and dir for its subtree |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |