# 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:
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'
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."""
'{% 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) }}'
}
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):