# HG changeset patch # User palgarvio # Date 1181625634 0 # Node ID 96037779b5187f9fe275718153a9b5094c6474a3 # Parent f008662b5d6e184ba1c29643ef9cb2ced6ddc211 Updated `read_po` to add user comments besides just auto comments. diff --git a/babel/messages/pofile.py b/babel/messages/pofile.py --- a/babel/messages/pofile.py +++ b/babel/messages/pofile.py @@ -43,6 +43,8 @@ ... msgid "foo %(name)s" ... msgstr "" ... + ... # A user comment + ... #. An auto comment ... #: main.py:3 ... msgid "bar" ... msgid_plural "baz" @@ -53,11 +55,11 @@ >>> for message in catalog: ... if message.id: ... print (message.id, message.string) - ... print ' ', (message.locations, message.flags) + ... print ' ', (message.locations, message.flags, message.comments) ('foo %(name)s', '') - ([('main.py', 1)], set(['fuzzy', 'python-format'])) + ([('main.py', 1)], set(['fuzzy', 'python-format']), []) (('bar', 'baz'), ('', '')) - ([('main.py', 3)], set([])) + ([('main.py', 3)], set([]), ['A user comment', 'An auto comment']) :param fileobj: the file-like object to read the PO file from :return: an iterator over ``(message, translation, location)`` tuples @@ -100,7 +102,17 @@ for flag in line[2:].lstrip().split(','): flags.append(flag.strip()) elif line[1:].startswith('.'): - comments.append(line[2:].strip) + # These are called auto-comments + comment = line[2:].strip() + if comment: + # Just check that we're not adding empty comments + 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) elif line: if line.startswith('msgid_plural'): in_msgid = True