An open API service indexing awesome lists of open source software.

https://github.com/megahertz/js-simple-plurals

Just a set of plural functions for different languages
https://github.com/megahertz/js-simple-plurals

Last synced: 10 months ago
JSON representation

Just a set of plural functions for different languages

Awesome Lists containing this project

README

          

# js-simple-plurals
Just a set of plural functions for different languages

# Installation

#### Install with Bower
```sh
$ bower install js-simple-plurals
```

#### Install with NPM

```sh
$ npm install js-simple-plurals
```

# Examples

#### Node.js
```js
var plural = require('./node/en');
function pluralizeEn(number, one, many) {
var rules = [one, many];
var position = plural(number);
return rules[position];
}

console.log('2 ' + pluralizeEn(2, 'day', 'days')); // prints '2 days'
```

#### Web
```html


Number


var number = document.getElementById('number');
var text = document.getElementById('text');

function pluralizeEn(number, one, many) {
var rules = [one, many];
var position = plural.en(number);
return rules[position];
}

function updateText() {
var content = number.value + ': ' + pluralizeEn(
number.value,
'day',
'days'
);
document.getElementById('text').textContent = content;
}

document.getElementById('number').addEventListener('change', updateText);
updateText();

```

## About
Plural rules follow the guideline found in the Unicode CLDR Charts on [Language Plural Rules](http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html).
This plural rules are based on rules generated by [universal-i18n](https://github.com/yanickrochon/universal-i18n/).