diff options
author | Florian Apolloner <florian@apolloner.eu> | 2012-01-18 17:47:54 +0100 |
---|---|---|
committer | Florian Apolloner <florian@apolloner.eu> | 2012-01-18 17:47:54 +0100 |
commit | 79c8475f80257be4999a20d1432ff6a8e3f38815 (patch) | |
tree | f9bbbb3f42ab66f22e3da666beaaa0599581c36e /jinja2 | |
parent | 5a25a47996e8a2ad93fa92217f9247dea9a3c424 (diff) | |
download | jinja2-79c8475f80257be4999a20d1432ff6a8e3f38815.tar.gz |
fix previous commit, which was kinda nonfunctional
Diffstat (limited to 'jinja2')
-rw-r--r-- | jinja2/ext.py | 11 | ||||
-rw-r--r-- | jinja2/testsuite/ext.py | 6 |
2 files changed, 12 insertions, 5 deletions
diff --git a/jinja2/ext.py b/jinja2/ext.py index 1d888a2..78d2429 100644 --- a/jinja2/ext.py +++ b/jinja2/ext.py @@ -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.""" diff --git a/jinja2/testsuite/ext.py b/jinja2/testsuite/ext.py index b9ffa66..2a16701 100644 --- a/jinja2/testsuite/ext.py +++ b/jinja2/testsuite/ext.py @@ -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): |