PluralRules
t
type tlocaleType
type localeType = [#cardinal | #ordinal]options
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
type pluralCategories = [
| #few
| #many
| #one
| #other
| #two
| #zero
]resolvedOptions
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,
}supportedLocalesOptions
type supportedLocalesOptions = {
localeMatcher: Intl_Common.localeMatcher,
}make
let make: (~locales: array<string>=?, ~options: options=?) => tCreates a new Intl.PluralRules instance to determine plural categories.
See Intl.PluralRules on MDN.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
let category = rules->Intl.PluralRules.select(1.0)
category == #one
supportedLocalesOf
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
RESCRIPTIntl.PluralRules.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]
resolvedOptions
let resolvedOptions: t => resolvedOptionsresolvedOptions(rules) returns the plural rule configuration in use.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
Intl.PluralRules.resolvedOptions(rules).locale == "en"
rule
type rule = [#few | #many | #one | #other | #two | #zero]select
let select: (t, float) => ruleselect(rules, value) returns the plural category for the given number.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
rules->Intl.PluralRules.select(1.) == #one
selectInt
let selectInt: (t, int) => ruleselectInt(rules, value) is like select but accepts an integer.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
rules->Intl.PluralRules.selectInt(2) == #other
selectRange
let selectRange: (t, ~start: float, ~end: float) => ruleselectRange(rules, ~start, ~end) returns the category for numbers in the range.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
rules->Intl.PluralRules.selectRange(~start=1., ~end=2.) == #other
selectRangeInt
let selectRangeInt: (t, ~start: int, ~end: int) => ruleselectRangeInt(rules, ~start, ~end) is the integer version of selectRange.
Examples
RESCRIPTlet rules = Intl.PluralRules.make(~locales=["en"])
rules->Intl.PluralRules.selectRangeInt(~start=1, ~end=1) == #other
ignore
let ignore: t => unitignore(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.