# smart-plurals

> A collection of language-specific rules for determining the plurality of a number

Latest version **1.1.0** (published 2014-05-12) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2014-05-12 |
| First published | 2014-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | Scott.William.Rippey@gmail.com |
| Maintainers | scottrippey |
| Keywords | plural, English, German, Dutch, Swedish, Danish, Norwegian, Faroese, Spanish, Portuguese, Italian, Bulgarian, Greek, Finnish, Estonian, Hebrew, Esperanto, Hungarian, Turkish, Czech, Slovak, French, Brazilian Portuguese, Gaeilge (Irish), Latvian, Lithuanian, Polish, Romanian, Russian, Ukrainian, Serbian, Croatian, Slovenian, localization, l10n, internationalization, i18n, vanilla javascript |

## Links

- npm: https://www.npmjs.com/package/smart-plurals
- Repository: https://github.com/scottrippey/Smart-Plurals
- Issues: https://github.com/scottrippey/Smart-Plurals/issues
- npm.io page: https://npm.io/package/smart-plurals

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

- 1.1.0 (latest) — 2014-05-12
- 1.0.7 — 2014-05-11
- 1.0.6 — 2014-02-22
- 1.0.4 — 2014-02-22
- 1.0.5 — 2014-02-22
- 1.0.3 — 2014-02-22
- 1.0.2 — 2014-01-21
- 1.0.1 — 2014-01-19
- 1.0.0 — 2014-01-18
- 0.9.4 — 2014-01-18
- 0.9.3 — 2014-01-18
- 0.9.2 — 2014-01-18
- 0.9.1 — 2014-01-18
- 0.9.0 — 2014-01-18

## README

# Smart.Plurals

A collection of language-specific rules for determining the plurality of a number.
These rules are designed to help with the localization of your application.

The library is small and simple, minified and gzipped to under 500b.

## Examples

For example, English has 2 plural forms - 1 is singular, all other values are plural:

    var english = Smart.Plurals.getRule('en');
    english(0, [ 'singular', 'plural'  ]); // returns 'plural'
    english(1, [ 'singular', 'plural'  ]); // returns 'singular'
    english(2, [ 'singular', 'plural'  ]); // returns 'plural'

However, many languages have different rules, and some even have 3 or 4 different plural forms.
For example, Russian has 3 plural forms - numbers ending with 1 (such as 21, 31, 41) are singular;
numbers ending in 2-4 (22, 23, 24) are "few", and all others are plural:

    // (TODO: Improve this example with actual Russian words)
    var russian = Smart.Plurals.getRule('ru');
    russian(91, [ 'singular', 'few', 'plural' ]); // returns 'singular'
    russian(94, [ 'singular', 'few', 'plural' ]); // returns 'few'
    russian(99, [ 'singular', 'few', 'plural' ]); // returns 'plural'

## Download

This library is designed to be tiny, has no dependencies, and should be very easy to integrate into any application.
This library comes in 3 flavors; `standalone`, `Angular`, and `Node`.

### Standalone
This standalone library exposes the API on the `Smart.Plurals` namespace.  It has no additional dependencies.

Usage:

```js
var pluralRule = Smart.Plurals.getRule('en');
```


### Using with Node
This is the same as the standalone build, but exports the entire Smart object.

Usage:

```js
var Smart = require('smart-plurals');
var pluralRule = Smart.Plurals.getRule('en');
...
```

### Using with Angular
This build exposes a `smart` module with a `SmartPlurals` service.
It also includes a `plural` filter.

Usage:

```js
angular.module('example', [ 'smart' ]).run(function(SmartPlurals) {
    var pluralRule = SmartPlurals.getRule('en');
    ...
});
```

```handlebars
<span> There {{ value | plural:"is":"are" }} {{ value }} {{ value | plural:"item":"items" }} remaining... </span>
```


## Supported languages:

* Germanic family
**  English, German, Dutch, Swedish, Danish, Norwegian, Faroese
* Romanic family
**  Spanish, Portuguese, Italian, Bulgarian
* Latin/Greek family
**  Greek
* Finno-Ugric family
**  Finnish, Estonian
* Semitic family
**  Hebrew
* Artificial
**  Esperanto
* Finno-Ugric family
**  Hungarian
* Turkic/Altaic family
**  Turkish
* Slavic family
**  Czech, Slovak
* Romanic family
**  French, Brazilian Portuguese
* Celtic
**  Gaeilge (Irish)
* Baltic family
**  Latvian
* Baltic family
**  Lithuanian
* Slavic family
**  Polish
* Romanic family
**  Romanian
* Slavic family
**  Russian, Ukrainian, Serbian, Croatian
* Slavic family
**  Slovenian

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