Loading django/templatetags/i18n.py +5 −2 Original line number Diff line number Diff line from __future__ import unicode_literals import re from django.conf import settings from django.template import (Node, Variable, TemplateSyntaxError, TokenParser, Library, TOKEN_TEXT, TOKEN_VAR) from django.template.base import render_value_in_context Loading @@ -17,7 +18,6 @@ class GetAvailableLanguagesNode(Node): self.variable = variable def render(self, context): from django.conf import settings context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES] return '' Loading Loading @@ -143,7 +143,10 @@ class BlockTranslateNode(Node): result = translation.pgettext(message_context, singular) else: result = translation.ugettext(singular) data = dict([(v, render_value_in_context(context.get(v, ''), context)) for v in vars]) default_value = settings.TEMPLATE_STRING_IF_INVALID render_value = lambda v: render_value_in_context( context.get(v, default_value), context) data = dict([(v, render_value(v)) for v in vars]) context.pop() try: result = result % data Loading tests/template_tests/tests.py +4 −1 Original line number Diff line number Diff line Loading @@ -1392,7 +1392,10 @@ class Templates(TestCase): 'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, 'Dutch Nederlands False'), # blocktrans handling of variables which are not in the context. 'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ''), # this should work as if blocktrans was not there (bug #19915) 'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ('', 'INVALID')), 'i18n34_2': ("{% load i18n %}{% blocktrans with a='α' %}{{ missing }}{% endblocktrans %}", {}, ('', 'INVALID')), 'i18n34_3': ('{% load i18n %}{% blocktrans with a=anton %}{{ missing }}{% endblocktrans %}', {'anton': 'α'}, ('', 'INVALID')), # trans tag with as var 'i18n35': ('{% load i18n %}{% trans "Page not found" as page_not_found %}{{ page_not_found }}', {'LANGUAGE_CODE': 'de'}, "Seite nicht gefunden"), Loading Loading
django/templatetags/i18n.py +5 −2 Original line number Diff line number Diff line from __future__ import unicode_literals import re from django.conf import settings from django.template import (Node, Variable, TemplateSyntaxError, TokenParser, Library, TOKEN_TEXT, TOKEN_VAR) from django.template.base import render_value_in_context Loading @@ -17,7 +18,6 @@ class GetAvailableLanguagesNode(Node): self.variable = variable def render(self, context): from django.conf import settings context[self.variable] = [(k, translation.ugettext(v)) for k, v in settings.LANGUAGES] return '' Loading Loading @@ -143,7 +143,10 @@ class BlockTranslateNode(Node): result = translation.pgettext(message_context, singular) else: result = translation.ugettext(singular) data = dict([(v, render_value_in_context(context.get(v, ''), context)) for v in vars]) default_value = settings.TEMPLATE_STRING_IF_INVALID render_value = lambda v: render_value_in_context( context.get(v, default_value), context) data = dict([(v, render_value(v)) for v in vars]) context.pop() try: result = result % data Loading
tests/template_tests/tests.py +4 −1 Original line number Diff line number Diff line Loading @@ -1392,7 +1392,10 @@ class Templates(TestCase): 'i18n33': ('{% load i18n %}{{ langcode|language_name }} {{ langcode|language_name_local }} {{ langcode|language_bidi }}', {'langcode': 'nl'}, 'Dutch Nederlands False'), # blocktrans handling of variables which are not in the context. 'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ''), # this should work as if blocktrans was not there (bug #19915) 'i18n34': ('{% load i18n %}{% blocktrans %}{{ missing }}{% endblocktrans %}', {}, ('', 'INVALID')), 'i18n34_2': ("{% load i18n %}{% blocktrans with a='α' %}{{ missing }}{% endblocktrans %}", {}, ('', 'INVALID')), 'i18n34_3': ('{% load i18n %}{% blocktrans with a=anton %}{{ missing }}{% endblocktrans %}', {'anton': 'α'}, ('', 'INVALID')), # trans tag with as var 'i18n35': ('{% load i18n %}{% trans "Page not found" as page_not_found %}{{ page_not_found }}', {'LANGUAGE_CODE': 'de'}, "Seite nicht gefunden"), Loading