Skip to content

Commit

Permalink
Merge pull request #121 from samhocevar-forks/fix-invalid-po-generation
Browse files Browse the repository at this point in the history
Ensure empty previous values for msgid and msgstr are properly saved.
  • Loading branch information
izimobil committed Mar 9, 2022
2 parents 6ca2043 + 8671b53 commit a67f372
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion polib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ def __unicode__(self, wrapwidth=78):
prefix = "#| "
for f in fields:
val = getattr(self, f)
if val:
if val is not None:
ret += self._str_field(f, prefix, "", val, wrapwidth)

ret.append(_BaseEntry.__unicode__(self, wrapwidth))
Expand Down
7 changes: 7 additions & 0 deletions tests/test_previous_msgid.po
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ msgstr ""
#| msgid "Partition table entries are not in disk order2\n"
msgid "The new msgid2"
msgstr ""


#| msgctxt "Some other message context"
#| msgid ""
msgctxt "The new msgctxt3"
msgid "The new msgid3"
msgstr ""
17 changes: 17 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,23 @@ def test_previous_msgid_2(self):
expected
)

def test_previous_msgid_3(self):
"""
Test saving empty previous msgid.
"""
po = polib.pofile('tests/test_previous_msgid.po')
fd, tmpfile = tempfile.mkstemp()
os.close(fd)
po.save(tmpfile)
po = polib.pofile(tmpfile)
os.remove(tmpfile)

expected = ""
self.assertEqual(
po[2].previous_msgid,
expected
)

def test_previous_msgctxt_1(self):
"""
Test previous msgctxt multiline.
Expand Down

0 comments on commit a67f372

Please sign in to comment.