Skip to content

Commit

Permalink
drop bad machine translations of Serbian
Browse files Browse the repository at this point in the history
I have modified the Weblate settings to use the v3 Google Translate API instead of the older one, which results in placeholders being handled correctly. Dropping the bad translations makes way for correct ones to be automatically generated by Weblate.
  • Loading branch information
Changaco committed Dec 16, 2023
1 parent bf9674f commit ef90825
Show file tree
Hide file tree
Showing 2 changed files with 504 additions and 489 deletions.
23 changes: 23 additions & 0 deletions cli/po-tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import sys

from babel.messages.pofile import read_po, write_po
Expand Down Expand Up @@ -76,6 +77,28 @@
with open(po_path, 'wb') as po:
write_po(po, catalog, width=0)

elif sys.argv[1] == 'drop-translations-matching':
drop_pattern = sys.argv[2]
po_path = sys.argv[3]
print(f'dropping translations matching {drop_pattern!r} 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)
# look for translations that match the pattern, and drop them
drop_re = re.compile(drop_pattern)
for m in catalog:
if isinstance(m.string, tuple):
m.string = tuple(
'' if drop_re.search(s) else s
for s in m.string
)
else:
m.string = '' if drop_re.search(m.string) else m.string
# write back
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]
Expand Down
Loading

0 comments on commit ef90825

Please sign in to comment.