From 127506aeacc09f07e8e6b7c694423579f9663371 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Thu, 4 Nov 2010 14:06:24 +0000 Subject: [PATCH] Fixed #11966 -- Made it possible to use a percent sign in a translation message id. Thanks for the patch, Claude Paroz. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14459 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/translation/trans_real.py | 5 +++-- tests/regressiontests/i18n/commands/extraction.py | 11 +++++++++++ .../regressiontests/i18n/commands/templates/test.html | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 8486fdf8f4..827337c837 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -463,10 +463,11 @@ def templatize(src): else: singular.append('%%(%s)s' % t.contents) elif t.token_type == TOKEN_TEXT: + contents = t.contents.replace('%', '%%') if inplural: - plural.append(t.contents) + plural.append(contents) else: - singular.append(t.contents) + singular.append(contents) else: if t.token_type == TOKEN_BLOCK: imatch = inline_re.match(t.contents) diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py index 7b064d1daa..116dfa6420 100644 --- a/tests/regressiontests/i18n/commands/extraction.py +++ b/tests/regressiontests/i18n/commands/extraction.py @@ -38,6 +38,17 @@ class ExtractorTests(TestCase): return self.assert_(not re.search('^msgid %s' % msgid, s, re.MULTILINE)) +class TemplateExtractorTests(ExtractorTests): + + def test_templatize(self): + os.chdir(self.test_dir) + management.call_command('makemessages', locale=LOCALE, verbosity=0) + self.assert_(os.path.exists(self.PO_FILE)) + po_contents = open(self.PO_FILE, 'r').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) + + class JavascriptExtractorTests(ExtractorTests): PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE diff --git a/tests/regressiontests/i18n/commands/templates/test.html b/tests/regressiontests/i18n/commands/templates/test.html index 7574efa863..e1c3eee573 100644 --- a/tests/regressiontests/i18n/commands/templates/test.html +++ b/tests/regressiontests/i18n/commands/templates/test.html @@ -1,3 +1,5 @@ {% load i18n %} {% trans "This literal should be included." %} -{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %} \ No newline at end of file +{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %} +{% blocktrans %}I think that 100% is more that 50% of anything.{% endblocktrans %} +{% blocktrans with 'txt' as obj %}I think that 100% is more that 50% of {{ obj }}.{% endblocktrans %} \ No newline at end of file