Unicode CLDR pluralization rules as JavaScript functions for internationalization applications
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Ordinal-only pluralization functions for languages that have specific ordinal rules. Only 103 of the 217 supported languages have distinct ordinal pluralization rules.
Languages with ordinal rules provide functions for determining ordinal plural categories (1st, 2nd, 3rd, etc.).
/**
* Determines the ordinal plural category for a number
* @param n - The number to pluralize (number or string)
* @returns The appropriate ordinal plural category
*/
(n: number | string) => PluralCategory;
type PluralCategory = "zero" | "one" | "two" | "few" | "many" | "other";import { en, cy, az } from "make-plural/ordinals";103 languages with ordinal rules include:
Major Languages with Ordinal Rules:
en - English: Returns "one" | "two" | "few" | "other"fr - French: Returns "one" | "other"es - Spanish: Returns "other"de - German: Returns "other"it - Italian: Returns "many" | "other"Complex Ordinal Systems:
cy - Welsh: Returns "zero" | "one" | "two" | "few" | "many" | "other"gv - Manx: Returns "one" | "two" | "few" | "many" | "other"kw - Cornish: Returns "one" | "many" | "other"Languages with Simple Ordinal Rules:
az - Azerbaijani: Returns "one" | "few" | "many" | "other"ka - Georgian: Returns "one" | "other"sq - Albanian: Returns "one" | "many" | "other"English Ordinals:
import { en } from "make-plural/ordinals";
// English ordinal patterns
en(1); // 'one' (1st, 21st, 31st, 41st, 51st, 61st, 71st, 81st, 91st)
en(2); // 'two' (2nd, 22nd, 32nd, 42nd, 52nd, 62nd, 72nd, 82nd, 92nd)
en(3); // 'few' (3rd, 23rd, 33rd, 43rd, 53rd, 63rd, 73rd, 83rd, 93rd)
en(4); // 'other' (4th, 5th, 6th, 7th, 8th, 9th, 10th, 11th, 12th, 13th...)
// Special cases
en(11); // 'other' (11th - not 'one' despite ending in 1)
en(12); // 'other' (12th - not 'two' despite ending in 2)
en(13); // 'other' (13th - not 'few' despite ending in 3)
en(21); // 'one' (21st - back to pattern)Welsh Complex Ordinals:
import { cy } from "make-plural/ordinals";
// Welsh has 6 ordinal categories
cy(0); // 'zero' (0th)
cy(1); // 'one' (1st)
cy(2); // 'two' (2nd)
cy(3); // 'few' (3rd, 4th)
cy(5); // 'many' (5th, 6th)
cy(7); // 'other' (7th+)French Ordinals:
import { fr } from "make-plural/ordinals";
// French has simple ordinal rules
fr(1); // 'one' (1er - premier)
fr(2); // 'other' (2e, 2ème)
fr(3); // 'other' (3e, 3ème)
fr(100); // 'other'Italian Ordinals:
import { it } from "make-plural/ordinals";
// Italian ordinal system
it(1); // 'many' (1º)
it(8); // 'many' (8º)
it(11); // 'many' (11º)
it(80); // 'many' (80º)
it(800); // 'many' (800º)
it(1000);// 'other' (1000º)English (en) Ordinal Rules:
one: n % 10 = 1 && n % 100 ≠ 11 (1st, 21st, 31st, but not 11th)two: n % 10 = 2 && n % 100 ≠ 12 (2nd, 22nd, 32nd, but not 12th)few: n % 10 = 3 && n % 100 ≠ 13 (3rd, 23rd, 33rd, but not 13th)other: everything else (4th-20th, 24th-30th, etc.)Welsh (cy) Ordinal Rules:
zero: n = 0one: n = 1two: n = 2few: n = 3,4many: n = 5,6other: everything elseAzerbaijani (az) Ordinal Rules:
one: n % 10 in 1,2,5,7,8 || n % 100 in 20,50,70,80few: n % 10 in 3,4 || n % 1000 in 100,200,300,400,500,600,700,800,900many: n = 0 || n % 10 = 6 || n % 100 in 40,60,90other: everything elseimport { en, cy } from "make-plural/ordinals";
// String representation support
en("1"); // 'one'
en("21"); // 'one'
en("12"); // 'other'
// Decimal handling (usually 'other')
en("1.0"); // 'one'
en("1.5"); // 'other'
cy("2.0"); // 'two'
cy("2.5"); // 'other'Languages without specific ordinal rules are not included in this module. For comprehensive coverage that falls back to cardinal rules when ordinal rules don't exist, use the main plurals module:
// Use this for comprehensive coverage
import { zh, ja, ko } from "make-plural";
zh(1, true); // 'other' (fallback to cardinal)
ja(1, true); // 'other' (fallback to cardinal)
ko(1, true); // 'other' (fallback to cardinal)
// These languages are NOT in make-plural/ordinals
// import { zh, ja, ko } from "make-plural/ordinals"; // ERRORUse ordinal-only functions when:
Use main plurals module when: