{"id":11263,"library":"make-plural","title":"Unicode CLDR Pluralization Rules","description":"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.","status":"active","version":"8.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/eemeli/make-plural","tags":["javascript","unicode","cldr","i18n","internationalization","pluralization"],"install":[{"cmd":"npm install make-plural","lang":"bash","label":"npm"},{"cmd":"yarn add make-plural","lang":"bash","label":"yarn"},{"cmd":"pnpm add make-plural","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Since v8.0.0, make-plural is ESM-only. The main export (`make-plural`) provides a combined function for cardinal and ordinal plurals.","wrong":"const { en } = require('make-plural')","symbol":"en","correct":"import { en } from 'make-plural'"},{"note":"Use named imports from sub-paths like `make-plural/cardinals` for optimal tree-shaking, otherwise bundlers might include all locales.","wrong":"import * as Cardinals from 'make-plural/cardinals'","symbol":"en","correct":"import { en } from 'make-plural/cardinals'"},{"note":"TypeScript type for pluralization functions, useful for explicit typing in consumers.","symbol":"LocalePluralFunc","correct":"import type { LocalePluralFunc } from 'make-plural'"},{"note":"The locale code `pt-PT` is transformed to `pt_PT` (with an underscore) for JavaScript identifier compatibility when accessed as an object key from the exports.","wrong":"import * as Categories from 'make-plural/pluralCategories'; Categories['pt-PT']","symbol":"pt_PT","correct":"import * as Categories from 'make-plural/pluralCategories'; Categories.pt_PT"}],"quickstart":{"code":"import { en, fr } from 'make-plural';\nimport { en as ordinalEn } from 'make-plural/ordinals';\nimport * as Categories from 'make-plural/pluralCategories';\n\n// Cardinal pluralization\nconsole.log('English cardinal for 1:', en(1)); // 'one'\nconsole.log('English cardinal for 2:', en(2)); // 'other'\nconsole.log('French cardinal for 1:', fr(1)); // 'one'\nconsole.log('French cardinal for 2:', fr(2)); // 'one'\nconsole.log('French cardinal for 3:', fr(3)); // 'other'\n\n// Ordinal pluralization using the combined function (second argument `true`)\nconsole.log('English ordinal for 1:', en(1, true)); // 'one'\nconsole.log('English ordinal for 2:', en(2, true)); // 'two'\nconsole.log('English ordinal for 3:', en(3, true)); // 'few'\n\n// Ordinal pluralization using the dedicated ordinals module\nconsole.log('English ordinal (dedicated module) for 3:', ordinalEn(3)); // 'few'\n\n// Accessing plural categories for a locale\nconst enCategories = Categories.en.cardinal;\nconsole.log('English cardinal categories:', enCategories); // ['one', 'other']\n\nconst ptPtCategories = Categories.pt_PT.cardinal; // Note: pt-PT becomes pt_PT\nconsole.log('Portuguese (Portugal) cardinal categories:', ptPtCategories); // ['one', 'other']\n\n// Example with string representation of a number\nconsole.log('English cardinal for \"1.0\":', en('1.0')); // 'other'","lang":"typescript","description":"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."},"warnings":[{"fix":"Migrate all imports from `require('make-plural')` to `import { ... } from 'make-plural'` syntax and ensure your build environment supports ES modules.","message":"The `make-plural` package dropped CommonJS exports, becoming an ES module-only package. Projects using `require()` will fail.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Review the new license for compliance. For environments not supporting ES6 (e.g., IE 11), ensure your build process includes transpilation (e.g., Babel) for ES6+ syntax.","message":"The `make-plural` package license changed to the OSI-approved Unicode Data Files and Software License. Additionally, generated functions now use ES6 `const` and `=>` syntax.","severity":"breaking","affected_versions":">=7.0.0"},{"fix":"Refactor your imports to target specific locale functions using named imports to allow bundlers to remove unused code.","message":"For optimal bundle size and effective tree-shaking, always use named imports when importing specific locales (e.g., `import { en } from 'make-plural/cardinals'`) instead of wildcard imports (e.g., `import * as Cardinals from 'make-plural/cardinals'`) from sub-paths.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"When accessing the `pt-PT` locale as a property from exported objects, use the underscore-separated `pt_PT` identifier.","message":"The locale code `pt-PT` (Portuguese as spoken in Portugal) is transformed to `pt_PT` for JavaScript identifier compatibility when accessed as an object key (e.g., from `make-plural/pluralCategories`).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Be aware that not all locales supported for cardinal plurals will have corresponding ordinal pluralization rules via `make-plural/ordinals`.","message":"The `make-plural/ordinals` module provides ordinal pluralization functions but covers a slightly smaller subset of locales compared to the main `make-plural` or `make-plural/cardinals` modules due to limitations in CLDR data availability for ordinal rules.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Update your code to use ES module `import { en } from 'make-plural'` syntax and ensure your build system supports ES modules.","cause":"Attempting to use `make-plural` with CommonJS `require()` syntax or an outdated bundler configuration after v8.0.0.","error":"TypeError: make_plural__WEBPACK_IMPORTED_MODULE_0__.en is not a function"},{"fix":"Configure your build process (e.g., Babel) to transpile ES6+ syntax to a compatible target for your deployment environment.","cause":"Running code generated by `make-plural@7.0.0` or later in an environment that does not support ES6 syntax without proper transpilation.","error":"SyntaxError: Unexpected token 'const' or SyntaxError: Unexpected token '=>'"},{"fix":"Use the transformed identifier `pt_PT` (with an underscore) when accessing the Portuguese (Portugal) locale, e.g., `Categories.pt_PT`.","cause":"Attempting to access the `pt-PT` locale directly using the hyphenated string as a JavaScript object key from exports like `pluralCategories`.","error":"TypeError: Cannot read properties of undefined (reading 'cardinal')"},{"fix":"Refactor your imports to use named imports for specific locales, e.g., `import { en, fr } from 'make-plural/cardinals'`.","cause":"Using wildcard imports (e.g., `import * as Plurals from 'make-plural/plurals'`) instead of named imports, which prevents effective tree-shaking by bundlers.","error":"My bundle size is unexpectedly large despite only using a few locales."}],"ecosystem":"npm"}