Using Hermes? Prefer native Intl & Temporal
We recommend the Rust-backed Hermes SDK (@formatjs/react-native-hermes-intl and @formatjs/react-native-hermes-temporal) over TypeScript polyfills for Hermes apps. It installs twelve Intl APIs and Temporal before your application JavaScript runs, with locale, calendar, and time-zone data compiled into the SDK.
Get started with native Intl & Temporal. Native integration requires rebuilding your app. Use TypeScript polyfills when you cannot add native code.
A polyfill for Intl.PluralRules tested by the official ECMAScript Conformance test suite
ECMA-402 Spec Compliance#
Private slot access uses WeakMap methods captured when the module loads.
This package implements Intl.PluralRules. See the conformance report for tested coverage and known limitations.
✅ Implemented Features#
Core Methods#
select(number)- Returns the plural category for a number ('zero','one','two','few','many','other')selectRange(start, end)- Returns the plural category for a number rangeresolvedOptions()- Returns resolved optionssupportedLocalesOf(locales)- Returns supported locales
Rule Types#
'cardinal'(default) - For cardinal numbers (e.g., "1 item", "2 items")'ordinal'- For ordinal numbers (e.g., "1st", "2nd", "3rd")
Locale Data#
- Supports 700+ locales with accurate LDML plural rules
- Includes all 6 plural categories per LDML specification
- Handles complex plural rules (e.g., Arabic has 6 forms, Chinese has 1)
Locale data modules are generated from CLDR supplemental plural-rule data. If a locale is available in other CLDR datasets but absent from the supplemental plural rules, this package does not publish a locale-data module for it.
Plural selection uses the rounded value and visible fraction digits, including
zeros required by minimumFractionDigits.
Example Usage#
Global import#
import '@formatjs/intl-pluralrules/polyfill.js'
const pr = new Intl.PluralRules('en')
pr.select(0) // "other"
pr.select(1) // "one"
pr.select(2) // "other"
const prOrdinal = new Intl.PluralRules('en', {type: 'ordinal'})
prOrdinal.select(1) // "one" (1st)
prOrdinal.select(2) // "two" (2nd)
prOrdinal.select(3) // "few" (3rd)
prOrdinal.select(4) // "other" (4th)
// selectRange for ranges
pr.selectRange(1, 5) // "other" (1-5 items)
Info
The global import does not include TypeScript type declarations. For TypeScript projects, we recommend using ES module imports instead.
If you choose to use the global import, in order to prevent type errors, you must manually include the corresponding type declaration files (.d.ts) in your project.
ES Modules#
import {PluralRules} from '@formatjs/intl-pluralrules'
const pr = new PluralRules('en')
pr.select(0) // "other"
Keep trailing zeros (Stage 3)#
Implements the Keep trailing zeros draft. String precision contributes to visible plural operands; Number and BigInt inputs keep their existing behavior.
const pr = new Intl.PluralRules('en')
pr.select(1) // "one"
pr.select('1.0') // "other"
pr.selectRange('1', '1.0') // "other"
new Intl.PluralRules('en', {trailingZeroDisplay: 'stripToMinimum'}).select(
'1.0'
) // "one"
stripToMinimum strips source trailing zeros beyond the configured minimum
fraction/significant digits. Digit maxima still limit precision. stripIfInteger
strips the fraction when the rounded value is an integer. Both modes are returned
by resolvedOptions(). The normal polyfill entry point detects missing native support.
Installation#
npm i @formatjs/intl-pluralrules
Requirements#
Usage#
Via polyfill-fastly.io#
You can use polyfill-fastly.io URL Builder to create a polyfill script tag for Intl.PluralRules. By default the created URL does not come with any locale data. In order to add locale data, append Intl.PluralRules.~locale.<locale> to your list of features. For example:
<!-- Polyfill Intl.PluralRules, its dependencies & `en` locale data -->
<script src="https://polyfill-fastly.io/v3/polyfill.min.js?features=Intl.PluralRules,Intl.PluralRules.~locale.en"></script>
Simple#
import '@formatjs/intl-pluralrules/polyfill.js'
import '@formatjs/intl-pluralrules/locale-data/en.js' // locale-data for en
React Native#
The polyfill conditional detection code runs very slowly on Android and can slow down your app's startup time by seconds. Since React Native uses Hermes which does not support Intl.PluralRules, import /polyfill-force instead for much better performance:
import '@formatjs/intl-pluralrules/polyfill-force.js' // instead of /polyfill
import '@formatjs/intl-pluralrules/locale-data/en.js'
Dynamic import + capability detection#
shouldPolyfill() falls back when the host locale query is missing or throws.
async function polyfill(locale: string) {
const unsupportedLocale = shouldPolyfill(locale)
// This locale is supported
if (!unsupportedLocale) {
return
}
// Load the polyfill 1st BEFORE loading data
await import('@formatjs/intl-pluralrules/polyfill-force.js')
await import(`@formatjs/intl-pluralrules/locale-data/${unsupportedLocale}.js`)
}
Draft options and range behavior#
notation accepts standard, scientific, engineering, and compact.
compactDisplay is validated for every notation and reported only for compact.
Compact notation uses the shared compact digit defaults. resolvedOptions()
returns an ordinary object, reports notation and rounding settings, and lists
plural categories in the order zero, one, two, few, many, other.
selectRange() accepts infinite endpoints; NaN still throws RangeError.
Compact plural selection uses generated CLDR exponent tables for locales whose
rules use c/e. It does not require NumberFormat locale data to be installed.
Locale data registers CLDR default-content variants, such as en-US for English.
Loading regional data preserves explicitly loaded language data.
Rust on Hermes#
The Hermes Intl SDK includes Rust PluralRules.
Default locale data is compiled into the archive; application scripts do not
load JSON packs. Build a custom SDK with --//crates/intl_data:locales=en,fr.
Rust handles locale matching, exact numeric rounding, and ICU4X rule selection.
Individual consumers can still link :pluralrules and call
formatjs::installPluralRules(runtime) after canonicalization.
Measured performance#
TypeScript and native JavaScript#
Measured 2026-10-31 on Apple M4 Max, macOS arm64, Node 24.14.0 / ICU 78.2; source 56d15e997. Median of seven warmed rounds.
| Operation | TS ops/s | TS full helpers ops/s | Native JS ops/s |
|---|---|---|---|
| select cardinal | 932,544 | 919,918 | 4,552,086 |
| select ordinal | 861,028 | 875,162 | 2,645,170 |
| construct + resolvedOptions | 685,222 | 621,338 | 316,752 |
TS uses host Intl helpers; TS full helpers installs all FormatJS Intl APIs.
Module loading and data registration are excluded. Construction rows include
resolvedOptions(). These are desktop microbenchmarks; native locale data may
differ. † marks noisy rows (round max/min > 1.5). See workloads, commands, and raw results.
Rust core#
| Rust core operation | µs/call | Rust core ops/s |
|---|---|---|
| select cardinal | 0.059 | 16,854,579 |
| select ordinal | 0.065 | 15,323,842 |
| construct + resolvedOptions | 0.073 | 13,781,888 |
Same machine and source revision, optimized Rust build, seven warmed rounds. Rust core timings exclude Hermes/JSI and JS boundary work; inputs are prepared Rust strings/UTF-16. Data and API-boundary differences prevent direct speedup claims against TS/native JS. † marks round max/min > 1.5. Workload details and raw results.