translationstring.Pluralizer() provides a gettext "plural forms"
It is called like so:
1 2 3 4
import gettext from translationstring import Pluralizer translations = gettext.translations(.. the right arguments ...) pluralizer = Pluralizer(translations)
translations argument is required; it should be an object
supporting at least the Python
but ideally the
babel.support.Translations API, which has
support for domain lookups like dungettext.
The object returned will be a callable which has the following signature:
def pluralizer(singular, plural, n, domain=None, mapping=None): """ Pluralize """
plural arguments passed may be translation
strings or unicode strings.
n represents the number of elements.
domain is the translation domain to use to do the pluralization,
mapping is the interpolation mapping that should be used on
the result. The pluralizer will return the plural form or the
singular form, translated, as necessary.
if the objects passed are translation strings, their domains and
mappings are ignored. The domain and mapping arguments must be used
instead. If the
domain is not supplied, a default domain is
object is created for the pluralizer to use.
translationstring.Pluralizer() function accepts an
additional optional argument named
policy should be a
callable which accepts five arguments:
domain. It must perform the actual
pluralization lookup. If
translationstring.dungettext_policy() policy will be used.