PluralRules

ignore

RESCRIPT
let ignore: t => unit

ignore(pluralRules) ignores the provided pluralRules and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

localeType

RESCRIPT
type localeType = [#cardinal | #ordinal]

make

RESCRIPT
let make: (~locales: array<string>=?, ~options: options=?) => t

Creates a new Intl.PluralRules instance to determine plural categories.

See Intl.PluralRules on MDN.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) let category = rules->Intl.PluralRules.select(1.0) category == #one

options

RESCRIPT
type options = { localeMatcher?: Intl_Common.localeMatcher, \"type"?: localeType, minimumIntegerDigits?: Intl_Common.oneTo21, minimumFractionDigits?: Intl_Common.zeroTo20, maximumFractionDigits?: Intl_Common.zeroTo20, minimumSignificantDigits?: Intl_Common.oneTo21, maximumSignificantDigits?: Intl_Common.oneTo21, }

pluralCategories

RESCRIPT
type pluralCategories = [ | #few | #many | #one | #other | #two | #zero ]

resolvedOptions

RESCRIPT
type resolvedOptions = { locale: string, pluralCategories: array<pluralCategories>, \"type": localeType, minimumIntegerDigits?: Intl_Common.oneTo21, minimumFractionDigits?: Intl_Common.zeroTo20, maximumFractionDigits?: Intl_Common.zeroTo20, minimumSignificantDigits?: Intl_Common.oneTo21, maximumSignificantDigits?: Intl_Common.oneTo21, }

resolvedOptions

RESCRIPT
let resolvedOptions: t => resolvedOptions

resolvedOptions(rules) returns the plural rule configuration in use.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) Intl.PluralRules.resolvedOptions(rules).locale == "en"

rule

RESCRIPT
type rule = [#few | #many | #one | #other | #two | #zero]

select

RESCRIPT
let select: (t, float) => rule

select(rules, value) returns the plural category for the given number.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) rules->Intl.PluralRules.select(1.) == #one

selectInt

RESCRIPT
let selectInt: (t, int) => rule

selectInt(rules, value) is like select but accepts an integer.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) rules->Intl.PluralRules.selectInt(2) == #other

selectRange

RESCRIPT
let selectRange: (t, ~start: float, ~end: float) => rule

selectRange(rules, ~start, ~end) returns the category for numbers in the range.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) rules->Intl.PluralRules.selectRange(~start=1., ~end=2.) == #other

selectRangeInt

RESCRIPT
let selectRangeInt: (t, ~start: int, ~end: int) => rule

selectRangeInt(rules, ~start, ~end) is the integer version of selectRange.

Examples

RESCRIPT
let rules = Intl.PluralRules.make(~locales=["en"]) rules->Intl.PluralRules.selectRangeInt(~start=1, ~end=1) == #other

supportedLocalesOf

RESCRIPT
let supportedLocalesOf: ( array<string>, ~options: supportedLocalesOptions=?, ) => array<string>

supportedLocalesOf(locales, ~options) filters locales to those supported for plural rules.

See Intl.PluralRules.supportedLocalesOf on MDN.

Examples

RESCRIPT
Intl.PluralRules.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]

supportedLocalesOptions

RESCRIPT
type supportedLocalesOptions = { localeMatcher: Intl_Common.localeMatcher, }

t

RESCRIPT
type t