Index: django/templatetags/i18n.py =================================================================== --- django/templatetags/i18n.py (revision 10826) +++ django/templatetags/i18n.py (working copy) @@ -1,7 +1,7 @@ import re from django.template import Node, Variable, VariableNode, _render_value_in_context -from django.template import TemplateSyntaxError, TokenParser, Library +from django.template import TemplateSyntaxError, TokenParser, Library, Parser from django.template import TOKEN_TEXT, TOKEN_VAR from django.utils import translation from django.utils.encoding import force_unicode @@ -56,13 +56,13 @@ def render_token_list(self, tokens): result = [] - vars = [] + vars = {} for token in tokens: if token.token_type == TOKEN_TEXT: result.append(token.contents) elif token.token_type == TOKEN_VAR: result.append(u'%%(%s)s' % token.contents) - vars.append(token.contents) + vars[token.contents] = token return ''.join(result), vars def render(self, context): @@ -82,8 +82,15 @@ result = translation.ugettext(singular) # Escape all isolated '%' before substituting in the context. result = re.sub(u'%(?!\()', u'%%', result) + + # Resolve simple variables and add them to the context + resolved_context = {} + for key, value in vars.iteritems(): + resolved_context[key] = Parser([value]).parse().render(context) + context.update(resolved_context) data = dict([(v, _render_value_in_context(context[v], context)) for v in vars]) context.pop() + context.pop() return result % data def do_get_available_languages(parser, token):