How to use the @phensley/messageformat.MessageFormatter function in @phensley/messageformat

To help you get started, we’ve selected a few @phensley/messageformat 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 phensley / cldr-engine / packages / cldr-core / __benchmarks__ / messages / index.ts View on Github external
MessageEngine,
  MessageFormatter,
} from '@phensley/messageformat';

export const messageSuite: Suite = makeSuite('message');

const FORMATTERS = {
  foo: (args: MessageArg[], options: string[]) =>
    options[0] === 'upper' ? args[0].toUpperCase() : args[0].toLowerCase()
};

const MESSAGE = 'foo bar {0 plural one {# item} other {# items}} {1}';
const MATCHER = buildMessageMatcher(Object.keys(FORMATTERS));
const CODE = parseMessagePattern(MESSAGE, MATCHER);

const FORMATTER = new MessageFormatter({ language: 'en', formatters: FORMATTERS });

const PLURALS = pluralRules.get('en');

messageSuite.add('parse', () => {
  parseMessagePattern(MESSAGE, MATCHER);
});

messageSuite.add('eval', () => {
  new MessageEngine(PLURALS, FORMATTERS, CODE).evaluate([12, 'hello']);
});

messageSuite.add('formatter', () => {
  FORMATTER.format(MESSAGE, [12, 'hello'], {});
});
github phensley / cldr-engine / packages / cldr-core / src / api / general.ts View on Github external
messageFormatter(options?: MessageFormatterOptions): MessageFormatter {
    const plurals = this._bundle.plurals();
    return new MessageFormatter({ ...options, plurals });
  }

@phensley/messageformat

Extensible ICU message formatter

Apache-2.0
Latest version published 14 days ago

Package Health Score

60 / 100
Full package analysis

Similar packages