mirror of
https://github.com/django/django.git
synced 2025-07-19 17:19:12 +00:00
[1.9.x] Fixed #26341 -- Fixed makemessages breaking location comments for HTML files
Thanks Sylvain Garancher for the report and Veranika Sabiashchanskaya for the initial patch. Backport of b16b124996 from master.
This commit is contained in:
parent
cd2ac512e6
commit
4a6bdff430
@ -147,13 +147,18 @@ class BuildFile(object):
|
|||||||
# Remove '.py' suffix
|
# Remove '.py' suffix
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# Preserve '.\' prefix on Windows to respect gettext behavior
|
# Preserve '.\' prefix on Windows to respect gettext behavior
|
||||||
old = '#: ' + self.work_path
|
old_path = self.work_path
|
||||||
new = '#: ' + self.path
|
new_path = self.path
|
||||||
else:
|
else:
|
||||||
old = '#: ' + self.work_path[2:]
|
old_path = self.work_path[2:]
|
||||||
new = '#: ' + self.path[2:]
|
new_path = self.path[2:]
|
||||||
|
|
||||||
return msgs.replace(old, new)
|
return re.sub(
|
||||||
|
r'^(#: .*)(' + re.escape(old_path) + r')',
|
||||||
|
r'\1' + new_path,
|
||||||
|
msgs,
|
||||||
|
flags=re.MULTILINE
|
||||||
|
)
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
"""
|
"""
|
||||||
|
@ -27,3 +27,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Restored conversion of an empty string to null when saving values of
|
* Restored conversion of an empty string to null when saving values of
|
||||||
``GenericIPAddressField`` on SQLite and MySQL (:ticket:`26557`).
|
``GenericIPAddressField`` on SQLite and MySQL (:ticket:`26557`).
|
||||||
|
|
||||||
|
* Fixed a ``makemessages`` regression where temporary ``.py`` extensions were
|
||||||
|
leaked in source file paths (:ticket:`26341`).
|
||||||
|
@ -12,3 +12,6 @@ number = 3
|
|||||||
dummy3 = ungettext("%(number)s Foo", "%(number)s Foos", number) % {'number': number}
|
dummy3 = ungettext("%(number)s Foo", "%(number)s Foos", number) % {'number': number}
|
||||||
|
|
||||||
dummy4 = _('Size')
|
dummy4 = _('Size')
|
||||||
|
|
||||||
|
# This string is intentionally duplicated in test.html
|
||||||
|
dummy5 = _('This literal should be included.')
|
||||||
|
@ -70,6 +70,9 @@ continued here.{% endcomment %}
|
|||||||
{% trans "Translatable literal #7.1g"|add:2 context "context #7.1g" as var %}
|
{% trans "Translatable literal #7.1g"|add:2 context "context #7.1g" as var %}
|
||||||
{% trans "Translatable literal #7.1h" | add:"foo" | add:2 context "context #7.1h" as var %}
|
{% trans "Translatable literal #7.1h" | add:"foo" | add:2 context "context #7.1h" as var %}
|
||||||
|
|
||||||
|
<!-- Source file inside a msgid, should be left as-is. -->
|
||||||
|
{% trans "#: templates/test.html.py" %}
|
||||||
|
|
||||||
{% blocktrans context "Special blocktrans context #1" %}Translatable literal #8a{% endblocktrans %}
|
{% blocktrans context "Special blocktrans context #1" %}Translatable literal #8a{% endblocktrans %}
|
||||||
{% blocktrans count 2 context "Special blocktrans context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktrans %}
|
{% blocktrans count 2 context "Special blocktrans context #2" %}Translatable literal #8b-singular{% plural %}Translatable literal #8b-plural{% endblocktrans %}
|
||||||
{% blocktrans context "Special blocktrans context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktrans %}
|
{% blocktrans context "Special blocktrans context #3" count 2 %}Translatable literal #8c-singular{% plural %}Translatable literal #8c-plural{% endblocktrans %}
|
||||||
|
@ -635,8 +635,19 @@ class LocationCommentsTests(ExtractorTests):
|
|||||||
# #16903 -- Standard comment with source file relative path should be present
|
# #16903 -- Standard comment with source file relative path should be present
|
||||||
self.assertLocationCommentPresent(self.PO_FILE, 'Translatable literal #6b', 'templates', 'test.html')
|
self.assertLocationCommentPresent(self.PO_FILE, 'Translatable literal #6b', 'templates', 'test.html')
|
||||||
|
|
||||||
# #21208 -- Leaky paths in comments on Windows e.g. #: path\to\file.html.py:123
|
def test_location_comments_for_templatized_files(self):
|
||||||
self.assertLocationCommentNotPresent(self.PO_FILE, None, 'templates', 'test.html.py')
|
"""
|
||||||
|
Ensure no leaky paths in comments, e.g. #: path\to\file.html.py:123
|
||||||
|
Refs #21209/#26341.
|
||||||
|
"""
|
||||||
|
os.chdir(self.test_dir)
|
||||||
|
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
|
||||||
|
self.assertTrue(os.path.exists(self.PO_FILE))
|
||||||
|
with open(self.PO_FILE, 'r') as fp:
|
||||||
|
po_contents = force_text(fp.read())
|
||||||
|
self.assertMsgId('#: templates/test.html.py', po_contents)
|
||||||
|
self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py')
|
||||||
|
self.assertLocationCommentPresent(self.PO_FILE, 5, 'templates', 'test.html')
|
||||||
|
|
||||||
|
|
||||||
class KeepPotFileExtractorTests(ExtractorTests):
|
class KeepPotFileExtractorTests(ExtractorTests):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user