Olddevs UI4.14.0
Foundations

Localization: provider and message catalog

Since 2.0.0 the kit defaults to English and supports other languages. Before 2.0.0 Russian labels were hard-coded into prop defaults, and another language meant passing a label at every call site.

How a string is resolved

component prop  →  provider message  →  English fallback in code

The prop always wins: it is a targeted override, not the only way. The fallback lives in the code and in the bundle — without it a component with no provider would render nothing instead of a label.

Setup

The kit does not load message catalogs automatically — otherwise Russian would end up in everyone's bundle, including those who only need English. A message catalog is imported explicitly:

import { UiProvider } from "@olddevs/ui";
import ru from "@olddevs/ui/locales/ru";

<UiProvider locale="ru-RU" messages={ru}>
  <App />
</UiProvider>;

Both props are needed, and each does a different job:

PropWhat it is responsible forWithout it
messagesthe kit's labelsEnglish strings from the fallback
localedate, number and unit formats and plural form selectionthe locale comes from above, see below

messages without locale produces Russian labels with dates in the browser's format — almost certainly not what you need.

You do not need to set up English: it is the fallback. @olddevs/ui/locales/en exists for symmetry — code that picks a message catalog by the user's language should not stumble on one language having an import and another not.

Partial override

A message catalog can be supplied in pieces: the fallback fills in any branches you omit.

<UiProvider messages={{ confirmDialog: { confirm: "Yes, delete" } }}>

A nested UiProvider inherits everything from the outer one and overrides what it sets itself, so a dialog can have its own locale inside an app that uses another language.

If you already have an I18nProvider from react-aria

A common case: the app has its own I18nProvider because it uses react-aria directly. The kit does not conflict with it.

Without locale the kit does not mount its own I18nProvider at all — the locale is taken from yours. This is deliberate: a kit that forced en-US would make date pickers use a different language from the rest of the app.

<I18nProvider locale="de-DE">
  <UiProvider messages={de}>…</UiProvider>
</I18nProvider>

Here dates and calendars are German, and labels come from your message catalog. Pass locale to UiProvider only if you want to override the outer locale for a subtree.

Without a provider

The kit works this way too: all strings are English, date formats come from the browser's locale. You do not need to wrap a single button separately.

What does not count as translation

Three things bypass the message catalog on purpose:

  • The Keyboard layout. The array ["Й","Ц","У",…] defines which characters the keyboard enters, not which language it is labeled in. layout="ru" works with locale="en" and vice versa.
  • Units of measure. File size is formatted with Intl.NumberFormat and style: "unit": "МБ" and "MB" are one unit by the rules of the locale, not two strings to translate.
  • Exception messages. throw new Error("Unknown period") is read by a developer in a stack trace, not by a user on screen.

How to add a string

  1. A key in src/i18n/messages.ts — in the namespace of its family; if a label means the same thing in two places, it goes to common and is not duplicated.
  2. A value in src/i18n/defaults.ts (English) and in src/locales/ru.ts.
  3. In the component — useMessages(), and prop ?? messages.family.key.

A parameterized message is a function, not an ICU MessageFormat template: collapsed: ({ count }) => …. Intl.PluralRules handles pluralization inside the locale file: the locale knows the rules, not the component. A component that counts word endings supports only one language.

The gate tests/i18n-gate.test.ts fails on both a literal that bypasses the message catalog and a key missing from the Russian locale.

Hooks

HookWhat it returns
useMessages()the whole message catalog; read messages.pagination.next, not a string key
useUiLocale()the locale for Intl: explicit → the consumer's I18nProvider → browser
useUiConfig()dir, the portal container and the default density

Density

Since 2.2.0 UiProvider accepts density — "comfortable" or "compact". This is a default, not a mode: the DataTable prop and the table state override the value, while the provider saves an app with five tables from five identical props.

The resolution chain works the same way as for message catalog strings:

DataTable prop → table state → provider → kit default (comfortable)

The prop appeared only in 2.2.0, although it was promised as early as 2.0.0: ADR-0002 postponed it until a reader appeared, and DataTable became one. Details — ADR-0023.

RTL

UiProvider accepts dir and exposes it, but the kit has no component-level RTL (right-to-left writing) support: no component mirrors its layout. The prop exists so that the contract does not have to be broken when a requesting screen appears. Until then, dir="rtl" changes only what you do with that value yourself.

See also

  • Full catalog of keys — part of the public API.

On this page