MessageFormat.compile() method

Compile a message into a function

Signature:

compile(message: string): MessageFunction<ReturnType>;

Parameters

Parameter Type Description
message string The input message to be compiled, in ICU MessageFormat

Returns:

MessageFunction<ReturnType>

The compiled function

Remarks

Given a string message with ICU MessageFormat declarations, the result is a function taking a single Object parameter representing each of the input’s defined variables, using the first valid locale.

Example

const mf = new MessageFormat('en')
const msg = mf.compile('A {TYPE} example.')

msg({ TYPE: 'simple' })  // 'A simple example.'