Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #18881 -- Made the context option in {% trans %} and {% blocktr…

…ans %} accept literals wrapped in single quotes. Thanks to lanyjie for the report.
  • Loading branch information...
commit b8244c654c85034bd4209a93a7802eb306c32e2b 1 parent 751a7d0
Julien Phalip authored September 27, 2012
4  django/utils/translation/trans_real.py
@@ -437,8 +437,8 @@ def blankout(src, char):
437 437
     return dot_re.sub(char, src)
438 438
 
439 439
 context_re = re.compile(r"""^\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?'))\s*""")
440  
-inline_re = re.compile(r"""^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(\s+.*context\s+(?:"[^"]*?")|(?:'[^']*?'))?\s*""")
441  
-block_re = re.compile(r"""^\s*blocktrans(\s+.*context\s+(?:"[^"]*?")|(?:'[^']*?'))?(?:\s+|$)""")
  440
+inline_re = re.compile(r"""^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?\s*""")
  441
+block_re = re.compile(r"""^\s*blocktrans(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?(?:\s+|$)""")
442 442
 endblock_re = re.compile(r"""^\s*endblocktrans$""")
443 443
 plural_re = re.compile(r"""^\s*plural$""")
444 444
 constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""")
15  tests/regressiontests/i18n/commands/extraction.py
@@ -156,6 +156,21 @@ def test_template_message_context_extractor(self):
156 156
             self.assertTrue('msgctxt "Special blocktrans context #4"' in po_contents)
157 157
             self.assertTrue("Translatable literal #8d" in po_contents)
158 158
 
  159
+    def test_context_in_single_quotes(self):
  160
+        os.chdir(self.test_dir)
  161
+        management.call_command('makemessages', locale=LOCALE, verbosity=0)
  162
+        self.assertTrue(os.path.exists(self.PO_FILE))
  163
+        with open(self.PO_FILE, 'r') as fp:
  164
+            po_contents = fp.read()
  165
+            # {% trans %}
  166
+            self.assertTrue('msgctxt "Context wrapped in double quotes"' in po_contents)
  167
+            self.assertTrue('msgctxt "Context wrapped in single quotes"' in po_contents)
  168
+
  169
+            # {% blocktrans %}
  170
+            self.assertTrue('msgctxt "Special blocktrans context wrapped in double quotes"' in po_contents)
  171
+            self.assertTrue('msgctxt "Special blocktrans context wrapped in single quotes"' in po_contents)
  172
+
  173
+
159 174
 class JavascriptExtractorTests(ExtractorTests):
160 175
 
161 176
     PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
5  tests/regressiontests/i18n/commands/templates/test.html
@@ -77,3 +77,8 @@
77 77
 {% trans "Shouldn't double escape this sequence %% either" context "ctx1" %}
78 78
 {% trans "Looks like a str fmt spec %s but shouldn't be interpreted as such" %}
79 79
 {% trans "Looks like a str fmt spec % o but shouldn't be interpreted as such" %}
  80
+
  81
+{% trans "Translatable literal with context wrapped in single quotes" context 'Context wrapped in single quotes' as var %}
  82
+{% trans "Translatable literal with context wrapped in double quotes" context "Context wrapped in double quotes" as var %}
  83
+{% blocktrans context 'Special blocktrans context wrapped in single quotes' %}Translatable literal with context wrapped in single quotes{% endblocktrans %}
  84
+{% blocktrans context "Special blocktrans context wrapped in double quotes" %}Translatable literal with context wrapped in double quotes{% endblocktrans %}

0 notes on commit b8244c6

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