@intlayer/core
Version:
Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.
25 lines (23 loc) • 652 B
JavaScript
import { getCachedIntl } from "../utils/intl.mjs";
//#region src/interpreter/getPlural.ts
/**
* Picks content from a plural map based on a count and locale, using CLDR
* pluralization rules (`Intl.PluralRules`).
*
* Falls back to the `other` category when no specific category matches.
*
* @example
* ```ts
* getPlural({
* one: 'one item',
* other: '{{count}} items',
* }, 5, 'en');
* // '{{count}} items'
* ```
*/
const getPlural = (pluralContent, count, locale) => {
return pluralContent[getCachedIntl(Intl.PluralRules, locale).select(count)] ?? pluralContent.other;
};
//#endregion
export { getPlural };
//# sourceMappingURL=getPlural.mjs.map