Unicode MessageFormat for JavaScript
    Preparing search index...
    • Convert an ICU MessageFormat 1 message into a Model.Message data object.

      If the source message contains any inner selectors, they will be lifted into a single top-level selector.

      Only literal values are supported in formatter parameters. Any unsupported argStyle value will be included as a Model.Options value.

      import { mf1ToMessageData, mf1Validate } from '@messageformat/icu-messageformat-1';
      import { parse } from '@messageformat/parser';

      const mf1Msg = parse('The total is {V, number, ::currency/EUR}.');
      const mf2Msg = mf1ToMessageData(mf1Msg);
      mf1Validate(mf2Msg);
      mf2msg;
      {
      type: 'message',
      declarations: [],
      pattern: [
      'The total is ',
      {
      type: 'expression',
      arg: { type: 'variable', name: 'V' },
      functionRef: {
      type: 'function',
      name: 'mf1:currency',
      options: Map(1) { 'currency' => { type: 'literal', value: 'EUR' } }
      },
      attributes: Map(2) {
      'mf1:argType' => { type: 'literal', value: 'number' },
      'mf1:argStyle' => { type: 'literal', value: '::currency/EUR' }
      }
      },
      '.'
      ]
      }

      Parameters

      • ast: Token[]

        An ICU MessageFormat message as an array of @messageformat/parser AST tokens.

      Returns Model.Message