Issue #45 resolved

incorrectly parses MO files with no header

Jakub Wilk
created an issue

The MO file parser assumes that the first entry in the MO file is the header entry. This is true but only if the header entry actually exists. If it doesn't, then polib parses the MO file incorrectly.

As a test case I attached a MO file that contains two translated strings, but no header:

$ msgunfmt no-header.mo
msgid "bar"
msgstr "rab"

msgid "foo"
msgstr "oof"

This is how polib parses the file:

>>> import polib
>>> print(polib.mofile('no-header.mo'))
msgid ""
msgstr "rab: \n"

msgid "foo"
msgstr "oof"

Comments (4)

  1. David Jean Louis repo owner

    I've got a fix, but IMO the correct output should be:

    msgid ""
    msgstr ""
    
    msgid "bar"
    msgstr "rab"
    
    msgid "foo"
    msgstr "oof"
    

    Just to be consistent with the way polib deals with pofiles: if no metadata is defined it create an empty entry at the begin of the file.

    What do you think ?

  2. Log in to comment