Course contentsShow
← JavaScript
Lesson 2229 of 2,72346. InternationalizationFree lesson

Intl.PluralRules Constructor and Options

Create a PluralRules instance with locale and type options (cardinal vs ordinal) for grammatically correct plurals.

Intl.PluralRules Constructor and Options

You'll learn how to create a PluralRules instance with locale and type options to produce grammatically correct plurals across languages.

What Is Intl.PluralRules?

The Intl.PluralRules constructor creates an object that determines which plural form a number should use in a given language. Different languages have different rules—English has two forms (one vs. other), but Polish has three, and Arabic has six!

The constructor accepts two parameters: a locale (like 'en-US' or 'pl-PL') and an options object where you specify the type of plural rule you need.

The Two Types: Cardinal vs Ordinal

The type option controls whether you're dealing with:

  • cardinal (default): Counting items → "1 apple" vs "2 apples"
  • ordinal: Ranking or ordering → "1st place" vs "2nd place"
// Cardinal plurals (counting)
const cardinalRules = new Intl.PluralRules('en-US', { type: 'cardinal' });
console.log(cardinalRules.select(1));  // "one"
console.log(cardinalRules.select(2));  // "other"

// Ordinal plurals (ranking)
const ordinalRules = new Intl.PluralRules('en-US', { type: 'ordinal' });
console.log(ordinalRules.select(1));   // "one"   → 1st
console.log(ordinalRules.select(2));   // "two"   → 2nd
console.log(ordinalRules.select(3));   // "few"   → 3rd
console.log(ordinalRules.select(4));   // "other" → 4th

Notice how ordinal rules return different categories ("one", "two", "few", "other") that you can map to suffixes like "st", "nd", "rd", "th".

Why This Matters

Without PluralRules, you'd hard-code plural logic per language. This constructor handles the complex rules automatically, letting you write internationalized text that sounds natural everywhere.

Key Takeaway: Use new Intl.PluralRules(locale, { type }) to create rule engines for cardinal (counting) or ordinal (ranking) plurals, then call select(number) to get the grammatical category.