Edgewall Software
Modify

Ticket #239 (new defect)

Opened 18 months ago

write_po() with width=None breaks header comment

Reported by: benhoyt Owned by: cmlenz
Priority: major Milestone: 1.0
Component: PO and MO Files Version: 0.9.5
Keywords: Cc:

Description

pofile.write_po() with width=None doesn't output a line feed after the header comment. And read_po() strips the last line feed on the header comment -- which is fine, but the two together mean that if you read_po() and then write_po() with width=None it has the effect of commenting out the initial msgid "".

Complete example:

import StringIO
import babel.messages.pofile as pofile
fin = StringIO.StringIO('# header comment\nmsgid ""\nmsgstr ""\n')
catalog = pofile.read_po(fin)
fout = StringIO.StringIO()
pofile.write_po(fout, catalog, width=None)
print fout.getvalue()

This prints out:

# header commentmsgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
...

As you can see, msgid is put on the last header comment line.

To fix, simply replace these two lines in pofile.py:

                comment_header = u'\n'.join(lines) + u'\n'
            _write(comment_header)

with:

                comment_header = u'\n'.join(lines)
            _write(comment_header + u'\n')

Attachments

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from cmlenz. Next status will be 'new'
The owner will be changed from cmlenz to anonymous. Next status will be 'assigned'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.