Ticket #15632: 15632-5.diff
File 15632-5.diff, 5.1 KB (added by , 14 years ago) |
---|
-
django/utils/translation/trans_real.py
diff -r c157247a9018 django/utils/translation/trans_real.py
a b 435 435 does so by translating the Django translation tags into standard gettext 436 436 function invocations. 437 437 """ 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) 439 440 out = StringIO() 440 441 intrans = False 441 442 inplural = False … … 446 447 for t in Lexer(src, origin).tokenize(): 447 448 if incomment: 448 449 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') 450 460 incomment = False 451 461 comment = [] 452 462 else: -
tests/regressiontests/i18n/commands/extraction.py
diff -r c157247a9018 tests/regressiontests/i18n/commands/extraction.py
a b 49 49 self.assertTrue('This comment should not be extracted' not in po_contents) 50 50 # Comments in templates 51 51 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) 53 65 54 66 def test_templatize(self): 55 67 os.chdir(self.test_dir) -
tests/regressiontests/i18n/commands/templates/test.html
diff -r c157247a9018 tests/regressiontests/i18n/commands/templates/test.html
a b 1 1 {% load i18n %} 2 {% comment %}Translators: Django comment block for translators {% endcomment %} 2 {% comment %}Translators: Django comment block for translators 3 string's meaning unveiled 4 {% endcomment %} 3 5 {% trans "This literal should be included." %} 4 6 {% trans "This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option." %} 5 7 6 8 {# Translators: Django template comment for translators #} 7 9 <p>{% blocktrans %}I think that 100% is more that 50% of anything.{% endblocktrans %}</p> 8 10 {% blocktrans with 'txt' as obj %}I think that 100% is more that 50% of {{ obj }}.{% endblocktrans %} 11 12 {% comment %}Some random comment 13 Some random comment 14 Translators: One-line translator comment #1 15 {% endcomment %} 16 {% trans "Translatable literal #1a" %} 17 18 {% comment %}Some random comment 19 Some random comment 20 Translators: Two-line translator comment #1 21 continued here. 22 {% endcomment %} 23 {% trans "Translatable literal #1b" %} 24 25 {% comment %}Some random comment 26 Translators: One-line translator comment #2 27 {% endcomment %} 28 {% trans "Translatable literal #2a" %} 29 30 {% comment %}Some random comment 31 Translators: Two-line translator comment #2 32 continued 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 %} 42 Translators: Two-line translator comment #3 43 continued 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 51 continued here.{% endcomment %} 52 {% trans "Translatable literal #4b" %}