Ticket #15632: 15632-2.diff

File 15632-2.diff, 2.7 KB (added by claudep, 4 years ago)

Same patch which doesn't replace newlines (following ramiro's idea)

  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 675fb3f..5839e74 100644
    a b def templatize(src, origin=None): 
    435435    does so by translating the Django translation tags into standard gettext
    436436    function invocations.
    437437    """
    438     from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, TOKEN_COMMENT
     438    from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, TOKEN_COMMENT, TRANSLATOR_COMMENT_MARK
    439439    out = StringIO()
    440440    intrans = False
    441441    inplural = False
    def templatize(src, origin=None): 
    446446    for t in Lexer(src, origin).tokenize():
    447447        if incomment:
    448448            if t.token_type == TOKEN_BLOCK and t.contents == 'endcomment':
    449                 out.write(' # %s' % ''.join(comment))
     449                content = u''.join(comment).lstrip()
     450                if content.startswith(TRANSLATOR_COMMENT_MARK):
     451                    for line in content.splitlines(True):
     452                        out.write(u' # %s' % line)
    450453                incomment = False
    451454                comment = []
    452455            else:
  • tests/regressiontests/i18n/commands/extraction.py

    diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
    index 1f36b8a..c7b25d2 100644
    a b class BasicExtractorTests(ExtractorTests): 
    4949        self.assertTrue('This comment should not be extracted' not in po_contents)
    5050        # Comments in templates
    5151        self.assertTrue('#. Translators: Django template comment for translators' in po_contents)
    52         self.assertTrue('#. Translators: Django comment block for translators' in po_contents)
     52        self.assertTrue("#. Translators: Django comment block for translators\n#. string's meaning unveiled" in po_contents)
    5353
    5454    def test_templatize(self):
    5555        os.chdir(self.test_dir)
  • 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 ff8485e..cbe0752 100644
    a b  
    11{% load i18n %}
    2 {% comment %}Translators: Django comment block for translators {% endcomment %}
     2{% comment %}Translators: Django comment block for translators
     3string's meaning unveiled
     4{% endcomment %}
    35{% trans "This literal should be included." %}
    46{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
    57
Back to Top