Skip to content

Commit

Permalink
[1.2.X] Fixed #11966 -- Made it possible to use a percent sign in a t…
Browse files Browse the repository at this point in the history
…ranslation 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
  • Loading branch information
jezdez committed Nov 4, 2010
1 parent fca56e8 commit 85f4dd6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions django/utils/translation/trans_real.py
Expand Up @@ -439,10 +439,11 @@ def templatize(src):
else: else:
singular.append('%%(%s)s' % t.contents) singular.append('%%(%s)s' % t.contents)
elif t.token_type == TOKEN_TEXT: elif t.token_type == TOKEN_TEXT:
contents = t.contents.replace('%', '%%')
if inplural: if inplural:
plural.append(t.contents) plural.append(contents)
else: else:
singular.append(t.contents) singular.append(contents)
else: else:
if t.token_type == TOKEN_BLOCK: if t.token_type == TOKEN_BLOCK:
imatch = inline_re.match(t.contents) imatch = inline_re.match(t.contents)
Expand Down
11 changes: 11 additions & 0 deletions tests/regressiontests/makemessages/extraction.py
Expand Up @@ -34,6 +34,17 @@ def assertNotMsgId(self, msgid, s):
return self.assert_(not re.search('^msgid "%s"' % msgid, s, re.MULTILINE)) 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): class JavascriptExtractorTests(ExtractorTests):


PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
Expand Down
4 changes: 3 additions & 1 deletion tests/regressiontests/makemessages/templates/test.html
@@ -1,2 +1,4 @@
{% load i18n %} {% load i18n %}
{% trans "This literal should be included." %} {% 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 %}

0 comments on commit 85f4dd6

Please sign in to comment.