Unicode CLDR Pluralization Rules

8.1.0 · active · verified Sun Apr 19

make-plural provides JavaScript functions that implement the Unicode CLDR pluralization rules for approximately 220 languages. It handles both cardinal (e.g., 'one book') and ordinal (e.g., '1st book') pluralization categories. As of version 8.1.0, the library is actively maintained with regular updates to support the latest CLDR versions, ensuring accuracy for new locales and rule changes. Key differentiators include its pre-compiled, runtime-dependency-free functions, optimized for tree-shaking with ES modules, which can result in very small bundle sizes when only specific locales are imported. It is used internally by the `intl-pluralrules` polyfill and offers companion packages `make-plural-cli` and `make-plural-compiler` for custom build generation. The project maintains a steady release cadence, often tied to new CLDR versions or feature enhancements like compact notation support, ensuring current and accurate pluralization logic.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates cardinal and ordinal pluralization for English and French, including specific locale imports for tree-shaking and accessing plural categories for different languages, highlighting locale key transformations.

import { en, fr } from 'make-plural';
import { en as ordinalEn } from 'make-plural/ordinals';
import * as Categories from 'make-plural/pluralCategories';

// Cardinal pluralization
console.log('English cardinal for 1:', en(1)); // 'one'
console.log('English cardinal for 2:', en(2)); // 'other'
console.log('French cardinal for 1:', fr(1)); // 'one'
console.log('French cardinal for 2:', fr(2)); // 'one'
console.log('French cardinal for 3:', fr(3)); // 'other'

// Ordinal pluralization using the combined function (second argument `true`)
console.log('English ordinal for 1:', en(1, true)); // 'one'
console.log('English ordinal for 2:', en(2, true)); // 'two'
console.log('English ordinal for 3:', en(3, true)); // 'few'

// Ordinal pluralization using the dedicated ordinals module
console.log('English ordinal (dedicated module) for 3:', ordinalEn(3)); // 'few'

// Accessing plural categories for a locale
const enCategories = Categories.en.cardinal;
console.log('English cardinal categories:', enCategories); // ['one', 'other']

const ptPtCategories = Categories.pt_PT.cardinal; // Note: pt-PT becomes pt_PT
console.log('Portuguese (Portugal) cardinal categories:', ptPtCategories); // ['one', 'other']

// Example with string representation of a number
console.log('English cardinal for "1.0":', en('1.0')); // 'other'

view raw JSON →