How to use the @phensley/plurals.pluralRules.get function in @phensley/plurals

To help you get started, we’ve selected a few @phensley/plurals 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 / src / resource / bundle.ts View on Github external
constructor(
    readonly _id: string,
    readonly _tag: LanguageTag,
    readonly strings: string[],
    readonly exceptions: string[],
    readonly index: ExceptionIndex,
    readonly _spellout: any
  ) {
    const language = _tag.language();
    this._languageRegion = `${language}-${_tag.region()}`;
    this._languageScript = `${language}-${_tag.script()}`;
    this._plurals = pluralRules.get(language, _tag.region());

    // When bundle is constructed, see if there are unicode extensions for
    // number and calendar systems.
    for (const subtag of _tag.extensionSubtags('u')) {
      if (subtag.startsWith('nu-')) {
        this._numberSystem = subtag.substring(3);
      } else if (subtag.startsWith('ca-')) {
        this._calendarSystem = subtag.substring(3);
      }
    }
  }
github phensley / cldr-engine / packages / cldr-ext-rbnf / src / algorithmic.ts View on Github external
import { Decimal } from '@phensley/decimal';
import { pluralRules, PluralRules } from '@phensley/plurals';
import { algorithmicNumbering } from './autogen.names';
import { rbnfRulesets } from './autogen.rbnf';
import { RBNF, RBNFDecimalFormatter, RBNFSet, RBNFSymbols } from './rbnf';

const U = undefined;
const ROOT = new RBNF(pluralRules.get('root'), rbnfRulesets);
const RBNFROOT = ROOT.get('root')!;

export class AlgorithmicNumberingSystems {

  readonly rbnfset: RBNFSet | undefined;
  readonly rulenames: string[] = [];

  constructor(plurals: PluralRules, spellout: any, ...ids: string[]) {
    const rbnf = new RBNF(plurals, spellout);

    // Find the first defined system. This lets us check if a region-specific
    // system exists, falling back to the language-script.
    for (const id of ids) {
      this.rbnfset = rbnf.get(id);
      if (this.rbnfset) {
        this.rulenames = this.rbnfset.pubnames;
github phensley / cldr-engine / packages / messageformat / src / formatter.ts View on Github external
constructor(options: MessageFormatterOptions = { }) {
    this.formatters = options.formatters || {};
    this.plurals = options.plurals || pluralRules.get(options.language || 'root', options.region);
    const size = options.cacheSize || DEFAULT_CACHE_SIZE;
    this.matcher = buildMessageMatcher(Object.keys(this.formatters));
    this.cache = new Cache(s => parseMessagePattern(s, this.matcher), size);
  }
github phensley / cldr-engine / packages / cldr-core / __benchmarks__ / messages / index.ts View on Github external
} 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 / messageformat / example.ts View on Github external
const plurals = (language: string, region?: string) =>
  pluralRules.get(language, region);

@phensley/plurals

Plural rules engine

Apache-2.0
Latest version published 17 days ago

Package Health Score

60 / 100
Full package analysis

Popular @phensley/plurals functions

Similar packages