Examples

Three locales

Each subtree formats and parses for its own locale; Arabic also sets dir="rtl".

Preview
en-US · ltr
de-DE · ltr
ar-EG · rtl
Example.tsx
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

LocaleProvider props
PropTypeDefault
locale
BCP 47 tag, e.g. de-DE, ar-EG, ja-JP-u-ca-japanese. Defaults to the browser locale.
string—
children
ReactNode—

useLocale()

useLocale()
PropTypeDefault
locale
The active locale.
string—
direction
Derived 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.