Internationalization
Luxel builds a view in several languages from catalogs. Each language is its own compiled view, with its own template and its own lang. The runtime is the same file in every language. The server chooses plurals and formats money, dates and numbers; the browser only fills templates.
This is a base, not a full i18n system: one language per page, no language switcher, no right-to-left support yet.
Configure the languages
// luxel.config.ts export default defineConfig({ lang: 'es', locale: { lang: 'es-PE', currency: 'PEN' }, i18n: { source: 'es', // the language the views are written in languages: { es: 'es-PE', en: 'en-US' }, // code → BCP 47 tag of the page and of formatting views: { cobranza: ['en'] }, // view → the languages it is also built in // catalogs: 'i18n', // directory of the catalogs (default "i18n") }, // ... });
With this, cobranza is built twice:
- cobranza, in the source language, served at /dom/cobranza;
- cobranza-en, from i18n/en.json, with lang="en-US", served at /dom/cobranza-en.
Both run the same contract view and the same handlers. You write one view, one contract entry and one set of handlers.
Catalogs
The build extracts every fixed text of the translated views to i18n/‹source>.json: titles, labels, static text, placeholders, runtime messages and the contract's message templates. The keys are the source texts themselves. You keep one catalog per other language, with the same keys:
{ "Cobranza": "Collections", "Cobranza mensual": "Monthly collections", "Total del año": "Year total", "{0} agencia con cobranza en {1}": "{0} agency with collections in {1}", "{0} agencias con cobranza en {1}": "{0} agencies with collections in {1}" }
A fixed text without an entry in a declared language's catalog fails the build with LUXEL-E049 (missing-translation), and a missing catalog file too. So a new label never ships untranslated.
Messages and placeholders
Server messages are templates in the contract, with placeholders {0} to {9}:
messages: { period: 'Periodo no disponible.', 'agencies.one': '{0} agencia con cobranza en {1}', 'agencies.other': '{0} agencias con cobranza en {1}', },
A handler never sends a phrase for these. It sends a reference, a message key plus its arguments:
return ctx.reject('NOT_FOUND', ctx.message('period'));
On the wire the answer carries the message's index and its arguments. The page fills the template of its own language. The keys are server names and are never published; the templates are public text.
Prefer messages over plain strings in ctx.reject and in text values: a plain string is sent as is, in whatever language you wrote it.
Plurals: the server chooses
Declare one key per plural category, ‹key>.‹category>, with at least ‹key>.other:
'summary.one': '{0} contact · page {1} of {2}', 'summary.other': '{0} contacts · page {1} of {2}',
ctx.plural('summary', total, String(total), String(page), String(pages))
ctx.plural(key, count, ...args) picks the variant that the page's language selects for count (Intl.PluralRules: zero, one, two, few, many, other) and falls back to ‹key>.other. The server decides; the browser fills the chosen template.
Unlike ctx.message, the generated types do not check ctx.plural's key or arguments: keep them in step with the contract yourself.
The framework's own messages
The framework answers some refusals itself (a conflict, a forbidden action, invalid input). Their default texts follow the view's language: Spanish for a Spanish page, English otherwise. To control them in a translated view, declare them in the contract as luxel.* messages; they are then extracted and translated like the others:
'luxel.unsupported': 'Evento no soportado por la vista.', 'luxel.conflict': 'La vista cambió. Vuelve a cargar el estado.', 'luxel.mismatch': 'El eventId ya se usó con otra solicitud.', 'luxel.forbidden': 'Acción no permitida.', 'luxel.invalid': 'Revisa los datos ingresados.',
Errors the gateway answers before it knows the view (rate limit, Origin, content type, size, CSRF) are plain phrases in the host's language.
Formatting by the host
The browser formats nothing. luxel-host formats on the server, with Intl:
| Leaf | Without locale | With locale |
|---|---|---|
| money() | The bindings' formatMoney(cents) | formatMoney; in a page whose language comes from i18n (a view listed in i18n.views and its translations, when the tag differs from lang), Intl.NumberFormat with that language and locale.currency |
| date() | The ISO string as sent | Intl.DateTimeFormat, medium date style, in UTC, in the page's language |
| quantity() | String(value) | Intl.NumberFormat, up to 2 decimals, in the page's language |
Money stays integer cents all the way: the host turns cents into an exact decimal string before formatting, with no float arithmetic on the amount.
ctx.lang gives a handler the page's language, for anything language-dependent it chooses itself.
What is not supported yet
- One language per page. A page is built in one language; mixing languages in one page is not supported.
- No language switcher. There is no built-in way to choose the language. Each language is its own view id and URL (cobranza, cobranza-en); linking between them is up to you.
- No right-to-left layout.
- Gateway errors before the view is known are not translated (see above).