class documentation

class PluralRule(object):

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.

Class Method parse Create a PluralRule instance for the given rules. If the rules are a PluralRule object, that object is returned.
Class Variable tags Undocumented
Method __call__ Undocumented
Method __getstate__ Undocumented
Method __init__ Initialize the rule instance.
Method __repr__ Undocumented
Method __setstate__ Undocumented
Class Variable __slots__ Undocumented
Instance Variable ​_func Undocumented
Instance Variable abstract Undocumented
Property rules The PluralRule as a dict of unicode plural rules.
@classmethod
def parse(cls, rules):
Create a PluralRule instance for the given rules. If the rules are a PluralRule object, that object is returned.
Parameters
rulesthe rules as list or dict, or a PluralRule object
Raises
RuleErrorif the expression is malformed
tags =

Undocumented

def __call__(self, n):

Undocumented

def __getstate__(self):

Undocumented

def __init__(self, rules):
Initialize the rule instance.
Parameters
rulesa list of (tag, expr)) tuples with the rules conforming to UTS #35 or a dict with the tags as keys and expressions as values.
Raises
RuleErrorif the expression is malformed
def __repr__(self):

Undocumented

def __setstate__(self, abstract):

Undocumented

__slots__: tuple[str, ...] =

Undocumented

_func =

Undocumented

abstract =

Undocumented

@property
rules =

The PluralRule as a dict of unicode plural rules.

>>> rule = PluralRule({'one': 'n is 1'})
>>> rule.rules
{'one': 'n is 1'}