PluralRule

Wrapper class for PluralRules, designed for ease-of-use and safety.

A PluralRule is created by using a create() method. Create methods will return empty Optionals if a no plural rule is found for a given language. Optional method chaining can be used to return a default rule, or createOrDefault() can be used (less error-prone).

For example:

PluralRule rule = PluralRule.createOrDefault(Locale.ENGLISH, PluralRuleType.ORDINAL);
assert (rule.select(1) == PluralCategory.ONE); // e.g., "1 day"
assert (rule.select(10) == PluralCategory.OTHER); // e.g., "10 days"
assert (rule.select("1100.00") == PluralCategory.OTHER); // e.g., "1100.00 days"
<p>
PluralRule rule = PluralRule.createOrDefault(Locale.ENGLISH, PluralRuleType.CARDINAL);
assert (rule.select(1) == PluralCategory.ONE); // e.g, "1st" use 'st' suffix
assert (rule.select(2) == PluralCategory.TWO); // e.g., "2nd" use 'nd' suffix
assert (rule.select(3) == PluralCategory.FEW); // e.g., "3rd" use 'rd' suffix
assert (rule.select(4) == PluralCategory.OTHER); // e.g., "4th" use 'th' suffix
assert (rule.select(43) == PluralCategory.FEW); // e.g., "43rd"
assert (rule.select(50) == PluralCategory.OTHER); // e.g., "50th"

The PluralCategory returned determines how subsequent localization logic then handles the number, ranking, or quantity, which is locale-dependent.

When matching a language, the empty String "" and String "root" are equivalent to Locale.ROOT. The Locale.ROOT rule can be used if there is no match for a language. This is particularly important when using cardinal rules; many languages do not have specific cardinal rules.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Returns the PluralRuleType corresponding to this PluralRule. Never null.

Link copied to clipboard

Returns the rule as a Function. Never null.

Link copied to clipboard

Determine the PluralCategory for the given PluralOperand.

Determine the PluralCategory for the given double value.

fun select(value: Long): PluralCategory?

Determine the PluralCategory for the given long value.

Determine the PluralCategory for the given Number.

Determine the PluralCategory for the given numeric String.

Link copied to clipboard
fun selectCompact(value: Double, suppressedExponent: Int): PluralCategory?

Determine the PluralCategory for the given "compact" double

fun selectCompact(value: Long, suppressedExponent: Int): PluralCategory?

Determine the PluralCategory for the given "compact" long

Link copied to clipboard
open override fun toString(): String