Author: ramiro Date: 2011-12-10 16:48:26 -0800 (Sat, 10 Dec 2011) New Revision: 17192
Modified: django/trunk/django/utils/translation/trans_real.py django/trunk/tests/regressiontests/i18n/commands/extraction.py django/trunk/tests/regressiontests/i18n/commands/templates/test.html Log: Made makemessages leave `'%%'` sequences untouched when extracting translatable 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.) Modified: django/trunk/django/utils/translation/trans_real.py =================================================================== --- django/trunk/django/utils/translation/trans_real.py 2011-12-11 00:09:30 UTC (rev 17191) +++ django/trunk/django/utils/translation/trans_real.py 2011-12-11 00:48:26 UTC (rev 17192) @@ -514,7 +514,7 @@ 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: Modified: django/trunk/tests/regressiontests/i18n/commands/extraction.py =================================================================== --- django/trunk/tests/regressiontests/i18n/commands/extraction.py 2011-12-11 00:09:30 UTC (rev 17191) +++ django/trunk/tests/regressiontests/i18n/commands/extraction.py 2011-12-11 00:48:26 UTC (rev 17192) @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +from __future__ import with_statement + import os import re import shutil @@ -52,7 +54,6 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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) Modified: django/trunk/tests/regressiontests/i18n/commands/templates/test.html =================================================================== --- django/trunk/tests/regressiontests/i18n/commands/templates/test.html 2011-12-11 00:09:30 UTC (rev 17191) +++ django/trunk/tests/regressiontests/i18n/commands/templates/test.html 2011-12-11 00:48:26 UTC (rev 17192) @@ -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" %} -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.