Ticket #15632: 15632-5.diff

File 15632-5.diff, 5.1 KB (added by Ramiro Morales, 13 years ago)

New patch for the issue -- preseves line numbers in .po file comments, expanded tests

  • django/utils/translation/trans_real.py

    diff -r c157247a9018 django/utils/translation/trans_real.py
    a b  
    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,
     439            TOKEN_COMMENT, TRANSLATOR_COMMENT_MARK)
    439440    out = StringIO()
    440441    intrans = False
    441442    inplural = False
     
    446447    for t in Lexer(src, origin).tokenize():
    447448        if incomment:
    448449            if t.token_type == TOKEN_BLOCK and t.contents == 'endcomment':
    449                 out.write(' # %s' % ''.join(comment))
     450                content = u''.join(comment)
     451                translators_comment_start = None
     452                for lineno, line in enumerate(content.splitlines(True)):
     453                    if line.lstrip().startswith(TRANSLATOR_COMMENT_MARK):
     454                        translators_comment_start = lineno
     455                for lineno, line in enumerate(content.splitlines(True)):
     456                    if translators_comment_start is not None and lineno >= translators_comment_start:
     457                        out.write(u' # %s' % line)
     458                    else:
     459                        out.write(u' #\n')
    450460                incomment = False
    451461                comment = []
    452462            else:
  • tests/regressiontests/i18n/commands/extraction.py

    diff -r c157247a9018 tests/regressiontests/i18n/commands/extraction.py
    a b  
    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)
     53
     54        self.assertTrue('#. Translators: One-line translator comment #1' in po_contents)
     55        self.assertTrue('#. Translators: Two-line translator comment #1\n#. continued here.' in po_contents)
     56
     57        self.assertTrue('#. Translators: One-line translator comment #2' in po_contents)
     58        self.assertTrue('#. Translators: Two-line translator comment #2\n#. continued here.' in po_contents)
     59
     60        self.assertTrue('#. Translators: One-line translator comment #3' in po_contents)
     61        self.assertTrue('#. Translators: Two-line translator comment #3\n#. continued here.' in po_contents)
     62
     63        self.assertTrue('#. Translators: One-line translator comment #4' in po_contents)
     64        self.assertTrue('#. Translators: Two-line translator comment #4\n#. continued here.' in po_contents)
    5365
    5466    def test_templatize(self):
    5567        os.chdir(self.test_dir)
  • tests/regressiontests/i18n/commands/templates/test.html

    diff -r c157247a9018 tests/regressiontests/i18n/commands/templates/test.html
    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
    68{# Translators: Django template comment for translators #}
    79<p>{% blocktrans %}I think that 100% is more that 50% of anything.{% endblocktrans %}</p>
    810{% blocktrans with 'txt' as obj %}I think that 100% is more that 50% of {{ obj }}.{% endblocktrans %}
     11
     12{% comment %}Some random comment
     13Some random comment
     14Translators: One-line translator comment #1
     15{% endcomment %}
     16{% trans "Translatable literal #1a" %}
     17
     18{% comment %}Some random comment
     19Some random comment
     20Translators: Two-line translator comment #1
     21continued here.
     22{% endcomment %}
     23{% trans "Translatable literal #1b" %}
     24
     25{% comment %}Some random comment
     26Translators: One-line translator comment #2
     27{% endcomment %}
     28{% trans "Translatable literal #2a" %}
     29
     30{% comment %}Some random comment
     31Translators: Two-line translator comment #2
     32continued here.
     33{% endcomment %}
     34{% trans "Translatable literal #2b" %}
     35
     36{% comment %}
     37    Translators: One-line translator comment #3
     38{% endcomment %}
     39{% trans "Translatable literal #3a" %}
     40
     41{% comment %}
     42Translators: Two-line translator comment #3
     43continued here.
     44{% endcomment %}
     45{% trans "Translatable literal #3b" %}
     46
     47{% comment %} Translators: One-line translator comment #4{% endcomment %}
     48{% trans "Translatable literal #4a" %}
     49
     50{% comment %}  Translators: Two-line translator comment #4
     51continued here.{% endcomment %}
     52{% trans "Translatable literal #4b" %}
Back to Top