The ecosystem · packages/intl
Every reader's language, written the same on the server and in the browser
Numbers, money, dates, relative times and translated messages with plurals, written as each reader's locale writes them. It is plain Roc on no platform: the server renders a page in the reader's language, and the browser hydrates the same text. In the demo below, pick a language or change n.
Installing it#
Name the package in your app's header (main.roc):
app [program] { intl: "../packages/intl/main.roc", pf: platform "…/server/platform/main.roc" }Both halves of the app, and tests, import its modules. One locale's formatting is an Intl value:
import intl.Intl
import intl.Locales
intl = Intl.new(Locales.pl)
intl.number(12345.5) # "12 345,5"
intl.currency(1234.5, "PLN") # "1234,50 zł"
intl.date(moment, Long) # "21 listopada 2026"
intl.relative(-2, Hour) # "2 godziny temu"The one component, <Language>, holds the reader's locale as a context and is a picker. rocx copies it into your app when it writes the app's code (using a package); import intl.Language imports the copy.
A first look#
number(n × 1234.5)- 3,703.5
currency(n × 19.99, "EUR")- €59.97
relative_day(-n)- 3 days ago
date(moment, Full)- Saturday, November 21, 2026
Language.store! makes a store: the reader's Intl in a signal, the supported locales, and a catalog of messages. <LanguageContext value={store}> provides it to everything inside as a context; <Language /> is the picker. Picking a language rewrites only the holes that call intl!(). Here remember! does nothing, so your choice isn't kept; in an app it sends the choice to an endpoint that sets a cookie (below).
The demo's catalog is empty: messages work in the browser too, but would add about 13 KB to the wasm every page of this site loads. Its message is under Messages, written as this page was built.
import intl.Language
import intl.Locales
import intl.Catalog
store = Language.store!({ supported: IntlDemo.supported, catalog: Catalog.empty("en"), tag: "en", remember!: |_| {} })
{ intl!, .. } = store
…
<LanguageContext value={store}>
…
<Language label="Language" />
…
<div><dt><code>{"number(n × 1234.5)"}</code></dt><dd lang={intl!().tag()} dir={intl!().direction()}>{intl!().number(count!().to_dec() * 1234.5)}</dd></div>
…
</LanguageContext>The whole demo: site/Demos/IntlDemo.rocx
import pf.Html
import pf.Solid exposing [create_signal!]
import pf.Context
import intl.Language
import intl.Locales
import intl.Catalog
## The intl page's demo: numbers, money, a relative day and a date, in the language the picker says,
## switched in place. Each hole calls `intl!()`, so picking a language writes them again, and
## nothing else runs. Nothing here asks a server: the locales' data is in the browser's wasm, the
## same as the server's that rendered the page. It has no messages (its catalog is empty): a
## translated message would add about 13 KB to the site's wasm, so the page shows the demo's
## message as it was written at build time instead (`IntlSamples.files`).
IntlDemo := [].{
## The demo's languages, English first: the default.
supported : List(Locales.Data)
supported = [Locales.en, Locales.de, Locales.pl, Locales.ar, Locales.ja]
view! : {} => Html
view! = |{}| {
store = Language.store!({ supported: IntlDemo.supported, catalog: Catalog.empty("en"), tag: "en", remember!: |_| {} })
{ intl!, .. } = store
(count!, set_count!) = create_signal!(3)
<LanguageContext value={store}>
<div class="intl-demo">
<div class="controls">
<Language label="Language" />
<button type="button" class="fewer" aria-label="One fewer" on:click={|| set_count!(count!() - 1)} disabled?={count!() == 0}>−</button>
<output class="count">n = {intl!().int(count!())}</output>
<button type="button" class="more" aria-label="One more" on:click={|| set_count!(count!() + 1)}>+</button>
</div>
<dl>
<div><dt><code>{"number(n × 1234.5)"}</code></dt><dd lang={intl!().tag()} dir={intl!().direction()}>{intl!().number(count!().to_dec() * 1234.5)}</dd></div>
<div><dt><code>{"currency(n × 19.99, \"EUR\")"}</code></dt><dd lang={intl!().tag()} dir={intl!().direction()}>{intl!().currency(count!().to_dec() * 19.99, "EUR")}</dd></div>
<div><dt><code>{"relative_day(-n)"}</code></dt><dd lang={intl!().tag()} dir={intl!().direction()}>{intl!().relative_day(0 - count!())}</dd></div>
<div><dt><code>{"date(moment, Full)"}</code></dt><dd lang={intl!().tag()} dir={intl!().direction()}>{intl!().date(1795273445000, Full)}</dd></div>
</dl>
</div>
</LanguageContext>
}
<style>
.intl-demo {
display: grid;
gap: var(--space-3);
}
.controls {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
align-items: center;
}
.controls :global(select) {
min-height: 2.5rem;
padding: var(--space-2) var(--space-3);
border: 0;
border-radius: var(--radius-sm);
background: var(--fill);
color: var(--text);
}
.controls button {
min-width: 2.5rem;
min-height: 2.5rem;
}
dl {
display: grid;
grid-template-columns: max-content 1fr;
gap: var(--space-2) var(--space-4);
margin: 0;
}
dl div {
display: contents;
}
dt {
color: var(--text-muted);
}
dd {
margin: 0;
font-size: var(--size-lg);
}
.count {
min-width: 4.5rem;
text-align: center;
font-family: var(--mono);
color: var(--accent);
}
</style>
}Ten locales#
English (American and British), German, French, Spanish, Polish, Czech, Russian, Arabic and Japanese, each writing the same calls (as this page was built):
| Locale | number(-1234567.891) | percent(0.256, 1) | compact(1234567) | currency(1234.5, "EUR") |
|---|---|---|---|---|
enEnglish | -1,234,567.891 | 25.6% | 1.2M | €1,234.50 |
en-GBBritish English | -1,234,567.891 | 25.6% | 1.2m | €1,234.50 |
deDeutsch | -1.234.567,891 | 25,6 % | 1,2 Mio. | 1.234,50 € |
frfrançais | -1 234 567,891 | 25,6 % | 1,2 M | 1 234,50 € |
esespañol | -1.234.567,891 | 25,6 % | 1,2 M | 1234,50 € |
plpolski | -1 234 567,891 | 25,6% | 1,2 mln | 1234,50 € |
csčeština | -1 234 567,891 | 25,6 % | 1,2 mil. | 1 234,50 € |
ruрусский | -1 234 567,891 | 25,6 % | 1,2 млн | 1 234,50 € |
arالعربية | -1,234,567.891 | 25.6% | 1.2 مليون | 1,234.50 € |
ja日本語 | -1,234,567.891 | 25.6% | 123万 | €1,234.50 |
| Locale | date(moment, Medium) | time(moment, Short) | relative(-3, Day) | relative_day(-1) |
|---|---|---|---|---|
enEnglish | Nov 21, 2026 | 3:04 PM | 3 days ago | yesterday |
en-GBBritish English | 21 Nov 2026 | 15:04 | 3 days ago | yesterday |
deDeutsch | 21.11.2026 | 15:04 | vor 3 Tagen | gestern |
frfrançais | 21 nov. 2026 | 15:04 | il y a 3 jours | hier |
esespañol | 21 nov 2026 | 15:04 | hace 3 días | ayer |
plpolski | 21 lis 2026 | 15:04 | 3 dni temu | wczoraj |
csčeština | 21. 11. 2026 | 15:04 | před 3 dny | včera |
ruрусский | 21 нояб. 2026 г. | 15:04 | 3 дня назад | вчера |
arالعربية | 21/11/2026 | 3:04 م | قبل 3 أيام | أمس |
ja日本語 | 2026/11/21 | 15:04 | 3 日前 | 昨日 |
The moment is 2026-11-21 15:04:05 UTC. The tests check each locale's output against JavaScript's Intl (ICU 78, CLDR 48), and each plural rule against Intl.PluralRules, number by number.
The reader's locale#
An app lists its supported locales, default first. A request gets the locale its locale cookie names (the reader's choice), else the one Accept-Language asks for, else the default. Locale.wanted(request, "locale") reads both, most wanted first; Intl.choose takes the closest supported locale. pl-PL gets pl; without plain en, en-US gets en-GB, not another language.
| Accept-Language | Read in, of en, en-GB, pl and de |
|---|---|
pl-PL,pl;q=0.9,en;q=0.8 | pl |
en-GB,en;q=0.8 | en-GB |
en-US | en |
fr-CH, fr;q=0.9, de;q=0.7 | de |
ja | en |
(none) | en |
Keep the app's locales and words in one module. A GET endpoint answers the request's locale, and the root layout reads it. The server renders in that locale and sends the answer with the page, so the browser hydrates in the same one.
import pf.Html
import intl.Locales
import intl.Catalog
import intl.Validation
## The app's locales and words, and the locale a request is read in.
I18n := [].{
## The locales the app is written in, its default first. Only these are compiled into it.
supported : List(Locales.Data)
supported = [Locales.en, Locales.pl, Locales.ar]
## Its words: a set of keyed messages for each locale, over the package's words for a form's
## issues.
catalog : Catalog
catalog = Catalog.merge(
Validation.catalog,
Catalog.new(
"en",
[
("en", [("title", "Your basket"), ("items", "{count, plural, =0 {Nothing in it yet} one {# thing} other {# things}}")]),
("pl", [("title", "Twój koszyk"), ("items", "{count, plural, =0 {Jeszcze nic} one {# rzecz} few {# rzeczy} many {# rzeczy} other {# rzeczy}}")]),
("ar", [("title", "سلتك"), ("items", "{count, plural, zero {لا شيء بعد} one {شيء واحد} two {شيئان} few {# أشياء} many {# شيئًا} other {# شيء}}")]),
],
),
)
}How the closest locale is found: Locale.best and Locale.wanted
## The supported locale closest to what is wanted (in order of preference), or `default`. For each
## wanted locale in turn: itself or a fallback of it (`pl-PL`, then `pl`) if supported, then any
## supported locale of its language (`en-US` takes `en-GB`). So a reader who asks for
## `en-US, de` and an app with `en-GB` and `de` gets `en-GB`.
best : List(Locale), List(Locale), Locale -> Locale
best = |wants, supported, default|
match Locale.lookup(wants, supported) {
Ok(found) => found
Err(NoMatch) => default
}
## What a request wants, the most wanted first: the locale in the cookie named `cookie` (a
## reader's own choice, kept), then its `Accept-Language`'s. Takes the platform's
## `Server.Request` (or any record with its `headers`). A `cookie` of `""` reads no cookie.
wanted : { headers : List({ name : Str, value : Str }), ..others }, Str -> List(Locale)
wanted = |request, cookie| {
header = |name| request.headers.find_first(|each| each.name.with_ascii_lowercased() == name).map_ok(|each| each.value) ?? ""
chosen =
if cookie == "" {
[]
} else {
match cookie_value(header("cookie"), cookie) {
Ok(value) =>
match Locale.parse(value) {
Ok(locale) => [locale]
Err(_) => []
}
Err(_) => []
}
}
chosen.concat(Locale.accept_language(header("accept-language")))
}<Language>#
The root layout makes the store and provides it. <html lang dir> follow it, so the whole page switches direction for Arabic:
import pf.Html
import pf.Context
import intl.Language
import ../I18n
import ../Generated/Styles
import ../Generated/Api
## The document, in the reader's language: `lang` and `dir` follow the store, and everything inside
## reads it from the context.
view! = |{ children, .. }| {
# A reader's pick is kept in the `locale` cookie (POST /locale), so the next page is in it too.
remember! = |tag| {
_kept = Api.post_locale({}).send!({ tag: tag })
{}
}
# The reader's locale: GET /locale, answered as the server renders the page, carried in it.
tag = Api.get_locale({}).read!()
store = Language.store!({ supported: I18n.supported, catalog: I18n.catalog, tag, remember! })
{ intl!, .. } = store
<>
<!doctype html>
<html lang={intl!().tag()} dir={intl!().direction()}>
<head>
<meta charset="utf-8" />
{Styles.style}
</head>
<body>
<LanguageContext value={store}>{...children}</LanguageContext>
</body>
</html>
</>
}A component reads the context with use_context! and calls intl!() in its holes:
import pf.Html
import pf.Solid exposing [create_signal!, use_context!]
import intl.Language
## A basket: its title and how many things are in it, in the reader's language, and the picker
## that switches it. Each hole that calls `intl!()` is written again when the reader picks another
## locale; nothing else runs.
Basket := [].{
view! : {} => Html
view! = |{}| {
{ intl!, .. } = use_context!(Language.language_context)
(count!, set_count!) = create_signal!(3)
<section class="basket">
<Language label="Language" />
<h1>{intl!().t("title", [])}</h1>
<p>{intl!().t("items", [("count", Int(count!()))])}</p>
<p>{intl!().currency(1234.5, "EUR")} · {intl!().date(1795273445000, Long)} · {intl!().relative(-2, Hour)}</p>
<p>{intl!().issue("too_short", [{ name: "min", value: count!().to_str() }])}</p>
<button on:click={|| set_count!(count!() + 1)}>+</button>
</section>
}
}Picking a language switches the page at once, then calls remember!. Here it sends the tag to an app endpoint that sets the locale cookie, so the next page is in it too. Its post! sets the cookie on an answer of its own, Answer(…):
import pf.Server
import pf.Endpoint
import intl.Intl
import intl.Locale
import ../../I18n
## GET /locale: the request's locale: its `locale` cookie (the reader's own choice), else what its
## Accept-Language asks for, else English. The layout reads it as each page renders, so the browser
## hydrates in the locale the server rendered.
get! : { request : Server.Request, params : {}, context : c } => Try(Str, Endpoint.Refusal)
get! = |{ request, .. }| Ok(Intl.choose(I18n.supported, Locale.wanted(request, "locale")).tag())
## POST /locale, `tag=pl` (a form) or `{"tag":"pl"}` (the picker): keeps the reader's choice in the
## `locale` cookie for a year. A form's post goes back to the page it came from.
post! : { request : Server.Request, params : {}, context : c, body : { tag : Str } } => Try({}, Endpoint.Refusal)
post! = |{ request, body, .. }|
match Locale.parse(body.tag) {
Ok(locale) => {
kept = |answer| Server.set_cookie(answer, "locale", locale.tag(), { ..Server.cookie_defaults, max_age_s: 365 * 86400 })
if Server.wants_html(request) {
Err(Answer(kept(Server.redirect(Server.header(request, "referer") ?? "/"))))
} else {
Err(Answer(kept(Server.response(204, [], ""))))
}
}
Err(_) => Err(BadRequest("not a language tag: ${body.tag}"))
}Language | Is |
|---|---|
Store | what the context holds: intl! : () => Intl, the reader's; choose! : Str => {}, to choose another; and supported : List(Locales.Data), the choices |
language_context | the context: <LanguageContext value={store}> provides it, use_context!(Language.language_context) reads it |
store!({ supported, catalog, tag, remember! }) | a store in tag's locale (the closest supported one; a string that isn't a tag gets the default); its choose!(tag) switches it and calls remember!(tag) |
<Language label={…} /> | a <select> of the supported locales, each named in its own language ("English", "polski", "العربية"), the reader's chosen; label names it for screen readers; its class is language |
These four files are from packages/intl/example, a small app that builds on both platforms (rocx dev packages/intl/example). It renders in Polish for Accept-Language: pl, and in Arabic, right to left, for a locale=ar cookie.
The component: packages/intl/components/Language.rocx
import pf.Html
import pf.Solid exposing [create_signal_with!, use_context!]
import pf.Context
import intl.Intl
import intl.Catalog
import intl.Locales
## The reader's language, for every component under it, as a Solid context: an `Intl` that changes
## when the reader picks another locale, so each hole that reads it is written again in the new
## language, and nothing else is. `<Language label="Language" />` is the picker.
##
## # the root layout: the store, given to everything inside
## store = Language.store!({ supported, catalog, tag: Api.get_locale({}).read!(), remember!: |_| {} })
## { intl!, .. } = store
## <html lang={intl!().tag()} dir={intl!().direction()}>
## …<body><LanguageContext value={store}>{...children}</LanguageContext></body>
## </html>
##
## # any component under it
## { intl!, .. } = use_context!(Language.language_context)
## <p>{intl!().t("cart.items", [("count", Int(count!()))])}</p>
##
## `tag` is the locale the server chose for the request (a GET endpoint's answer, read as the page
## renders, so the browser hydrates in the same one). `remember!` is called with each tag the
## reader picks, to keep it (in a cookie).
Language := [].{
## What the context holds: the reader's `Intl`, a way to choose another, and the choices.
Store : { intl! : () => Intl, choose! : Str => {}, supported : List(Locales.Data) }
language_context : Context(Store)
language_context = create_context()
## A store, in `tag`'s locale (the closest supported one).
store! : { supported : List(Locales.Data), catalog : Catalog, tag : Str, remember! : Str => {} } => Store
store! = |{ supported, catalog, tag, remember! }| {
(intl!, set_intl!) = create_signal_with!(Intl.for_tag(supported, tag).with_catalog(catalog), { equals: |_, _| Bool.False })
choose! = |wanted| {
set_intl!(Intl.for_tag(supported, wanted).with_catalog(catalog))
remember!(wanted)
}
{ intl!: intl!, choose!: choose!, supported: supported }
}
## A picker of the supported locales, each named in its own language ("English", "polski",
## "العربية"), the reader's chosen. Picking one switches the page at once. `label` names it for
## screen readers.
view! : { label : Str } => Html
view! = |{ label }| {
{ intl!, choose!, supported } = use_context!(language_context)
<select class="language" aria-label={label} on:input.value={choose!}>
{...supported.map(|data|
<option key={data.tag} value={data.tag} lang={data.tag} selected?={data.tag == intl!().tag()}>{data.name}</option>
)}
</select>
}
<style>
.language {
font: inherit;
}
</style>
}Formatting#
Intl.new(Locales.pl) makes an Intl for one locale, Intl.choose(supported, wanted) for the closest of several, and Intl.for_tag(supported, tag) for a tag (a cookie's). Numbers are Dec, Roc's decimal, rounded half away from zero. A moment is milliseconds since the epoch, written in UTC or at a fixed offset (intl.in_offset(60) for Central European winter time).
| Call | English | Polish |
|---|---|---|
number(1234.5) | 1,234.5 | 1234,5 (from five digits, Polish groups them) |
number(-1234567.891) | -1,234,567.891 | -1 234 567,891 |
fixed(2.5, 2) | 2.50 | 2,50 |
int(12345) | 12,345 | 12 345 |
percent(0.256, 1) | 25.6% | 25,6% |
compact(1234), compact(12345678) | 1.2K, 12M | 1,2 tys., 12 mln |
currency(1234.5, "EUR") | €1,234.50 | 1234,50 € |
currency(1234.5, "PLN") | PLN 1,234.50 | 1234,50 zł |
date(moment, Short) | 11/21/26 | 21.11.2026 |
date(moment, Medium) | Nov 21, 2026 | 21 lis 2026 |
date(moment, Long) | November 21, 2026 | 21 listopada 2026 |
date(moment, Full) | Saturday, November 21, 2026 | sobota, 21 listopada 2026 |
time(moment, Short) | 3:04 PM | 15:04 |
date_time(moment, Long, Short) | November 21, 2026 at 3:04 PM | 21 listopada 2026 15:04 |
day(Date.ymd(2026, 1, 5), Long), a day with no time | January 5, 2026 | 5 stycznia 2026 |
month_year(Date.ymd(2026, 11, 1)) | November 2026 | listopad 2026 |
month_name(11), weekday_name(6) | November, Saturday | listopad, sobota |
relative(-3, Day) | 3 days ago | 3 dni temu |
relative(2, Hour) | in 2 hours | za 2 godziny |
relative_day(-1) | yesterday | wczoraj |
ago(then, now), five minutes apart | 5 minutes ago | 5 minut temu |
plural(22) | other | few |
ordinal(23) | few ("23rd") | other |
tag(), name(), direction() | en, English, ltr | pl, polski, ltr |
number_with(x, options) takes the fraction digits and grouping ({ ..NumberFormat.defaults, min_fraction: 2 }). ago picks the unit: seconds under a minute, then minutes, hours, days (under a week), weeks (under 30 days), months (under a year), years. Arabic follows CLDR 48: Latin digits, invisible marks that keep right-to-left text in order, and its dual without a digit ("خلال ساعتين", "in two hours").
Messages#
A catalog holds keyed messages for each locale, one locale the default: Catalog.new("en", [("en", [(key, message), …]), ("pl", […])]), as in I18n.rocx above. intl.t(key, args) looks a key up in the reader's locale, then its fallbacks (pl-PL, then pl), then the default. So a regional set (en-GB) holds only what differs, and a missing translation shows the default's words. A key no set has shows as itself, so you spot it.
The demo's message, files, in five languages, and what t("files", [("count", Int(n))]) says for a few counts. Each language has its own plural categories: German two, Polish four (and =0), Arabic six, Japanese one.
## The demo's message, `files`, in each of its languages. The demo itself has none: a message
## would add about 13 KB to the site's wasm, so the page shows this one as it is written here,
## at build time.
files_catalog : Catalog
files_catalog = Catalog.new(
"en",
[
("en", [("files", "{count, plural, =0 {No files} one {# file} other {# files}}")]),
("de", [("files", "{count, plural, =0 {Keine Dateien} one {# Datei} other {# Dateien}}")]),
("pl", [("files", "{count, plural, =0 {Brak plików} one {# plik} few {# pliki} many {# plików} other {# pliku}}")]),
("ar", [("files", "{count, plural, zero {لا ملفات} one {ملف واحد} two {ملفان} few {# ملفات} many {# ملفًا} other {# ملف}}")]),
("ja", [("files", "{count, plural, other {# 件のファイル}}")]),
],
)
## The message `files` for `count` files, as `data`'s locale writes it.
files : Locales.Data, I64 -> Str
files = |data, count| Intl.new(data).with_catalog(IntlSamples.files_catalog).t("files", [("count", Int(count))])n | en | de | pl | ar | ja |
|---|---|---|---|---|---|
0 | No files | Keine Dateien | Brak plików | لا ملفات | 0 件のファイル |
1 | 1 file | 1 Datei | 1 plik | ملف واحد | 1 件のファイル |
2 | 2 files | 2 Dateien | 2 pliki | ملفان | 2 件のファイル |
3 | 3 files | 3 Dateien | 3 pliki | 3 ملفات | 3 件のファイル |
5 | 5 files | 5 Dateien | 5 plików | 5 ملفات | 5 件のファイル |
11 | 11 files | 11 Dateien | 11 plików | 11 ملفًا | 11 件のファイル |
22 | 22 files | 22 Dateien | 22 pliki | 22 ملفًا | 22 件のファイル |
100 | 100 files | 100 Dateien | 100 plików | 100 ملف | 100 件のファイル |
Messages use a subset of ICU MessageFormat, which translators' tools read and write. Arguments are name–value pairs: ("name", Text("Ada")), ("count", Int(3)), ("price", Num(9.99)) or ("when", Moment(ms)).
| Message | With | Is |
|---|---|---|
Hello, {name}! | name: Ada | Hello, Ada! |
{count, plural, =0 {No files} one {# file} other {# files}} | count: 0, 1, 1234 | No files · 1 file · 1,234 files |
{place, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} | place: 1, 22, 13 | 1st · 22nd · 13th |
{role, select, admin {Administrator} other {Member}} | role: admin, guest | Administrator · Member |
{guests, plural, offset:1 =0 {Nobody} =1 {{host}} one {{host} and # other} other {{host} and # others}} | host: Ada, guests: 3 | Ada and 2 others |
{total, number} · {share, number, percent} | total: 1234.5, share: 0.25 | 1,234.5 · 25% |
{when, date, long} at {when, time, short} | when: moment | November 21, 2026 at 3:04 PM |
It''s '{literal}' | It's {literal} |
A plural's cases are the locale's plural categories (zero, one, two, few, many, other); other is required. English has two, Polish four. For {count, plural, one {# plik} few {# pliki} many {# plików} other {# pliku}}:
| With | Is | Because |
|---|---|---|
count: 1 | 1 plik | one |
count: 3 | 3 pliki | few: 2–4, 22–24… |
count: 5 | 5 plików | many: the other whole numbers |
count: 12 | 12 plików | many: 12–14 too |
count: 22 | 22 pliki | few |
count: 2.5 | 2,5 pliku | other: a fraction |
Catalog.problems(catalog) lists what a translator still has to fix: a key missing from a locale, a key the default lacks, a message that can't be read (shown as written), and arguments that differ from the default's. Add expect Catalog.problems(I18n.catalog) == [] to your app's tests. For this catalog:
## A catalog with mistakes in it: what `Catalog.problems` finds.
typos : Catalog
typos = Catalog.new(
"en",
[
("en", [("hello", "Hello, {name}!"), ("cart", "{count, plural, one {# item} other {# items}}"), ("colour", "Colour")]),
("pl", [("hello", "Cześć, {imie}!"), ("cart", "{count, plural, one {# produkt} few {# produkty} other {# produktów}"), ("extra", "Nadmiar")]),
],
)- pl has no "colour" yet (the default's is shown)
- pl's "hello" reads {imie} where the default's reads {name}
- pl's "extra" isn't a key of the default's: misspelt, or no longer used?
- pl's "cart" can't be read, so it is shown as written: at 69, `count`'s plural is never closed
A form's errors#
packages/forms gives each issue a key and parameters: Issues.key(code) is "too_short", Issues.params(code) is [{ name: "min", value: "3" }]. intl.issue(key, params) says it in the reader's language from Validation.catalog, which words all nineteen of forms' keys in every starter locale, in forms' voice ("Use at least 3 characters"). Merge it under the app's catalog (Catalog.merge(Validation.catalog, words)), as I18n.rocx does. To reword a key, or word one of your own (a Custom issue's), put validation.<key> in the app's catalog (validation.not_postcode).
| Key | Params | English | Polish |
|---|---|---|---|
required | (none) | Fill this in | Wypełnij to pole |
too_short | min: 3 | Use at least 3 characters | Wpisz co najmniej 3 znaki |
too_short | min: 5 | Use at least 5 characters | Wpisz co najmniej 5 znaków |
too_large | max: 1500.5 | Enter 1,500.5 or less | Wpisz 1500,5 lub mniej |
too_early | min: 2026-01-31 | Enter Jan 31, 2026 or later | Wpisz 31 sty 2026 lub późniejszą datę |
not_email | (none) | Enter an email address, like name@example.com | Wpisz adres e-mail, np. name@example.com |
A number in the params picks the plural and is written the locale's way; a day (too_early, too_late) as the locale writes dates.
The modules#
Plain Roc, on no platform. roc test packages/intl/main.roc runs their expects. The README has every function.
| Module | What it does |
|---|---|
Intl | one locale's way of writing things, and its messages: new, choose, for_tag, with_catalog, in_offset, the functions above, t, format (a message given inline), translated, issue, error |
Locale | a BCP 47 tag: Locale.parse("EN_us") is en-US; fallbacks; accept_language(header); best(wanted, supported, default); wanted(request, cookie) |
Locales | each starter locale's data: en, en_gb, de, fr, es, pl, cs, ru, ar, ja, and all |
Plural | CLDR's categories, each language's cardinal and ordinal rules, and Forms, a word for each category |
NumberFormat | numbers by a locale's Symbols: grouping, fraction digits (Options, defaults), percent, compact, currency |
Date | a day on the calendar: Date.ymd(2026, 11, 21), days since 1970, weekdays, adding days and months, parse_iso, to_iso |
DateFormat | dates and times by CLDR's patterns (d MMMM y), in four styles |
RelativeTime | "in 3 days", "3 dni temu"; between(ms), the unit a difference is said in |
Message | the ICU subset above: parse, format, names, Arg |
Catalog | messages for each locale: new, empty, add, merge, find, keys, missing, problems, explain |
Validation | the words for packages/forms' issues, in every starter locale |
Locale data and size#
tools/locales.mjs writes packages/intl/Locales.roc from the CLDR in Node's ICU: the symbols, patterns and names for numbers, money, dates and times, and relative-time words for each plural category. Plural rules are code, in Plural.roc. To add a locale, add it to the script's list (with its plural rules if the language is new), run the script, and format the package with rocx fmt.
An app's wasm holds only the locales it names, under 1 KB (brotli) each. The code is the larger part and grows with what the app calls. Measured on 2026-11-21, before the browser's host moved to Rust: numbers alone added 12.6 KB to a small app, all the formatting 22.1 KB, and messages too 34.5 KB. The demo above added about 17 KB to this site's wasm (the store, the picker, numbers, money, dates and relative times in five locales; three would have saved 1.2 KB).
Status#
Works today, tested for the ten starter locales: everything above. The example app renders on the server, hydrates, switches language in place and keeps the choice in a cookie (checked by hand; it has no tests of its own).
Not yet (each has a proposal in packages/intl/PROPOSALS.md):
- The app writes the server's side: the endpoint that answers the locale and keeps a choice (as above), and any middleware that sends
Content-Language. - Message keys are strings, so the compiler doesn't check them. A build step that writes a function for each key from message files would.
- Time is UTC or a fixed offset. Named time zones, which follow summer time, need a host primitive.
- More locales and fuller data (CLDR's parent locales such as
en-001, other digits, long compact forms) wait on a generator that reads cldr-json.