Skip to content

ICU syntax

Sam A. Horvath-Hunt edited this page Oct 10, 2022 · 2 revisions

intlc supports most common ICU syntax with some optional extras.

Plaintext

Hello, world!

Anything not included in brace-denoted interpolations is parsed as plaintext. Escaping is supported as per the ICU 4.8+ spec.

Strings

{name}

String interpolations don't require an explicit type annotation.

Numbers

{age, number}

❎ Number skeletons are not yet supported.

Dates & times

{today, date, medium}: {now, time, short}

A format is required. Valid values are short, medium, long, and full.

❎ Date and time skeletons are not yet supported.

Selects

A {day, select, Friday {great} Monday {less great} other {}} day

🌟 Unlike other implementations targeting TypeScript, intlc will output a string literal union if a wildcard (other) is not provided.

Plurals

{numStars, plural, one {# person likes} other {# people like}} intlc

Both plural and selectordinal, representing cardinal and ordinal pluralization respectively, are supported. The # shorthand syntax to reference the same interpolated value is supported.

🌟 Unlike other implementations targeting TypeScript, intlc will output a number literal union if a wildcard (other) is not provided. This is only supported and semantically reasonable with cardinal plural.

Callbacks

Hello <bold>{name}</bold>

The above example compiles a little differently depending upon the targeted backend. With a ts backend bold will be string -> string, whereas with a tsx backend it will be ReactElement -> ReactElement.

🌟 Booleans

{isSubscribed, boolean, true {Manage} false {Subscribe}}

The boolean type is in practice similar to select with true and false cases, particularly in intlc where a wildcard is not required. Its addition is simply to avoid the need to cast boolean to 'true' | 'false' at call sites.

Clone this wiki locally