intlPlural

intlPlural(value, options?) returns text based on locale plural rules. Use this for item labels, counters, and plural-aware grammar in any output path.

Native reference: Intl.PluralRules

Signature

ts
1function intlPlural(2  value: number,3  options?: {4    locale?: string5    scope?: IntlRuntime6    type?: 'cardinal' | 'ordinal'7    zero?: string8    one?: string9    two?: string10    few?: string11    many?: string12    other?: string13  }14): string

Invalid values return ''.

Option map

OptionTypeDefaultEffect
localestringruntime localeOne-off locale override
scopeIntlRuntimegetIntl()Use scoped runtime locale
typecardinal | ordinalcardinalPluralization mode
zerostringundefinedText for zero category
onestringother fallbackText for one category
twostringundefinedText for two category
fewstringundefinedText for few category
manystringundefinedText for many category
otherstringrequiredText for other category

If a category is missing, output falls back to other or the selected category's raw token.

Examples

Cardinal examples

ts
1intlPlural(0, { locale: 'en-US', zero: 'no items', one: 'item', other: 'items' })2intlPlural(1, { locale: 'en-US', one: 'item', other: 'items' }) // "item"3intlPlural(2, { locale: 'en-US', one: 'item', other: 'items' }) // "items"

Ordinal examples

ts
1intlPlural(1, {2  type: 'ordinal',3  one: '1st',4  two: '2nd',5  few: '3rd',6  other: 'th',7})8 9intlPlural(11, {10  type: 'ordinal',11  one: '1st',12  two: '2nd',13  few: '3rd',14  other: 'th',15}) // other in en-US

Language-specific behavior

ts
1intlPlural(2, {2  locale: 'ar',3  one: 'article',4  two: 'couple',5  few: 'few',6  many: 'many',7  other: 'other',8})

Runtime scoping

ts
1import { createIntl, intlPlural } from '@beforesemicolon/intl'2 3const scoped = createIntl({ locale: 'fr-FR', messages: {} })4intlPlural(3, { scope: scoped, one: 'article', other: 'articles' })

See also

edit this doc