diff options
| author | Ramiro Morales <cramm0@gmail.com> | 2011-03-19 12:56:38 +0000 |
|---|---|---|
| committer | Ramiro Morales <cramm0@gmail.com> | 2011-03-19 12:56:38 +0000 |
| commit | 775a6e694fedc6b057dc560da8e4a07dc7e9457c (patch) | |
| tree | 52317f6c598f5952e1fee06fd672468ad2aeb12d /django/utils | |
| parent | 1a6d98dab97df7e4bfc6fd9c82183eb9a1349078 (diff) | |
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
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/translation/trans_real.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py index 675fb3f4ae..b8478354bd 100644 --- a/django/utils/translation/trans_real.py +++ b/django/utils/translation/trans_real.py @@ -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: |
