Esempio n. 1
0
def get_plural(amount, variants):
    """
    Get proper form for plural and it value.

    Value is a amount, parameters are forms of noun.
    Forms are variants for 1, 2, 5 nouns. It may be tuple
    of elements, or string where variants separates each other
    by comma. You can append 'absence variant' after all over variants

    Examples::
        {{ some_int|get_plural:"пример,примера,примеров,нет примеров" }}
    """
    try:
        if isinstance(variants, basestring):
            uvariants = pseudo_unicode(variants, encoding, default_value)
        else:
            uvariants = [pseudo_unicode(v, encoding, default_uvalue) for v in variants]
        ures = numeral._get_plural_legacy(amount, uvariants)
        res = pseudo_str(
            ures,
            encoding,
            default_value
            )
    except Exception, err:
        # because filter must die silently
        try:
            default_variant = variants
        except Exception:
            default_variant = ""
        res = default_value % {'error': err, 'value': default_variant}
def get_plural(amount, variants):
    """
    Get proper form for plural and it value.

    Value is a amount, parameters are forms of noun.
    Forms are variants for 1, 2, 5 nouns. It may be tuple
    of elements, or string where variants separates each other
    by comma. You can append 'absence variant' after all over variants

    Examples::
        {{ some_int|get_plural:"пример,примера,примеров,нет примеров" }}
    """
    try:
        if isinstance(variants, basestring):
            uvariants = pseudo_unicode(variants, encoding, default_value)
        else:
            uvariants = [
                pseudo_unicode(v, encoding, default_uvalue) for v in variants
            ]
        ures = numeral._get_plural_legacy(amount, uvariants)
        res = pseudo_str(ures, encoding, default_value)
    except Exception, err:
        # because filter must die silently
        try:
            default_variant = variants
        except Exception:
            default_variant = ""
        res = default_value % {'error': err, 'value': default_variant}
Esempio n. 3
0
def get_plural(amount, variants):
    """
    Get proper form for plural and it value.

    Value is a amount, parameters are forms of noun.
    Forms are variants for 1, 2, 5 nouns. It may be tuple
    of elements, or string where variants separates each other
    by comma. You can append 'absence variant' after all over variants

    Examples::
        {{ some_int|get_plural:"пример,примера,примеров,нет примеров" }}
    """
    try:
        if isinstance(variants, six.string_types):
            uvariants = smart_text(variants, encoding)
        else:
            uvariants = [smart_text(v, encoding) for v in variants]
        res = numeral._get_plural_legacy(amount, uvariants)
    except Exception as err:
        # because filter must die silently
        try:
            default_variant = variants
        except Exception:
            default_variant = ""
        res = default_value % {"error": err, "value": default_variant}
    return res