class PluralRule(object):
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. |
PluralRule
instance for the given rules. If the rules
are a PluralRule
object, that object is returned.Parameters | |
rules | the rules as list or dict, or a PluralRule object |
Raises | |
RuleError | if the expression is malformed |
Parameters | |
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. |
Raises | |
RuleError | if the expression is malformed |
The PluralRule
as a dict of unicode plural rules.
>>> rule = PluralRule({'one': 'n is 1'}) >>> rule.rules {'one': 'n is 1'}