Skip to content

Localize backend feedback

Opt in by setting localization on ArcApplication.createBuilder (or on ArcServer). Configure an ordered list of supported BCP 47 base tags and a default from that list. Without this option, Arc does not negotiate or add localization headers or framework validation descriptors.

import { ArcApplication, withUiLanguage } from '@cratis/arc.core';
const app = await ArcApplication.createBuilder({
localization: { languages: ['en', 'fr', 'fr-CA'], default: 'en' }
}).addCatalog({
en: { 'order.saved': 'Your order was saved.' },
fr: { 'order.saved': 'Votre commande a été enregistrée.' }
}).build();
function renderNotification(recipientLanguage: string): string | undefined {
return withUiLanguage(recipientLanguage, () => app.message('order.saved'));
}

Use uiLanguage() in an Arc operation to read the selected tag. For background work, pass the recipient’s saved preference explicitly, not the language of the request that scheduled the work. withUiLanguage confines the choice to its callback and asynchronous continuations. Use app.message(id, tag) for a single explicit lookup. Catalogs supply plain text or templates; the lookup doesn’t interpolate them. Lookup checks the selected language, a matching supported parent, then the host default and English. It returns undefined for an unknown message ID.

By default Arc reads Accept-Language. Set providers to choose the order of AcceptLanguage, QueryString (ui-culture) and Cookie (.AspNetCore.Culture). Optional aliases define explicit tag mappings. For SSE and WebSocket handshakes, _cratisUiCulture overrides the configured providers when exactly one valid hint is supplied. Arc does not bind that hint as a stream query argument. Subsequent observable evaluations use the handshake’s language.

Localized responses include Content-Language. Arc adds Accept-Language or Cookie to Vary whenever the corresponding provider is enabled, not just when it is selected. Cookie negotiation also sets Cache-Control: no-store, private.

Framework feedback retains the existing English message. When a stable descriptor is available, Arc includes reasonDetail and may include messageArguments for a client message template. Supply only named strings, booleans, or finite numbers (safe integers if integral). Never put raw user input, secrets, or diagnostics in message arguments. Localization does not change JSON, number and date formatting, or stored values.