gampleman/elm-translate-icu/1.0.0

Icu.Format

Format a parsed ICU Message into a String, using the browser Intl API (via anmolitor/intl-proxy) for locale-correct plural selection and number/date formatting.

You obtain the Intl value once at startup by decoding a flag with Intl.decode, passing window.Intl in through JavaScript.

format : Intl -> Locale -> Args -> Message -> String

Format a message for a locale with the given arguments.

Icu.Format.format intl
    locale
    (Icu.Format.args |> Icu.Format.string "name" "Alice")
    message
formatWith : Intl -> Locale -> Dict String Value -> Message -> String

Like format, but takes the argument dictionary directly. Useful for generated code that already has a Dict String Value.

type Args

A collection of named argument values to substitute into a message. Build one with args and the value helpers.

An empty argument set to pipe values into.

Icu.Format.args
    |> Icu.Format.string "name" "Alice"
    |> Icu.Format.int "count" 3
string : String -> String -> Args -> Args

Bind a string argument (for {name} and select).

int : String -> Int -> Args -> Args

Bind an integer argument (for number, plural, selectordinal).

float : String -> Float -> Args -> Args

Bind a floating-point argument (for number and plural).

time : String -> Posix -> Args -> Args

Bind a time argument (for date and time).