Skip to content

Instantly share code, notes, and snippets.

@dirkjanfaber
Created August 31, 2021 12:20
Show Gist options
  • Save dirkjanfaber/678ce33a670060c047e53eba4e4c7fb0 to your computer and use it in GitHub Desktop.
Save dirkjanfaber/678ce33a670060c047e53eba4e4c7fb0 to your computer and use it in GitHub Desktop.
POEditor add reference to exported .po file
#!/usr/bin/env python3
import argparse
import polib
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--source', nargs=1,
help='source PO file')
parser.add_argument('-r', '--reference', nargs=1,
help='reference PO file')
args = parser.parse_args()
if not (args.source and args.reference):
raise SystemExit("Both reference and source are needed")
po_source = polib.pofile(args.source[0])
po_reference = polib.pofile(args.reference[0])
for entry in po_source:
# Find the translation in the reference file and put this as comment
entry.tcomment = po_reference.find(entry.msgid).msgstr
# Store the source file again
po_source.save(args.source[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment