How to use the cldr.extractPluralRuleFunction function in cldr

To help you get started, we’ve selected a few cldr 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 angular / angular / tools / gulp-tasks / cldr / extract.js View on Github external
function getPluralFunction(locale, withTypes = true) {
  let fn = cldr.extractPluralRuleFunction(locale).toString();

  if (fn === EMPTY_RULE) {
    fn = DEFAULT_RULE;
  }

  const numberType = withTypes ? ': number' : '';
  fn = fn.replace(/function anonymous\(n[^}]+{/g, `function plural(n${numberType})${numberType} {`)
           .replace(toRegExp('var'), 'let')
           .replace(toRegExp('if(typeof n==="string")n=parseInt(n,10);'), '')
           .replace(toRegExp('\n}'), ';\n}');

  // The replacement values must match the `Plural` enum from common.
  // We do not use the enum directly to avoid depending on that package.
  return fn.replace(toRegExp('"zero"'), ' 0')
      .replace(toRegExp('"one"'), ' 1')
      .replace(toRegExp('"two"'), ' 2')
github ember-intl / ember-intl / lib / extract.js View on Github external
function extractPluralRuleFunction(locale) {
    assert(isValidLocale(locale), 'Invalid locale');

    var fn = cldr.extractPluralRuleFunction(normalize(locale)).toString();

    // Remove unnecessary function name.
    fn = fn.replace('function anonymous(', 'function (');

    // ParseInt() is expensive given that we already know the input is a number.
    fn = fn.replace('if(typeof n==="string")n=parseInt(n,10);', 'n=Math.floor(n);');

    // js-hint asi.
    fn = fn.replace('"\n}', '";\n}');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n===11)".
    fn = fn.replace(/!\((\w+)===(\d+)\)/g, '($1!==$2)');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n%100===11)".
    fn = fn.replace(/!\((\w+)%(\d+)===(\d+)\)/g, '($1%$2!==$3)');

    // Keep it neat.
    fn = fn.replace(/\n/g, '');
github bobisjan / ember-format / blueprints / locale / index.js View on Github external
extractPluralRuleFunction: function(locale) {
    var fn = cldr.extractPluralRuleFunction(locale).toString();

    // Remove unnecessary function name.
    fn = fn.replace('function anonymous(', 'function (');

    // ParseInt() is expensive given that we already know the input is a number.
    fn = fn.replace('if(typeof n==="string")n=parseInt(n,10);', 'n=Math.floor(n);');

    // js-hint asi.
    fn = fn.replace('"\n}', '";\n}');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n===11)".
    fn = fn.replace(/!\((\w+)===(\d+)\)/g, '($1!==$2)');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n%100===11)".
    fn = fn.replace(/!\((\w+)%(\d+)===(\d+)\)/g, '($1%$2!==$3)');

    // Keep it neat.
    fn = fn.replace(/\n/g, '');
github bobisjan / ember-format / lib / tasks / format-extract.js View on Github external
extractPluralRuleFunction: function(locale) {
    var fn = cldr.extractPluralRuleFunction(locale).toString();

    // Remove unnecessary function name.
    fn = fn.replace('function anonymous(', 'function (');

    // ParseInt() is expensive given that we already know the input is a number.
    fn = fn.replace('if(typeof n==="string")n=parseInt(n,10);', 'n=Math.floor(n);');

    // js-hint asi.
    fn = fn.replace('"\n}', '";\n}');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n===11)".
    fn = fn.replace(/!\((\w+)===(\d+)\)/g, '($1!==$2)');
    // js-hint W018 "Confusing use of '!'" caused by stuff like "!(n%100===11)".
    fn = fn.replace(/!\((\w+)%(\d+)===(\d+)\)/g, '($1%$2!==$3)');

    // Keep it neat.
    fn = fn.replace(/\n/g, '');
github angular / angular / scripts / cldr / gen_plural_rules.js View on Github external
locales.forEach(locale => {
  const rule = normalizeRule(cldr.extractPluralRuleFunction(locale).toString());
  const lang = getVariantLang(locale, rule);

  if (!lang || !rule) {
    return;
  }

  if (!ruleToLang[rule]) {
    ruleToLang[rule] = [];
  } else if (ruleToLang[rule].indexOf(lang) > -1) {
    return;
  }

  ruleToLang[rule].push(lang);
});