cp

cldr-plurals

CLDR logic in Javascript

Showing:

Popularity

Downloads/wk

12

GitHub Stars

48

Maintenance

Last Commit

6yrs ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

1.2KB

License

Apache-2.0

Type Definitions

Tree-Shakeable

No?

Categories

Readme

CLOSED

This project is no longer maintained

CLDR.js

CLDR.js provides logic from the Unicode Common Locale Data Repository. Currently, the only functionality it provides is the pluralization rules.

Plural Rules

Usage:

CLDR.pluralForm(0, 'en');     // => 'other'
CLDR.pluralForm(1, 'en-US');  // => 'one'
CLDR.pluralForm(2.383, 'fr'); // => 'other'
CLDR.pluralForm(1, 'zh');     // => 'other'
CLDR.pluralForm(26, 'uk');    // => 'many'

If you set CLDR.defaultLanguage then the second argument is optional:

CLDR.defaultLanguage = 'pl';
CLDR.pluralForm(22); // => 'few'

Though CLDR.js doens't provide an I18n framework, you can use this logic as part of yours. For example, you might write the following:

CLDR.defaultLanguage = 'en';

var translations = {
  'en': {
    'widget': {
      'one': 'one widget',
      'other': '{{count}} widgets'
    }
  },
  'jp': {
    'widget': {
      'other': '{{count}} ウィジェット'
    }
  }
};

function pluralize(key, count, language) {
  var form = CLDR.pluralForm(count),
      language = language || CLDR.defaultLanguage;
  return translations[language][key][form];
}

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial