Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11966 -- Made it possible to use a percent sign in a translati…

…on message id. Thanks for the patch, Claude Paroz.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14459 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 127506aeacc09f07e8e6b7c694423579f9663371 1 parent 6feef0c
Jannis Leidel authored November 04, 2010
5  django/utils/translation/trans_real.py
@@ -463,10 +463,11 @@ def templatize(src):
463 463
                 else:
464 464
                     singular.append('%%(%s)s' % t.contents)
465 465
             elif t.token_type == TOKEN_TEXT:
  466
+                contents = t.contents.replace('%', '%%')
466 467
                 if inplural:
467  
-                    plural.append(t.contents)
  468
+                    plural.append(contents)
468 469
                 else:
469  
-                    singular.append(t.contents)
  470
+                    singular.append(contents)
470 471
         else:
471 472
             if t.token_type == TOKEN_BLOCK:
472 473
                 imatch = inline_re.match(t.contents)
11  tests/regressiontests/i18n/commands/extraction.py
@@ -38,6 +38,17 @@ def assertNotMsgId(self, msgid, s, use_quotes=True):
38 38
         return self.assert_(not re.search('^msgid %s' % msgid, s, re.MULTILINE))
39 39
 
40 40
 
  41
+class TemplateExtractorTests(ExtractorTests):
  42
+
  43
+    def test_templatize(self):
  44
+        os.chdir(self.test_dir)
  45
+        management.call_command('makemessages', locale=LOCALE, verbosity=0)
  46
+        self.assert_(os.path.exists(self.PO_FILE))
  47
+        po_contents = open(self.PO_FILE, 'r').read()
  48
+        self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
  49
+        self.assertMsgId('I think that 100%% is more that 50%% of %\(obj\)s.', po_contents)
  50
+
  51
+
41 52
 class JavascriptExtractorTests(ExtractorTests):
42 53
 
43 54
     PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
4  tests/regressiontests/i18n/commands/templates/test.html
... ...
@@ -1,3 +1,5 @@
1 1
 {% load i18n %}
2 2
 {% trans "This literal should be included." %}
3  
-{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
  3
+{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
  4
+{% blocktrans %}I think that 100% is more that 50% of anything.{% endblocktrans %}
  5
+{% blocktrans with 'txt' as obj %}I think that 100% is more that 50% of {{ obj }}.{% endblocktrans %}

0 notes on commit 127506a

Please sign in to comment.
Something went wrong with that request. Please try again.