CldrPluralRules

CLDR's cardinal plural rules for a bounded set of languages, evaluated in common code.

This is the one part of SymbolLocaleFormatter that does not come from the platform, and not by preference: four of the seven targets have no plural-rules API at all. Android has android.icu.text.PluralRules and the web has Intl.PluralRules; the JVM ships neither (ICU4J is not on this module's classpath) and Apple's Foundation exposes plural selection only through .stringsdict resources, which is a build-time facility rather than a callable one. Delegating where it exists would have made pluralize answer differently on iOS than on Android from the same payload, so the rules live here and every target reads the same ones.

The set is a subset, and an unknown language answers PluralCategory.OTHER. That is the category pluralize requires an author to supply, so an unlisted language degrades to the form that is always present rather than to a missing argument. languageTags says which are covered.

The operands are CLDR's — see Operands for how a bare Double is read into them.

The table is checked against ICU rather than transcribed. CldrPluralRulesFixtureTest holds a category for every language here at forty-four probe values, cut from Intl.PluralRules. That comparison is what found five languages sitting in the wrong family and two operands this did not have; nothing in the rules below should be changed without re-running it.

Properties

Link copied to clipboard

The language subtags this object has rules for. Everything else is PluralCategory.OTHER.

Functions

Link copied to clipboard
fun categoryFor(languageTag: String, value: Double): PluralCategory

Which category value falls into for languageTag.