Localize request UI culture in Cratis Arc.Core
ArcApplication can select a UI culture per HTTP request without changing its default formatting culture. The self-hosted listener applies the same culture negotiation, provider order, and HTTP response headers as the ASP.NET Core host. No additional middleware call is needed.
using Cratis.Arc;
var builder = ArcApplication.CreateBuilder(args);builder.AddCratisArc(configureOptions: options =>{ options.Localization = new() { SupportedUICultures = ["en", "nb-NO"], DefaultUICulture = "en" };});
var app = builder.Build();app.UseCratisArc();await app.RunAsync();You can also configure Cratis:Arc:Localization in configuration. Without that section or a code override, the request pipeline doesn’t negotiate a language or change the response headers. With localization enabled, Accept-Language selects a supported UI culture for resource lookup and validation. For example, an Accept-Language: nb-NO request results in Content-Language: nb-NO. Requests that do not match a language use the configured default unless it is excluded and another supported language is eligible. Formatting remains invariant unless FormattingCulture pins a different culture for all requests.
On observable-query WebSocket and SSE connections, the Arc client can send one UI language hint through the reserved _cratisUiCulture transport selector. It uses the same tag matching as Accept-Language, takes precedence when it resolves to a supported language, and does not bind as a query argument.
The listener restores both cultures after each request. Background work still uses the host’s culture defaults; see Invariant culture to configure those independently.
Render catalog messages outside HTTP
Section titled “Render catalog messages outside HTTP”For jobs and reactors, you can render one message for an explicit CultureInfo. Build a portable catalog from the application’s frontend catalog sources while building the application:
cratis-l10n build --root frontend --catalog-output ../backend/catalog.jsonCopy that file into the service’s deployment or embed it as a resource. Load it once at startup. The service needs neither Node nor a request scope. The regular frontend build still generates its browser loaders; run it separately if you need both outputs.
using System.Globalization;using Cratis.Arc.Localization;
using var input = File.OpenRead("catalog.json");var catalog = MessageCatalog.Load(input);var message = catalog.Render("arc.validation.requiredField", new Dictionary<string, object?> { ["field"] = "Hours" }, CultureInfo.GetCultureInfo("nb-NO"));if (message is not null){ Console.WriteLine($"[{message.Locale}] {message.Text}");}With only built-in Arc English, this prints [en] Hours is required. Opt in to Bokmål in localization.json and supply that ID in locales/nb/overrides.json to use Norwegian copy. Feature English comes from messages.en.json; app translations come from the configured languages and their parent directories. A pack installed for the browser is not a server catalog. This does not migrate .resx resources or change descriptor transport.
Resolution is per ID: requested tag and parents, application default and parents, then English, ending with built-in Arc English. It does not negotiate request language, consult aliases, select a recipient language, or mutate either ambient culture. An empty string is a match. If no layer can render with the supplied arguments, Render returns null; the caller decides whether to omit the message or use its own fallback. Persist stable keys and only intentionally shareable arguments in durable work, rather than rendered prose.
Portable format compatibility
Section titled “Portable format compatibility”The compiler and Arc.Core exchange a versioned UTF-8 JSON artifact. Version 1 carries the app default, ordered layers of case-sensitive IDs and compiled message instructions, per-locale decimal symbols and cardinal rule data, and Unicode attribution. An incompatible format needs a new version and a reader that explicitly accepts it. Unknown versions and invalid instruction shapes fail on load with JsonException. Version 1 accepts at most 1 MiB (1,048,576 UTF-8 bytes including whitespace) and 24 nested select/plural branches along any path, inclusive. Both compiler and reader reject larger or deeper catalogs. Deploy a compatible reader before emitting a new format.
Portable templates support literals (including markup as text), plain string/number arguments, unstyled numbers, cardinal plurals with exact selectors and #, selects, and nested branches. A branch must have other. Exact plural selectors use = followed by a safe integer in canonical decimal spelling: =0, =1, and =-1 are valid; =01, =+1, and =-0 are not. Dates, times, number styles, plural offsets, and ordinals are not portable. Pass numbers as numbers, not strings. Boolean and structured arguments do not render a placeholder. Plain numbers are invariant; grouping and cardinal rules use the supplying locale. V1 covers safe integers and fractional magnitudes at least 0.000001, with localized number parity specified through three fraction digits.
Number data comes from Unicode CLDR JSON 48.0.0, not the host’s current culture data. The compiler uses the locale’s default decimal numbering system and can use its parent profile. A locale without a supported profile is rejected rather than formatted as English. Each artifact includes the data license notices. To update data, review the pinned release and notices, regenerate cldrData.ts with generateCldr.py from that release’s extracted directory, and verify the cross-runtime fixtures before changing the pin. Different browser CLDR releases need not produce byte-identical results outside the shared contract.