plurals-cldr
Plurals suport, generated from CLDR.
Last updated 5 months ago by vitaly .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install plurals-cldr 
SYNC missed versions from official npm registry.

plurals-cldr - plurals support for JS

Build Status NPM version Coverage Status

Key benefits:

  • Competely automated code generation from CLDR on update.
  • Generated code automatically tested with CLDR fixtures.
  • Both cardinal and ordinal forms support.
  • Rules for all languages are stored in single file in very compact form.

Installation

node.js:

$ npm install plurals-cldr

browser:

$ bower install plurals-cldr

Rebuild

make clean
make generate

API

.(locale, number)

Returns form name for given number. Number can be passed as string to keep tailing decimal zeros. If locale not supported, returns null.

var plural = require('plural-cldr');

// Get cardinal form name
//
// Params:
//
// - locale
// - number (Number|String)
//
plural('ru', 0)   // -> 'many'
plural('ru', 1)   // -> 'one'
plural('ru', 2)   // -> 'few'
plural('ru', 19)  // -> 'many'
plural('ru', 0.5) // -> 'other'

.forms(locale)

Returns array of available forms for specified locale. If locale not supported, returns null.

.indexOf(locale, number)

Returns index of form for specified locale. That's convenient, if you wish to implement lookup from compact ordered list, like babelfish does.

If locale not supported, function returns -1.

Order of forms is the same for all languages: zero, one, two, few, many, other. Remove unavailable forms, and you will get indexes of each.

.ordinal(), .ordinal.forms(), ordinal.indexOf()

The same as above, but for ordinal forms.

References

  1. CLDR downloads
  2. Latest chart
  3. Syntax description

License

Mit.

Current Tags

  • 1.0.4                                ...           latest (5 months ago)

5 Versions

  • 1.0.4                                ...           5 months ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 10
Last Day 0
Last Week 7
Last Month 18
Dependencies (0)
None
Dev Dependencies (8)

Copyright 2014 - 2016 © taobao.org |