UNPKG

@messageformat/icu-messageformat-1

Version:

Compile ICU MessageFormat 1 sources into MessageFormat 2 formatters

28 lines (27 loc) 1.26 kB
import { Token } from '@messageformat/parser'; import { type Model as MF, MessageFormat, MessageFormatOptions } from 'messageformat'; export type MF1Options = { /** See {@link https://messageformat.github.io/messageformat/api/parser.parseoptions/ ParseOptions.strict} in @messageformat/parser */ strict?: boolean; }; /** * Compile an ICU MessageFormat 1 message into a {@link MessageFormat} instance. * * ```js * import { mf1ToMessage } from '@messageformat/icu-messageformat-1'; * * const msg = mf1ToMessage('en', 'The total is {V, number, ::currency/EUR}.'); * msg.format({ V: 4.2 }); * ``` * * ```js * 'The total is €4.20.' * ``` * * @param locales - The locale to use for the message. * @param source - An ICU MessageFormat message, either in its syntax representation, * as an array of `@messageformat/parser` {@link https://messageformat.github.io/messageformat/api/parser.parse/ | AST tokens}, * or as a {@link MF.Message | Model.Message} data structure. * @param options - See {@link MF1Options} and {@link MessageFormatOptions} */ export declare function mf1ToMessage(locales: string | string[] | undefined, source: string | Token[] | MF.Message, { strict, ...opt }?: MF1Options & MessageFormatOptions): MessageFormat;