Fixed #21209 -- .po file path comments on Windows.

Literals from source files with Django template language syntax don't
have a '.py' suffix anymore.

Also, the '.\' prefix is preserved to respect GNU gettext behavior on
that platform.

Refs #16903.
This commit is contained in:
Ramiro Morales 2013-10-01 20:23:36 -03:00
parent 1d0fc61b1c
commit 4b715fc05a
2 changed files with 27 additions and 5 deletions

View File

@ -135,8 +135,14 @@ class TranslatableFile(object):
command.stdout.write(errors)
if msgs:
if is_templatized:
old = '#: ' + work_file[2:]
new = '#: ' + orig_file[2:]
# Remove '.py' suffix
if os.name =='nt':
# Preserve '.\' prefix on Windows to respect gettext behavior
old = '#: ' + work_file
new = '#: ' + orig_file
else:
old = '#: ' + work_file[2:]
new = '#: ' + orig_file[2:]
msgs = msgs.replace(old, new)
write_pot_file(potfile, msgs)
if is_templatized:

View File

@ -377,23 +377,39 @@ class NoWrapExtractorTests(ExtractorTests):
self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)
class NoLocationExtractorTests(ExtractorTests):
class LocationCommentsTests(ExtractorTests):
def test_no_location_enabled(self):
"""Behavior is correct if --no-location switch is specified. See #16903."""
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
po_contents = force_text(fp.read())
self.assertFalse('#: templates/test.html:55' in po_contents)
needle = os.sep.join(['#: templates', 'test.html:55'])
self.assertFalse(needle in po_contents, '"%s" shouldn\'t be in final .po file.' % needle)
def test_no_location_disabled(self):
"""Behavior is correct if --no-location switch isn't specified."""
os.chdir(self.test_dir)
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
# Standard comment with source file relative path should be present -- #16903
po_contents = force_text(fp.read())
self.assertTrue('#: templates/test.html:55' in po_contents)
if os.name == 'nt':
# #: .\path\to\file.html:123
cwd_prefix = '%s%s' % (os.curdir, os.sep)
else:
# #: path/to/file.html:123
cwd_prefix = ''
needle = os.sep.join(['#: %stemplates' % cwd_prefix, 'test.html:55'])
self.assertTrue(needle in po_contents, '"%s" not found in final .po file.' % needle)
# #21208 -- Leaky paths in comments on Windows e.g. #: path\to\file.html.py:123
bad_suffix = '.py'
bad_string = 'templates%stest.html%s' % (os.sep, bad_suffix) #
self.assertFalse(bad_string in po_contents, '"%s" shouldn\'t be in final .po file.' % bad_string)
class KeepPotFileExtractorTests(ExtractorTests):