]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
fix previous commit, which was kinda nonfunctional 89/head
authorFlorian Apolloner <florian@apolloner.eu>
Wed, 18 Jan 2012 16:47:54 +0000 (17:47 +0100)
committerFlorian Apolloner <florian@apolloner.eu>
Wed, 18 Jan 2012 16:47:54 +0000 (17:47 +0100)
jinja2/ext.py
jinja2/testsuite/ext.py

index 1d888a2ab20a1ab6eefcd0aaa53138d82adaee85..78d2429cd20256d84a11368aa1a2693a5547ed8c 100644 (file)
@@ -218,6 +218,7 @@ class InternationalizationExtension(Extension):
         # defined in the body of the trans block too, but this is checked at
         # a later state.
         plural_expr = None
+        plural_expr_assignment = None
         variables = {}
         while parser.stream.current.type != 'block_end':
             if variables:
@@ -242,7 +243,10 @@ class InternationalizationExtension(Extension):
 
             if plural_expr is None:
                 if isinstance(var, nodes.Call):
-                    plural_expr = nodes.Name(name.value, 'load')
+                    plural_expr = nodes.Name('_trans', 'load')
+                    variables[name.value] = plural_expr
+                    plural_expr_assignment = nodes.Assign(
+                        nodes.Name('_trans', 'store'), var)
                 else:
                     plural_expr = var
                 num_called_num = name.value == 'num'
@@ -294,7 +298,10 @@ class InternationalizationExtension(Extension):
                                bool(referenced),
                                num_called_num and have_plural)
         node.set_lineno(lineno)
-        return node
+        if plural_expr_assignment is not None:
+            return [plural_expr_assignment, node]
+        else:
+            return node
 
     def _parse_block(self, parser, allow_pluralize):
         """Parse until the next block tag with a given name."""
index b9ffa66b54e68cd95560d05f72830bbb51caaa88..2a1670114a03ef3f5d681d53b2185ba4a3816057 100644 (file)
@@ -38,8 +38,8 @@ i18n_templates = {
                   '{% trans %}watch out{% endtrans %}{% endblock %}',
     'plural.html': '{% trans user_count %}One user online{% pluralize %}'
                    '{{ user_count }} users online{% endtrans %}',
-    'plural2.html': '{% trans user_count=get_user_count() %}{{ user_count }}'
-                    '{% pluralize %}{{ user_count }}{% endtrans %}',
+    'plural2.html': '{% trans user_count=get_user_count() %}{{ user_count }}s'
+                    '{% pluralize %}{{ user_count }}p{% endtrans %}',
     'stringformat.html': '{{ _("User: %(num)s")|format(num=user_count) }}'
 }
 
@@ -267,7 +267,7 @@ class InternationalizationTestCase(JinjaTestCase):
             get_user_count.called += 1
             return 1
         get_user_count.called = 0
-        assert tmpl.render(LANGUAGE='de', get_user_count=get_user_count) == '1'
+        assert tmpl.render(LANGUAGE='de', get_user_count=get_user_count) == '1s'
         assert get_user_count.called == 1
 
     def test_complex_plural(self):