GithubHelp home page GithubHelp logo

some-old-junk / plurals-cldr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodeca/plurals-cldr

0.0 2.0 0.0 49 KB

Plurals suport for JS, autogenerated from CLDR.

License: MIT License

Makefile 6.33% JavaScript 89.41% Smarty 4.26%

plurals-cldr's Introduction

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.

plurals-cldr's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.