You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
21 lines
652 B
21 lines
652 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"
|
|
`));
|
|
}
|
|
const filteredOptions = filterProps(options, PLURAL_FORMAT_OPTIONS);
|
|
try {
|
|
return getPluralRules(locale, filteredOptions).select(value);
|
|
}
|
|
catch (e) {
|
|
onError(createError('Error formatting plural.', e));
|
|
}
|
|
return 'other';
|
|
}
|