class documentation

class PluralRule: (source)

View In Hierarchy

Represents a set of language pluralization rules. The constructor accepts a list of (tag, expr) tuples or a dict of `CLDR rules`_. The resulting object is callable and accepts one parameter with a positive or negative number (both integer and float) for the number that indicates the plural form for a string and returns the tag for the format: >>> rule = PluralRule({'one': 'n is 1'}) >>> rule(1) 'one' >>> rule(2) 'other' Currently the CLDR defines these tags: zero, one, two, few, many and other where other is an implicit default. Rules should be mutually exclusive; for a given numeric value, only one rule should apply (i.e. the condition should only be true for one of the plural rule elements. .. _`CLDR rules`: https://www.unicode.org/reports/tr35/tr35-33/tr35-numbers.html#Language_Plural_Rules

Class Method parse Create a `PluralRule` instance for the given rules. If the rules are a `PluralRule` object, that object is returned.
Method __call__ Undocumented
Method __getstate__ Undocumented
Method __init__ Initialize the rule instance.
Method __repr__ Undocumented
Method __setstate__ Undocumented
Class Variable __slots__ Undocumented
Instance Variable abstract Undocumented
Property rules The `PluralRule` as a dict of unicode plural rules.
Property tags A set of explicitly defined tags in this rule. The implicit default ``'other'`` rules is not part of this set unless there is an explicit rule for it.
Instance Variable _func Undocumented

Create a `PluralRule` instance for the given rules. If the rules are a `PluralRule` object, that object is returned. :param rules: the rules as list or dict, or a `PluralRule` object :raise RuleError: if the expression is malformed

def __call__(self, n: float|decimal.Decimal) -> str: (source)

Undocumented

def __getstate__(self) -> list[tuple[str, Any]]: (source)

Undocumented

def __init__(self, rules: Mapping[str, str]|Iterable[tuple[str, str]]): (source)

Initialize the rule instance. :param rules: a list of ``(tag, expr)``) tuples with the rules conforming to UTS #35 or a dict with the tags as keys and expressions as values. :raise RuleError: if the expression is malformed

def __repr__(self) -> str: (source)

Undocumented

def __setstate__(self, abstract: list[tuple[str, Any]]): (source)

Undocumented

__slots__: tuple[str, ...] = (source)

Undocumented

abstract = (source)

Undocumented

The `PluralRule` as a dict of unicode plural rules. >>> rule = PluralRule({'one': 'n is 1'}) >>> rule.rules {'one': 'n is 1'}

A set of explicitly defined tags in this rule. The implicit default ``'other'`` rules is not part of this set unless there is an explicit rule for it.

Undocumented