Skip to content

Formatting

Formatting uses the platform’s Intl, so no locale data ships. Formatters are cached. A locale Intl has no data for, such as fur, formats like the first of its fallbacks it knows.

{
"price": "Total: {$amount :currency currency=EUR}",
"distance": "Distance: {$km :unit unit=kilometer}",
"views": "Views: {$views :number notation=compact}",
"day": "Date: {$when :date style=full}"
}

Loading…

MF2 ICU Intl
:number {n, number} NumberFormat
:integer {n, number, integer} NumberFormat, maximumFractionDigits: 0
:currency currency=… {n, number, ::currency/EUR} NumberFormat, style: 'currency'
:percent {n, number, percent} NumberFormat, style: 'percent': 0.25 → 25%
:unit unit=… {n, number, ::unit/kilometer} NumberFormat, style: 'unit'
:date {d, date, medium} DateTimeFormat, dateStyle, default medium
:time {d, time, short} DateTimeFormat, timeStyle, default short
:datetime – dateStyle: 'medium', timeStyle: 'short'
{$x}, no function {x} Numbers and dates with the locale’s defaults

Intl’s other options work too: minimumFractionDigits=2, notation=compact, unitDisplay=long, timeZone=UTC. An option or value Intl would reject fails the build. An option may read a param too, currency=$code, which the call then needs.

Function Param type
Number ones number
Date ones Date | number
:string string

An invalid date, such as new Date('soon'), or an unknown timeZone throws a RangeError when the message is called, as in Intl: check data you do not control first.

Declare it in the config; implement it on the instance:

parla.config.ts
functions: { capitalize: 'string' },
// the app
createParla({
catalog,
functions: { capitalize: ({ value, locale }) => String(value).toLocaleUpperCase(locale) },
});
{ "shout": "{$name :capitalize}!" }

A function gets { value, options, locale, locales }; pass locales, the locale then its fallbacks, to Intl. createParla requires every declared function. Built-in names cannot be redefined.