Ticket #15632: 15632-1.diff

File 15632-1.diff, 2.6 KB (added by Claude Paroz, 13 years ago)

Handle properly multiline translator comments

  • django/utils/translation/trans_real.py

    diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
    index 675fb3f..0f1e226 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).strip()
     450                if content.startswith(TRANSLATOR_COMMENT_MARK):
     451                    out.write(u' # %s' % content.replace('\n', ' '))
    450452                incomment = False
    451453                comment = []
    452454            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..5258df9 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 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