Пример #1
0
    def test_po_plural_forms(self):
        po_plural_form = '(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'
        po_python_expr =  lambda n: 0 if n == 1 else 1 if (n % 10 >= 2 and n % 10 <= 4 and (n % 100 < 10 or n % 100 >= 20)) else 2

        expr = expr_parser.parse(po_plural_form)
        for i in range(200):
            self.assertEqual(expr_parser.calculate(expr, i), po_python_expr(i))
Пример #2
0
    def test_po_plural_forms(self):
        po_plural_form = '(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2)'
        po_python_expr = lambda n: 0 if n == 1 else 1 if (
            n % 10 >= 2 and n % 10 <= 4 and
            (n % 100 < 10 or n % 100 >= 20)) else 2

        expr = expr_parser.parse(po_plural_form)
        for i in range(200):
            self.assertEqual(expr_parser.calculate(expr, i), po_python_expr(i))
Пример #3
0
    def _decorator(f):
        f.gettext_rule = rule
        f.gettext_num_plurals = num_plurals

        ruleexpression = expr_parser.parse(rule)
        f.gettext_forms = {}
        for form, num in example_numbers(f):
            # Match the gettext msgstr index (computed by the plural= rule) to a codename for the same number
            f.gettext_forms.setdefault(int(expr_parser.calculate(ruleexpression, num)), []).append(form)

        # when we get all expressions working, this should pass:
        #assert num_plurals == len(f.gettext_forms)
        return f
Пример #4
0
    def _decorator(f):
        f.gettext_rule = rule
        f.gettext_num_plurals = num_plurals

        ruleexpression = expr_parser.parse(rule)
        f.gettext_forms = {}
        for form, num in example_numbers(f):
            # Match the gettext msgstr index (computed by the plural= rule) to a codename for the same number
            f.gettext_forms.setdefault(expr_parser.calculate(ruleexpression, num), []).append(form)

        # when we get all expressions working, this should pass:
        #assert num_plurals == len(f.gettext_forms)
        return f