Fixed #15632 -- Ignore unrelated content in template multi-line comment blocks when looking for tokens that identify comments for translators. Thanks andrew AT ie-grad DOT ru for the report and Claude Paroz for spotting the problem and helping to fix it.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15882 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
1a6d98dab9
commit
775a6e694f
|
@ -435,7 +435,8 @@ def templatize(src, origin=None):
|
|||
does so by translating the Django translation tags into standard gettext
|
||||
function invocations.
|
||||
"""
|
||||
from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK, TOKEN_COMMENT
|
||||
from django.template import (Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK,
|
||||
TOKEN_COMMENT, TRANSLATOR_COMMENT_MARK)
|
||||
out = StringIO()
|
||||
intrans = False
|
||||
inplural = False
|
||||
|
@ -446,7 +447,16 @@ def templatize(src, origin=None):
|
|||
for t in Lexer(src, origin).tokenize():
|
||||
if incomment:
|
||||
if t.token_type == TOKEN_BLOCK and t.contents == 'endcomment':
|
||||
out.write(' # %s' % ''.join(comment))
|
||||
content = u''.join(comment)
|
||||
translators_comment_start = None
|
||||
for lineno, line in enumerate(content.splitlines(True)):
|
||||
if line.lstrip().startswith(TRANSLATOR_COMMENT_MARK):
|
||||
translators_comment_start = lineno
|
||||
for lineno, line in enumerate(content.splitlines(True)):
|
||||
if translators_comment_start is not None and lineno >= translators_comment_start:
|
||||
out.write(u' # %s' % line)
|
||||
else:
|
||||
out.write(u' #\n')
|
||||
incomment = False
|
||||
comment = []
|
||||
else:
|
||||
|
|
|
@ -49,7 +49,19 @@ class BasicExtractorTests(ExtractorTests):
|
|||
self.assertTrue('This comment should not be extracted' not in po_contents)
|
||||
# Comments in templates
|
||||
self.assertTrue('#. Translators: Django template comment for translators' in po_contents)
|
||||
self.assertTrue('#. Translators: Django comment block for translators' in po_contents)
|
||||
self.assertTrue("#. Translators: Django comment block for translators\n#. string's meaning unveiled" in po_contents)
|
||||
|
||||
self.assertTrue('#. Translators: One-line translator comment #1' in po_contents)
|
||||
self.assertTrue('#. Translators: Two-line translator comment #1\n#. continued here.' in po_contents)
|
||||
|
||||
self.assertTrue('#. Translators: One-line translator comment #2' in po_contents)
|
||||
self.assertTrue('#. Translators: Two-line translator comment #2\n#. continued here.' in po_contents)
|
||||
|
||||
self.assertTrue('#. Translators: One-line translator comment #3' in po_contents)
|
||||
self.assertTrue('#. Translators: Two-line translator comment #3\n#. continued here.' in po_contents)
|
||||
|
||||
self.assertTrue('#. Translators: One-line translator comment #4' in po_contents)
|
||||
self.assertTrue('#. Translators: Two-line translator comment #4\n#. continued here.' in po_contents)
|
||||
|
||||
def test_templatize(self):
|
||||
os.chdir(self.test_dir)
|
||||
|
|
|
@ -1,8 +1,52 @@
|
|||
{% load i18n %}
|
||||
{% comment %}Translators: Django comment block for translators {% endcomment %}
|
||||
{% comment %}Translators: Django comment block for translators
|
||||
string's meaning unveiled
|
||||
{% endcomment %}
|
||||
{% trans "This literal should be included." %}
|
||||
{% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %}
|
||||
|
||||
{# Translators: Django template comment for translators #}
|
||||
<p>{% blocktrans %}I think that 100% is more that 50% of anything.{% endblocktrans %}</p>
|
||||
{% blocktrans with 'txt' as obj %}I think that 100% is more that 50% of {{ obj }}.{% endblocktrans %}
|
||||
|
||||
{% comment %}Some random comment
|
||||
Some random comment
|
||||
Translators: One-line translator comment #1
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #1a" %}
|
||||
|
||||
{% comment %}Some random comment
|
||||
Some random comment
|
||||
Translators: Two-line translator comment #1
|
||||
continued here.
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #1b" %}
|
||||
|
||||
{% comment %}Some random comment
|
||||
Translators: One-line translator comment #2
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #2a" %}
|
||||
|
||||
{% comment %}Some random comment
|
||||
Translators: Two-line translator comment #2
|
||||
continued here.
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #2b" %}
|
||||
|
||||
{% comment %}
|
||||
Translators: One-line translator comment #3
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #3a" %}
|
||||
|
||||
{% comment %}
|
||||
Translators: Two-line translator comment #3
|
||||
continued here.
|
||||
{% endcomment %}
|
||||
{% trans "Translatable literal #3b" %}
|
||||
|
||||
{% comment %} Translators: One-line translator comment #4{% endcomment %}
|
||||
{% trans "Translatable literal #4a" %}
|
||||
|
||||
{% comment %} Translators: Two-line translator comment #4
|
||||
continued here.{% endcomment %}
|
||||
{% trans "Translatable literal #4b" %}
|
||||
|
|
Loading…
Reference in New Issue