|
| 1 | +# Validate that all entries in the .pot are in every .po. Only the .pot is updated so we can detect |
| 2 | +# if a translation was added to the source but isn't in a .po. This ensures translators can grab |
| 3 | +# complete files to work on. |
| 4 | + |
| 5 | +import git |
| 6 | +import sys |
| 7 | +import polib |
| 8 | + |
| 9 | +po_filenames = sys.argv[1:] |
| 10 | +repo = git.Repo() |
| 11 | + |
| 12 | +NO_TRANSLATION_WHITELIST = ["ffi_prep_closure_loc"] |
| 13 | + |
| 14 | +bad_commits = {} |
| 15 | +for po_filename in po_filenames: |
| 16 | + print("Checking", po_filename) |
| 17 | + |
| 18 | + commits = repo.iter_commits(paths=po_filename, reverse=True, topo_order=True) |
| 19 | + first_translations = None |
| 20 | + fixed_ids = set() |
| 21 | + for commit in commits: |
| 22 | + try: |
| 23 | + blob = commit.tree / po_filename |
| 24 | + except KeyError: |
| 25 | + continue |
| 26 | + try: |
| 27 | + current_file = polib.pofile(blob.data_stream.read().decode("utf-8")) |
| 28 | + except OSError: |
| 29 | + print("skipping invalid po in", commit) |
| 30 | + continue |
| 31 | + if not first_translations: |
| 32 | + first_translations = current_file |
| 33 | + continue |
| 34 | + print(commit.authored_date, commit) |
| 35 | + first_translations.metadata = current_file.metadata |
| 36 | + for entry in first_translations: |
| 37 | + if entry.msgid == "soft reboot\n": |
| 38 | + continue |
| 39 | + newer_entry = current_file.find(entry.msgid) |
| 40 | + if newer_entry and entry.msgstr != newer_entry.msgstr: |
| 41 | + if newer_entry.msgstr != "" and (newer_entry.msgstr != entry.msgid or entry.msgid in NO_TRANSLATION_WHITELIST): |
| 42 | + entry.merge(newer_entry) |
| 43 | + entry.msgstr = newer_entry.msgstr |
| 44 | + elif entry.msgid not in fixed_ids: |
| 45 | + if commit not in bad_commits: |
| 46 | + bad_commits[commit] = set() |
| 47 | + bad_commits[commit].add(po_filename) |
| 48 | + fixed_ids.add(entry.msgid) |
| 49 | + print(entry.msgid, "\"" + entry.msgstr + "\"", "\"" + newer_entry.msgstr + "\"") |
| 50 | + |
| 51 | + first_translations.save(po_filename) |
| 52 | + |
| 53 | +print() |
| 54 | +for commit in bad_commits: |
| 55 | + files = bad_commits[commit] |
| 56 | + print(commit) |
| 57 | + for file in files: |
| 58 | + print("\t",file) |
0 commit comments