diff options
| author | Jannis Leidel <jannis@leidel.info> | 2010-11-04 14:15:16 +0000 |
|---|---|---|
| committer | Jannis Leidel <jannis@leidel.info> | 2010-11-04 14:15:16 +0000 |
| commit | 85f4dd6353b9254ccf1dc5b4393b028f2eb3c4ab (patch) | |
| tree | c106be92591a7890562e0a26ac573414f9c14f5c | |
| parent | fca56e845065da91e13b6511cc8cf7b70ad1272e (diff) | |
[1.2.X] Fixed #11966 -- Made it possible to use a percent sign in a translation message id. Thanks for the patch, Claude Paroz.
Backport from trunk (r14459).
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14460 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/utils/translation/trans_real.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/makemessages/extraction.py | 11 | ||||
| -rw-r--r-- | tests/regressiontests/makemessages/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 b528f8e586..feb2f41ac1 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -439,10 +439,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/makemessages/extraction.py b/tests/regressiontests/makemessages/extraction.py index 4b4fa1b07e..6df6e90211 100644 --- a/tests/regressiontests/makemessages/extraction.py +++ b/tests/regressiontests/makemessages/extraction.py @@ -34,6 +34,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/makemessages/templates/test.html b/tests/regressiontests/makemessages/templates/test.html index 2c38b3e4e6..96438e1b63 100644 --- a/tests/regressiontests/makemessages/templates/test.html +++ b/tests/regressiontests/makemessages/templates/test.html @@ -1,2 +1,4 @@ {% load i18n %} -{% trans "This literal should be included." %}
\ No newline at end of file +{% trans "This literal should be included." %} +{% 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 |
