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): stringInvalid values return ''.
Option map
| Option | Type | Default | Effect |
|---|---|---|---|
locale | string | runtime locale | One-off locale override |
scope | IntlRuntime | getIntl() | Use scoped runtime locale |
type | cardinal | ordinal | cardinal | Pluralization mode |
zero | string | undefined | Text for zero category |
one | string | other fallback | Text for one category |
two | string | undefined | Text for two category |
few | string | undefined | Text for few category |
many | string | undefined | Text for many category |
other | string | required | Text 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-USLanguage-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' })