summaryrefslogtreecommitdiff
path: root/django/templatetags
diff options
context:
space:
mode:
authorDoug Beck <doug@douglasbeck.com>2015-04-15 17:01:11 -0400
committerTim Graham <timograham@gmail.com>2015-08-12 10:23:34 -0400
commitb7508896fbe19ec2cdeb81565cd587091b6b68d0 (patch)
tree5efb501dcc753cdaf1314ba826ca59cd44c4297b /django/templatetags
parentd772d812cf583e0f99e21850f26addf1d59bfa35 (diff)
Fixed #24257 -- Corrected i18n handling of percent signs.
Refactored tests to use a sample project. Updated extraction: * Removed special handling of single percent signs. * When extracting messages from template text, doubled all percent signs so they are not interpreted by gettext as string format flags. All strings extracted by gettext, if containing a percent sign, will now be labeled "#, python-format". Updated translation: * Used "%%" for "%" in template text before calling gettext. * Updated {% trans %} rendering to restore "%" from "%%".
Diffstat (limited to 'django/templatetags')
-rw-r--r--django/templatetags/i18n.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py
index 4e77aaece4..050ef2c741 100644
--- a/django/templatetags/i18n.py
+++ b/django/templatetags/i18n.py
@@ -7,6 +7,7 @@ from django.template import Library, Node, TemplateSyntaxError, Variable
from django.template.base import TOKEN_TEXT, TOKEN_VAR, render_value_in_context
from django.template.defaulttags import token_kwargs
from django.utils import six, translation
+from django.utils.safestring import SafeData, mark_safe
register = Library()
@@ -86,6 +87,11 @@ class TranslateNode(Node):
self.message_context.resolve(context))
output = self.filter_expression.resolve(context)
value = render_value_in_context(output, context)
+ # Restore percent signs. Percent signs in template text are doubled
+ # so they are not interpreted as string format flags.
+ is_safe = isinstance(value, SafeData)
+ value = value.replace('%%', '%')
+ value = mark_safe(value) if is_safe else value
if self.asvar:
context[self.asvar] = value
return ''