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
- Host: GitHub
- URL: https://github.com/megahertz/js-simple-plurals
- Owner: megahertz
- License: mit
- Created: 2016-01-29T04:42:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-29T04:47:10.000Z (over 10 years ago)
- Last Synced: 2025-03-16T19:55:25.434Z (about 1 year ago)
- Language: JavaScript
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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/).