The `Generated-By` header value needed a missing `\n`.
The frontends now pass the value of `--copyright-holder` to the Catalog, and removed the `copyright_holder` arg for `write_po` left behind on [105].
Tests changed accordingly.
class Message(object):
"""Representation of a single message in a catalog."""
- def __init__(self, id, string='', locations=(), flags=(), comments=()):
+ def __init__(self, id, string='', locations=(), flags=(), auto_comments=(),
+ user_comments=()):
"""Create the message object.
:param id: the message ID, or a ``(singular, plural)`` tuple for
self.flags.add('python-format')
else:
self.flags.discard('python-format')
- self.comments = list(comments)
+ self.auto_comments = list(auto_comments)
+ self.user_comments = list(user_comments)
def __repr__(self):
return '<%s %r>' % (type(self).__name__, self.id)
:type: `bool`
""")
+
DEFAULT_HEADER = u"""\
# Translations template for PROJECT.
# Copyright (C) YEAR COPYRIGHT HOLDER
headers.append(('Content-Type',
'text/plain; charset=%s' % self.charset))
headers.append(('Content-Transfer-Encoding', '8bit'))
- headers.append(('Generated-By', 'Babel %s' % VERSION))
+ headers.append(('Generated-By', 'Babel %s\n' % VERSION))
return headers
mime_headers = property(mime_headers, doc="""\
The MIME headers of the catalog, used for the special ``msgid ""`` entry.
current.id = message.id
current.string = message.string
current.locations.extend(message.locations)
- current.comments.extend(message.comments)
+ current.auto_comments.extend(message.auto_comments)
+ current.user_comments.extend(message.user_comments)
current.flags |= message.flags
message = current
else:
assert isinstance(message.string, (list, tuple))
self._messages[key] = message
- def add(self, id, string=None, locations=(), flags=(), comments=()):
+ def add(self, id, string=None, locations=(), flags=(), auto_comments=(),
+ user_comments=()):
"""Add or update the message with the specified ID.
>>> catalog = Catalog()
:param flags: a set or sequence of flags
:param comments: a list of translator comments
"""
- self[id] = Message(id, string, list(locations), flags, comments)
+ self[id] = Message(id, string, list(locations), flags, auto_comments,
+ user_comments)
def _key_for(self, id):
"""The key for a message is just the singular ID even for pluralizable
catalog = Catalog(project=self.distribution.get_name(),
version=self.distribution.get_version(),
msgid_bugs_address=self.msgid_bugs_address,
+ copyright_holder=self.copyright_holder,
charset=self.charset)
for dirname, (method_map, options_map) in mappings.items():
for filename, lineno, message, comments in extracted:
filepath = os.path.normpath(os.path.join(dirname, filename))
catalog.add(message, None, [(filepath, lineno)],
- comments=comments)
+ auto_comments=comments)
log.info('writing PO template file to %s' % self.output_file)
write_po(outfile, catalog, width=self.width,
no_location=self.no_location,
omit_header=self.omit_header,
sort_output=self.sort_output,
- sort_by_file=self.sort_by_file,
- copyright_holder=self.copyright_holder)
+ sort_by_file=self.sort_by_file)
finally:
outfile.close()
try:
catalog = Catalog(msgid_bugs_address=options.msgid_bugs_address,
+ copyright_holder=options.copyright_holder,
charset=options.charset)
for dirname in args:
>>> for message in catalog:
... if message.id:
... print (message.id, message.string)
- ... print ' ', (message.locations, message.flags, message.comments)
+ ... print ' ', (message.locations, message.flags)
+ ... print ' ', (message.user_comments, message.auto_comments)
('foo %(name)s', '')
- ([('main.py', 1)], set(['fuzzy', 'python-format']), [])
+ ([('main.py', 1)], set(['fuzzy', 'python-format']))
+ ([], [])
(('bar', 'baz'), ('', ''))
- ([('main.py', 3)], set([]), ['A user comment', 'An auto comment'])
+ ([('main.py', 3)], set([]))
+ (['An auto comment'], ['A user comment'])
:param fileobj: the file-like object to read the PO file from
:return: an iterator over ``(message, translation, location)`` tuples
translations = []
locations = []
flags = []
- comments = []
+ user_comments = []
+ auto_comments = []
in_msgid = in_msgstr = False
in_header = True
header_lines = []
string = tuple([t[1] for t in translations])
else:
string = translations[0][1]
- catalog.add(msgid, string, list(locations), set(flags), list(comments))
+ catalog.add(msgid, string, list(locations), set(flags),
+ list(user_comments), list(auto_comments))
del messages[:]; del translations[:]; del locations[:];
- del flags[:]; del comments[:]
+ del flags[:]; del auto_comments[:]; del user_comments[:]
for line in fileobj.readlines():
line = line.strip()
comment = line[2:].strip()
if comment:
# Just check that we're not adding empty comments
- comments.append(comment)
+ auto_comments.append(comment)
elif line[1:].startswith(' '):
# These are called user comments
comment = line[1:].strip()
if comment:
# Just check that we're not adding empty comments
- comments.append(comment)
+ user_comments.append(comment)
else:
in_header = False
if line.startswith('msgid_plural'):
comment_header = u'\n'.join(lines) + u'\n'
_write(comment_header)
- if message.comments:
- for comment in message.comments:
+ if message.user_comments:
+ for comment in message.user_comments:
+ for line in wrap(comment, width, break_long_words=False):
+ _write('# %s\n' % line.strip())
+
+ if message.auto_comments:
+ for comment in message.auto_comments:
for line in wrap(comment, width, break_long_words=False):
_write('#. %s\n' % line.strip())
assert catalog.PYTHON_FORMAT('foo %d bar')
assert catalog.PYTHON_FORMAT('foo %s bar')
assert catalog.PYTHON_FORMAT('foo %r bar')
-
+
def test_translator_comments(self):
- mess = catalog.Message('foo', comments=['Comment About `foo`'])
- self.assertEqual(mess.comments, ['Comment About `foo`'])
+ mess = catalog.Message('foo', user_comments=['Comment About `foo`'])
+ self.assertEqual(mess.user_comments, ['Comment About `foo`'])
mess = catalog.Message('foo',
- comments=['Comment 1 About `foo`',
+ auto_comments=['Comment 1 About `foo`',
'Comment 2 About `foo`'])
- self.assertEqual(mess.comments, ['Comment 1 About `foo`',
+ self.assertEqual(mess.auto_comments, ['Comment 1 About `foo`',
'Comment 2 About `foo`'])
def test_update_message_updates_comments(self):
cat = catalog.Catalog()
cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])
- self.assertEqual(cat[u'foo'].comments, [])
+ self.assertEqual(cat[u'foo'].auto_comments, [])
+ self.assertEqual(cat[u'foo'].user_comments, [])
# Update cat[u'foo'] with a new location and a comment
cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)],
- comments=['Foo Bar comment 1'])
- self.assertEqual(cat[u'foo'].comments, ['Foo Bar comment 1'])
+ user_comments=['Foo Bar comment 1'])
+ self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1'])
# now add yet another location with another comment
cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)],
- comments=['Foo Bar comment 2'])
- self.assertEqual(cat[u'foo'].comments,
- ['Foo Bar comment 1', 'Foo Bar comment 2'])
+ auto_comments=['Foo Bar comment 2'])
+ self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2'])
def suite():
def test_pot_with_translator_comments(self):
catalog = Catalog()
catalog.add(u'foo', locations=[('main.py', 1)],
- comments=['Comment About `foo`'])
+ auto_comments=['Comment About `foo`'])
catalog.add(u'bar', locations=[('utils.py', 3)],
- comments=['Comment About `bar` with',
- 'multiple lines.'])
+ user_comments=['Comment About `bar` with',
+ 'multiple lines.'])
buf = StringIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual('''#. Comment About `foo`
msgid "foo"
msgstr ""
-#. Comment About `bar` with
-#. multiple lines.
+# Comment About `bar` with
+# multiple lines.
#: utils.py:3
msgid "bar"
msgstr ""''', buf.getvalue().strip())