How to use the intl-messageformat-parser.parse function in intl-messageformat-parser

To help you get started, we’ve selected a few intl-messageformat-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github elastic / kibana / src / dev / i18n / utils.js View on Github external
export function extractValueReferencesFromMessage(message, messageId) {
  // Skip validation if message doesn't use ICU.
  if (!message.includes('{')) {
    return [];
  }

  let messageAST;
  try {
    messageAST = parser.parse(message);
  } catch (error) {
    if (error.name === 'SyntaxError') {
      const errorWithContext = createParserErrorMessage(message, {
        loc: {
          line: error.location.start.line,
          column: error.location.start.column - 1,
        },
        message: error.message,
      });

      throw createFailError(
        `Couldn't parse default message ("${messageId}"):\n${errorWithContext}`
      );
    }

    throw error;
github formatjs / react-intl / test / perf / index.tsx View on Github external
many {{var0, number} message} 
      other {{var0, number} messages}
    }`;
    formattedMessages.push(
      
    );
  }

  ReactDOMServer.renderToString(
    
      {formattedMessages}
    
  );
});

const cachedAst = parse(
  `{var0, plural, 
    zero {{var0, number} message} 
    one {{var0, number} message} 
    few {{var0, number} message} 
    many {{var0, number} message} 
    other {{var0, number} messages}
  }`
);
suite.add(
  '100 x  with placeholder, cached in AST form',
  function() {
    let messages: Record = {};
    let formattedMessages = [];
    for (let i = 0, len = 100; i < len; i += 1) {
      messages[i] = cachedAst;
      formattedMessages.push(
github formatjs / react-intl / test / unit / format.ts View on Github external
config = {
      locale: 'en',

      messages: {
        no_args: 'Hello, World!',
        with_arg: 'Hello, {name}!',
        with_named_format: 'It is {now, date, year-only}',
        with_html: 'Hello, <b>{name}</b>!',

        missing: undefined,
        empty: '',
        invalid: 'invalid {}',
        missing_value: 'missing {arg_missing}',
        missing_named_format: 'missing {now, date, format_missing}',
        ast_simple: parse('hello world'),
        ast_var: parse('hello there, {name}'),
      },

      formats: {
        date: {
          'year-only': {
            year: 'numeric',
          },
          missing: undefined,
        },

        time: {
          'hour-only': {
            hour: '2-digit',
            hour12: false,
          },
          missing: undefined,
github formatjs / react-intl / examples / translations / scripts / lib / translator.js View on Github external
translate(message) {
    let ast = parse(message);
    let translated = this.transform(ast);
    return print(translated);
  }
github reportportal / service-ui / app / localization / translator.js View on Github external
translate(message) {
    const ast = parse(message);
    const translated = this.transform(ast);
    return print(translated);
  }