Foundations
LocaleProvider
Sets the locale for every ReactLoom component below it: number and date formatting and parsing, calendar systems, first day of the week, and keyboard mirroring in right-to-left languages.
import { LocaleProvider, useLocale } from '@reactloom/ui';Examples
Three locales
Each subtree formats and parses for its own locale; Arabic also sets dir="rtl".
en-US · ltr11
10
2026
de-DE · ltr10
11
2026
ar-EG · rtl١٠
١١
٢٠٢٦
import { DatePicker, parseDate } from '@reactloom/dates';
import { LocaleProvider, NumberInput, Stack, useLocale } from '@reactloom/ui';
function Current() {
const { locale, direction } = useLocale();
return <code>{`${locale} · ${direction}`}</code>;
}
export default function Example() {
return (
<Stack gap="6" style={{ width: '100%', maxWidth: 300 }}>
{['en-US', 'de-DE', 'ar-EG'].map((locale) => (
<LocaleProvider key={locale} locale={locale}>
{/* The locale drives formatting and keyboard mirroring; dir drives layout. Set both. */}
<Stack gap="2" dir={locale.startsWith('ar') ? 'rtl' : 'ltr'}>
<Current />
<NumberInput label="Amount" defaultValue={1234.5} formatOptions={{ style: 'currency', currency: 'EUR' }} />
<DatePicker label="Date" defaultValue={parseDate('2026-11-10')} />
</Stack>
</LocaleProvider>
))}
</Stack>
);
}API reference
LocaleProvider props
| Prop | Type | Default |
|---|---|---|
localeBCP 47 tag, e.g. de-DE, ar-EG, ja-JP-u-ca-japanese. Defaults to the browser locale. | string | — |
children | ReactNode | — |
useLocale()
| Prop | Type | Default |
|---|---|---|
localeThe active locale. | string | — |
directionDerived from the locale. | 'ltr' | 'rtl' | — |
Accessibility
- The locale changes formatting and arrow-key mirroring, not layout: also set
dir="rtl"on<html>or the subtree. - Set lang on the same element so screen readers pick the right voice.
Usage guidelines
Do
- Wrap the whole app once; nest providers only for regions in another language.
Don’t
- Don’t format numbers or dates yourself before passing them to components — pass values and formatOptions.