|
| 1 | +#!/bin/python3 |
| 2 | + |
| 3 | +import statistics |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +try: |
| 8 | + import polib |
| 9 | + import requests |
| 10 | +except ImportError: |
| 11 | + print("You need to install polib and requests to be able to run make todo.") |
| 12 | + exit(1) |
| 13 | + |
| 14 | + |
| 15 | +def main(): |
| 16 | + issues = requests.get( |
| 17 | + "https://api.github.com/repos/python/python-docs-fr/issues" |
| 18 | + ).json() |
| 19 | + reservations = { |
| 20 | + issue["title"].split()[-1]: issue["user"]["login"] for issue in issues |
| 21 | + } |
| 22 | + |
| 23 | + po_files = list(Path(".").glob("**/*.po")) |
| 24 | + |
| 25 | + po_files_per_directory = { |
| 26 | + path.parent.name: set(path.parent.glob("*.po")) for path in po_files |
| 27 | + } |
| 28 | + |
| 29 | + for directory, po_files in sorted(po_files_per_directory.items()): |
| 30 | + print("\n\n# " + directory) |
| 31 | + folder_stats = [] |
| 32 | + for po_file in sorted(po_files): |
| 33 | + stats = polib.pofile(po_file) |
| 34 | + po_file_stat = stats.percent_translated() |
| 35 | + if po_file_stat == 100: |
| 36 | + folder_stats.append(po_file_stat) |
| 37 | + continue |
| 38 | + print( |
| 39 | + f"{po_file.name:<30}", |
| 40 | + f"{len(stats.translated_entries()):3d} / {len(stats):3d}", |
| 41 | + f"({po_file_stat:5.1f}% translated)", |
| 42 | + f"{len(stats.fuzzy_entries())} fuzzy" if stats.fuzzy_entries() else "", |
| 43 | + f"Réservé par {reservations[str(po_file)]}" |
| 44 | + if str(po_file) in reservations |
| 45 | + else "", |
| 46 | + ) |
| 47 | + folder_stats.append(po_file_stat) |
| 48 | + # TODO: Have the percentage printed next to the folder name |
| 49 | + print("\n{}% done.".format(round(statistics.mean(folder_stats), 2))) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == '__main__': |
| 53 | + # TODO: Add PR handling |
| 54 | + # TODO: Add total from all folders |
| 55 | + main() |
0 commit comments