How to use make-plural-compiler - 10 common examples

To help you get started, we’ve selected a few make-plural-compiler 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 TrigenSoftware / i18n-for-browser / src / index.ts View on Github external
}
	}

	translated = translate(config, locale, singular, plural);

	// find the correct plural rule for given locale
	if (typeof translated === 'object') {

		let p = null;

		// create a new Plural for locale
		// and try to cache instance
		if (pluralsInstanceForLocale[locale]) {
			p = pluralsInstanceForLocale[locale];
		} else {
			MakePlural.load(plurals);
			p = new MakePlural(locale).compile();
			pluralsInstanceForLocale[locale] = p;
		}

		// fallback to 'other' on case of missing translations
		translated = translated[p(countNumber)] || translated.other;
	}

	// Accept an object with named values as the last parameter
	if (typeof values[values.length - 1] === 'object') {
		namedValues = values.pop();
	}

	return postProcess(config, translated, namedValues, values, countNumber);
}
github TrigenSoftware / i18n-for-browser / src / index.ts View on Github external
}

	translated = translate(config, locale, singular, plural);

	// find the correct plural rule for given locale
	if (typeof translated === 'object') {

		let p = null;

		// create a new Plural for locale
		// and try to cache instance
		if (pluralsInstanceForLocale[locale]) {
			p = pluralsInstanceForLocale[locale];
		} else {
			MakePlural.load(plurals);
			p = new MakePlural(locale).compile();
			pluralsInstanceForLocale[locale] = p;
		}

		// fallback to 'other' on case of missing translations
		translated = translated[p(countNumber)] || translated.other;
	}

	// Accept an object with named values as the last parameter
	if (typeof values[values.length - 1] === 'object') {
		namedValues = values.pop();
	}

	return postProcess(config, translated, namedValues, values, countNumber);
}
github eemeli / make-plural / test / plural-data.js View on Github external
it('has autogenerated tests', function() {
    const mpc = new MakePlural(lc, opt)
    expect(() => mpc.compile()).to.not.throw()
    expect(mpc.tests[type]).to.not.be.empty
  })
github eemeli / make-plural / test / compiler.js View on Github external
it('should not validate bad functions', function() {
      var cldr = {
          supplemental: {
            'plurals-type-cardinal': {
              xx: {
                'pluralRule-count-one': 'n = 1 @integer 2',
                'pluralRule-count-other': ''
              }
            }
          }
        },
        prevRules = MakePlural.rules
      MakePlural.load(cldr)
      var mpc = new MakePlural('xx')
      var mp = mpc.compile()
      expect(mpc.test).to.throw(/self-test failed/)
      MakePlural.rules = prevRules
    })
  })
github eemeli / make-plural / test / plural-data.js View on Github external
function testPluralData(type, lc, getPlural) {
  var opt = { cardinals: type == 'cardinal', ordinals: type == 'ordinal' }

  it('has autogenerated tests', function() {
    const mpc = new MakePlural(lc, opt)
    expect(() => mpc.compile()).to.not.throw()
    expect(mpc.tests[type]).to.not.be.empty
  })

  it('is included in the output', function() {
    expect(getPlural(lc)).to.be.an.instanceOf(Function)
  })

  var mpc = new MakePlural(lc, opt)
  var mp = mpc.compile()
  for (var cat in mpc.tests[type]) {
    describe(
      cat + ': ' + MakePlural.rules[type][lc]['pluralRule-count-' + cat],
      function() {
        ;(function(cat) {
          it('Live data', function() {
            var test = mpc.tests.testCat.bind(mpc.tests)
            expect(() => test(type, cat, mp)).to.not.throw()
          })
          it('Output', function() {
            var test = mpc.tests.testCat.bind(mpc.tests)
            expect(() => test(type, cat, getPlural(lc))).to.not.throw()
          })
        })(cat)
      }
github eemeli / make-plural / test / compiler.js View on Github external
it('should handle local options', function() {
      var mp = new MakePlural('en', { ordinals: true }).compile()
      expect(mp(2, true)).to.equal('two')
    })
    it('should handle global options', function() {
github eemeli / make-plural / test / compiler.js View on Github external
it('should validate default functions', function() {
      var mpc = new MakePlural('en', { ordinals: true })
      var mp = mpc.compile()
      expect(() => mpc.test()).not.to.throw()
    })
    it('should not validate bad functions', function() {
github eemeli / make-plural / test / compiler.js View on Github external
it('should return rules for "cardinal", "en"', function() {
      var en = MakePlural.getRules('cardinal', 'en')
      expect(en).to.be.an('object')
      expect(en).to.have.keys('pluralRule-count-one', 'pluralRule-count-other')
    })
    it('should return the same rules for "cardinal", "EN"', function() {
github eemeli / make-plural / test / compiler.js View on Github external
it('should return the same rules for "cardinal", "EN"', function() {
      var en = MakePlural.getRules('cardinal', 'en')
      var EN = MakePlural.getRules('cardinal', 'EN')
      expect(EN).to.equal(en)
    })
  })
github eemeli / make-plural / test / compiler.js View on Github external
it('should return the same rules for "cardinal", "EN"', function() {
      var en = MakePlural.getRules('cardinal', 'en')
      var EN = MakePlural.getRules('cardinal', 'EN')
      expect(EN).to.equal(en)
    })
  })