UNPKG

react-intl

Version:

Internationalize React apps. This library provides React components and an API to format dates, numbers, and strings, including pluralization and handling translations.

21 lines (20 loc) 650 B
import { filterProps, createError } from '../utils'; const PLURAL_FORMAT_OPTIONS = [ 'localeMatcher', 'type', ]; export function formatPlural({ locale, onError }, getPluralRules, value, options = {}) { if (!Intl.PluralRules) { onError(createError(`Intl.PluralRules is not available in this environment. Try polyfilling it using "@formatjs/intl-pluralrules" `)); } let filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS); try { return getPluralRules(locale, filteredOptions).select(value); } catch (e) { onError(createError('Error formatting plural.', e)); } return 'other'; }