Skip to content

Commit

Permalink
add a fuzz subcommand to po-tools.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Feb 8, 2020
1 parent 38d4402 commit 087fdda
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cli/po-tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@
with open(po_path, 'wb') as po:
write_po(po, catalog, width=0)

elif sys.argv[1] == 'fuzz':
po_path = sys.argv[2]
old_msg = sys.argv[3]
new_msg = sys.argv[4]
print('switching a message in PO file', po_path)
# read PO file
lang = po_path.rsplit('/', 1)[-1].split('.', 1)[0]
with open(po_path, 'rb') as po:
catalog = read_po(po, locale=lang)
# replace old msg
m = catalog.get(old_msg)
if m.string:
assert not isinstance(m.id, tuple)
m.id = new_msg
m.flags.add('fuzzy')
# write back
with open(po_path, 'wb') as po:
write_po(po, catalog, width=0)

else:
print("unknown command")
raise SystemExit(1)

0 comments on commit 087fdda

Please sign in to comment.