# plurals-cldr

> Plurals support, generated from CLDR.

Latest version **2.0.1** (published 2021-11-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install plurals-cldr
pnpm add plurals-cldr
yarn add plurals-cldr
bun add plurals-cldr
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-11-30 |
| First published | 2014-12-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/plurals-cldr) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 51.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Vitaly Puzrin |
| Maintainers | vitaly |
| Keywords | i18n, l10n, plural, plurals, pluralize, pluralizer, cldr |

## Links

- npm: https://www.npmjs.com/package/plurals-cldr
- Repository: https://github.com/nodeca/plurals-cldr
- Homepage: https://github.com/nodeca/plurals-cldr#readme
- Issues: https://github.com/nodeca/plurals-cldr/issues
- Funding: https://github.com/nodeca/plurals-cldr?sponsor=1
- npm.io page: https://npm.io/package/plurals-cldr

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-11-30
- 2.0.0 — 2021-11-29
- 1.0.4 — 2020-05-18
- 1.0.3 — 2016-11-03
- 1.0.2 — 2016-01-17
- 1.0.1 — 2014-12-14
- 1.0.0 — 2014-12-14

## README

plurals-cldr - plurals support for JS
=====================================

[![CI](https://github.com/nodeca/plurals-cldr/actions/workflows/ci.yml/badge.svg)](https://github.com/nodeca/plurals-cldr/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/plurals-cldr.svg)](https://www.npmjs.org/package/plurals-cldr)
[![Coverage Status](https://img.shields.io/coveralls/nodeca/plurals-cldr.svg)](https://coveralls.io/r/nodeca/plurals-cldr)

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:__

```bash
$ npm install plurals-cldr
```


### 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`.


```js
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](https://github.com/nodeca/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.


### Update CLDR version (for developers)

You need to bump `cldr-core` version & run rebuild:

```sh
npm install cldr-core@latest --save-dev
rm package-lock.json
rm -rf node_modules
npm install
npm run build
```


### References

1. [CLDR downloads](http://cldr.unicode.org/index/downloads)
2. [Latest chart](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html)
3. [Syntax description](http://www.unicode.org/reports/tr35/tr35-numbers.html#Language_Plural_Rules)

---
_Source: https://npm.io/package/plurals-cldr · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
