python

Howto copy the msgid to the msgstr in a .po file using polib

Today I got a request to take a .po file, and copy each msgid (the translation string identifier) to the msgstr (the translated text), since the msgids were already english strings. Here's how I did this using polib and Python:

po_in = polib.pofile(input_file)
for entry in po_in:
    entry.msgstr = entry.msgid
po_in.save(output_file)

Very straightforward! Kudos to the people who developed this library.