Skip to content

Localize Cratis Components

English is built in. For other languages, supply a catalog with value.catalog. Catalogs translate labels and feedback owned by Components, including accessible names and content rendered in overlays. React Aria supplies its own locale data; applications remain responsible for their own text, data, and server validation messages.

A catalog translator implements t(id, values?), returning a formatted string or undefined for a missing message. Use a translator returned by Arc 25.12’s createCatalogRegistry, or supply another translator with the same interface. Register your own flat ICU MessageFormat 1 catalog, or install @cratis/components.locale.nb at the same version as @cratis/components.

import { createCatalogRegistry } from '@cratis/arc/localization/catalog';
import { CratisComponentsProvider } from '@cratis/components';
const registry = createCatalogRegistry({
default: 'en',
catalog: [{ fr: () => ({ 'components.dialog.cancel': 'Annuler' }) }],
});
const catalog = await registry.load('fr-FR');
<CratisComponentsProvider value={{ locale: 'fr-FR', formatLocale: 'de-DE', catalog }}>
<App />
</CratisComponentsProvider>;

Load a fresh translator for the new UI language when it changes. The formatting locale controls date and number formatting independently of the catalog language. Catalogs can be partial; missing entries use built-in English.

Mount ArcComponentsProvider inside your existing Arc instead of adding a second Components provider. The bridge follows Arc’s UI and formatting locales independently and accepts the same value.catalog as the standalone provider. It forwards value, children, toaster, and dialogHeaderActions to the Components provider. Set value.locale or value.formatLocale to override just that setting.

import { createLocale } from '@cratis/arc/localization';
import { Arc } from '@cratis/arc.react';
import { ArcComponentsProvider, LanguageSelector } from '@cratis/components/Localization';
const locale = createLocale({ defaultLocale: 'en-US', supported: ['en-US', 'nb-NO'] });
// Pass the translator for the current locale; reload it when the UI language changes.
<Arc locale={locale}>
<ArcComponentsProvider value={{ catalog }} toaster>
<LanguageSelector />
<App />
</ArcComponentsProvider>
</Arc>;

Configure the available languages in Arc. LanguageSelector displays those languages by their own names, such as English and norsk bokmål, with the casing the platform returns and no flags. When multiple supported tags share a language, options add the script and region, such as English (United Kingdom). Each option carries its own lang and dir, and an explicit { tag, label } option replaces the endonym. Selecting an option asks Arc to switch locale without reloading the page. On Arc versions that do not expose locale state, the bridge uses the standalone defaults and an uncontrolled selector renders nothing. The setup-only @cratis/components import does not use Arc.

A control-specific prop takes precedence, followed by value.messages, matching legacy value.locales overrides, the supplied catalog, and then English. Overrides merge by individual key. Function-valued messages stay functions, and you can override one without redefining its group.

<ArcComponentsProvider
value={{ messages: { paginator: { page: (number) => `Side ${number}` } } }}
>
<App />
</ArcComponentsProvider>;

See provider configuration for message groups and control-specific overrides.

Catalog ID Named inputs
components.paginator.page page
components.paginator.range start, end, total
components.columnFilter.filterTriggerAriaLabel field
components.columnFilter.valueAriaLabel field
components.columnFilter.matchModeLabel mode, defaultLabel
components.command.validationAnnouncement count, firstMessage
components.controls.removeItem item

Dates passed to chat, TimeMachine, and date-range filter templates are already formatted. Chat timestamps, TimeMachine event timestamps, and date-range values use formatLocale, then an explicitly configured UI locale, then the browser locale.

The messagePacks="builtin" prop and the automatic Bokmål registration in ArcComponentsProvider without a catalog still work for existing apps. Using automatic Bokmål logs one deprecation warning. The legacy registration will be removed in a future major release; supply an explicit catalog to opt into the new behavior now.

LanguageSelector also accepts value, options, and onChange, so you can connect it to application state instead of Arc. The selector prefers an exact supported tag, then the first option with the same base language. It shows no selection when neither matches. The native select uses the localized accessible name when no name is supplied. To name it yourself, use label, pt.root['aria-label'], pt.root['aria-labelledby'], or a visible label associated with pt.root.id. Add a class with className or pass other attributes through pt.root and pt.option.

import { useState } from 'react';
import { CratisComponentsProvider } from '@cratis/components';
import { LanguageSelector } from '@cratis/components/Localization';
function LocalizedApp() {
const [locale, setLocale] = useState('en-US');
return (
<CratisComponentsProvider value={{ locale }}>
<LanguageSelector value={locale} options={['en-US', 'nb-NO']} onChange={setLocale} />
<App />
</CratisComponentsProvider>
);
}

LanguageSelector renders a native select by default. Pass variant="segmented" for a native radio group, where the arrow keys move between languages and focus stays on the control after a switch.

<LanguageSelector variant="segmented" />

useLanguage() returns { language, options, setLanguage } for building your own control. It reads the nearest LanguageProvider, then Arc’s locale. Without either, options is empty. LanguageProvider is the controlled, Arc-free source.

import { LanguageProvider, useLanguage } from '@cratis/components/Localization';
<LanguageProvider value={locale} options={['en', 'nb-NO', { tag: 'fr', label: 'Français' }]} onChange={setLocale}>
<App />
</LanguageProvider>;

Specs and Storybook run axe against both variants, and the target size, focus indicator and selected state use theme tokens. Automated results are not certification: keyboard-only use, screen readers, zoom reflow and right-to-left layouts still need a manual pass.