Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made makemessages leave `'%%'` sequences untouched when extracting tr…

…anslatable literals from blocktrans template tags.

This makes it consistent with behavior introduced when fixing #11240 in
processing of literal passed to the trans tag to avoid double escaping
(i.e. `'%%%%'` sequences in resulting PO files.)

Also, cleaned up tests changes from r17190 (removed commented out code and
implemented compatibility with Python 2.5.)

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17192 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f2e99ecfdad245e9425bad038d5006912728e10d 1 parent 12a20b6
@ramiro ramiro authored
View
2  django/utils/translation/trans_real.py
@@ -514,7 +514,7 @@ def templatize(src, origin=None):
else:
singular.append('%%(%s)s' % t.contents)
elif t.token_type == TOKEN_TEXT:
- contents = t.contents.replace('%', '%%')
+ contents = one_percent_re.sub('%%', t.contents)
if inplural:
plural.append(contents)
else:
View
15 tests/regressiontests/i18n/commands/extraction.py
@@ -1,4 +1,6 @@
# -*- encoding: utf-8 -*-
+from __future__ import with_statement
+
import os
import re
import shutil
@@ -52,7 +54,6 @@ def test_comments_extractor(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertTrue('#. Translators: This comment should be extracted' in po_contents)
@@ -81,7 +82,6 @@ def test_templatize_trans_tag(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('Literal with a percent symbol at the end %%', po_contents)
@@ -98,11 +98,11 @@ def test_templatize_blocktrans_tag(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents)
+ self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents)
def test_extraction_error(self):
os.chdir(self.test_dir)
@@ -128,7 +128,6 @@ def test_template_message_context_extractor(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
# {% trans %}
@@ -159,7 +158,6 @@ def test_javascript_literals(self):
os.chdir(self.test_dir)
management.call_command('makemessages', domain='djangojs', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents)
@@ -183,7 +181,6 @@ def test_ignore_option(self):
pattern1 = os.path.join('ignore_dir', '*')
management.call_command('makemessages', locale=LOCALE, verbosity=0, ignore_patterns=[pattern1])
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents)
@@ -215,7 +212,6 @@ def test_symlink(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents)
@@ -228,7 +224,6 @@ def test_copy_plural_forms(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
@@ -240,7 +235,6 @@ def test_no_wrap_enabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents)
@@ -249,7 +243,6 @@ def test_no_wrap_disabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)
@@ -261,7 +254,6 @@ def test_no_location_enabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertFalse('#: templates/test.html:55' in po_contents)
@@ -270,7 +262,6 @@ def test_no_location_disabled(self):
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
self.assertTrue(os.path.exists(self.PO_FILE))
- #po_contents = open(self.PO_FILE, 'r').read()
with open(self.PO_FILE, 'r') as fp:
po_contents = fp.read()
self.assertTrue('#: templates/test.html:55' in po_contents)
View
2  tests/regressiontests/i18n/commands/templates/test.html
@@ -67,6 +67,8 @@
{% blocktrans context "Special blocktrans context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktrans %}
{% blocktrans with a=1 context "Special blocktrans context #4" %}Translatable literal #8d {{ a }}{% endblocktrans %}
+{% blocktrans with a=1 %}Blocktrans extraction shouldn't double escape this: %%, a={{ a }}{% endblocktrans %}
+
{% trans "Literal with a percent symbol at the end %" %}
{% trans "Literal with a percent % symbol in the middle" %}
{% trans "Completed 50% of all the tasks" %}
Please sign in to comment.
Something went wrong with that request. Please try again.