Ticket #18881: 18881.trans-context-single-quotes.diff

File 18881.trans-context-single-quotes.diff, 3.4 KB (added by julien, 3 years ago)
  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 9fd33a7..6911c2c 100644
    a b def blankout(src, char): 
    437437    return dot_re.sub(char, src)
    438438
    439439context_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+|$)""")
     440inline_re = re.compile(r"""^\s*trans\s+((?:"[^"]*?")|(?:'[^']*?'))(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?\s*""")
     441block_re = re.compile(r"""^\s*blocktrans(\s+.*context\s+((?:"[^"]*?")|(?:'[^']*?')))?(?:\s+|$)""")
    442442endblock_re = re.compile(r"""^\s*endblocktrans$""")
    443443plural_re = re.compile(r"""^\s*plural$""")
    444444constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""")
  • tests/regressiontests/i18n/commands/extraction.py

    diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
    index 29d9e27..ca2c3cc 100644
    a b class BasicExtractorTests(ExtractorTests): 
    156156            self.assertTrue('msgctxt "Special blocktrans context #4"' in po_contents)
    157157            self.assertTrue("Translatable literal #8d" in po_contents)
    158158
     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
    159174class JavascriptExtractorTests(ExtractorTests):
    160175
    161176    PO_FILE='locale/%s/LC_MESSAGES/djangojs.po' % LOCALE
  • tests/regressiontests/i18n/commands/templates/test.html

    diff --git a/tests/regressiontests/i18n/commands/templates/test.html b/tests/regressiontests/i18n/commands/templates/test.html
    index 5789346..e7d7f3c 100644
    a b continued here.{% endcomment %} 
    7777{% trans "Shouldn't double escape this sequence %% either" context "ctx1" %}
    7878{% trans "Looks like a str fmt spec %s but shouldn't be interpreted as such" %}
    7979{% 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 %}
     85 No newline at end of file
Back to Top