|
6 | 6 |
|
7 | 7 |
|
8 | 8 | parser = argparse.ArgumentParser() |
9 | | -parser.add_argument( |
10 | | - "subject", nargs="?", default=None, help="Subject to check (file or directory)" |
11 | | -) |
| 9 | +parser.add_argument("subject", nargs="?", default=None, help="Subject to check (file or directory)") |
12 | 10 | parser.add_argument("-c", "--completed", action="store_true") |
13 | 11 | parser.add_argument("-t", "--threshold", type=int, default=90) |
14 | 12 | args = parser.parse_args() |
|
28 | 26 |
|
29 | 27 | elif os.path.isfile(args.subject): |
30 | 28 | is_file = True |
31 | | - args.subject = ( |
32 | | - args.subject |
33 | | - if os.path.isabs(args.subject) |
34 | | - else os.path.join(PO_DIR, args.subject) |
35 | | - ) |
| 29 | + args.org_subject = args.subject |
| 30 | + args.subject = args.subject if os.path.isabs(args.subject) else os.path.join(PO_DIR, args.subject) |
36 | 31 |
|
37 | 32 | else: |
38 | 33 | print("Invalid subject, showing all files.") |
39 | 34 |
|
40 | 35 |
|
| 36 | +def po_stats(pofilename): |
| 37 | + po = polib.pofile(pofilename) |
| 38 | + translated = len(po.translated_entries()) |
| 39 | + total = len(po) + translated |
| 40 | + return (po.percent_translated(), translated, total) |
| 41 | + |
| 42 | + |
41 | 43 | def main(): |
42 | 44 | files = [] |
| 45 | + translated = [] |
| 46 | + total = [] |
43 | 47 | if is_file: |
44 | 48 | po = polib.pofile(args.subject) |
45 | | - return [[args.subject.replace(PO_DIR, ""), po.percent_translated()]] |
| 49 | + return os.path.relpath(args.org_subject), po.percent_translated() |
46 | 50 |
|
47 | 51 | for pofilename in glob.glob(f"{PO_DIR}**/*.po"): |
48 | | - po = polib.pofile(pofilename) |
49 | | - files.append((pofilename.replace(PO_DIR, ""), po.percent_translated())) |
| 52 | + stats = po_stats(pofilename) |
| 53 | + translated.append(stats[1]) |
| 54 | + total.append(stats[2]) |
| 55 | + files.append((os.path.relpath(pofilename).replace("\\", "/"), stats[0])) |
50 | 56 | for pofilename in glob.glob(f"{PO_DIR}**/**/*.po"): |
51 | | - po = polib.pofile(pofilename) |
52 | | - files.append((pofilename.replace(PO_DIR, ""), po.percent_translated())) |
53 | | - return files |
| 57 | + stats = po_stats(pofilename) |
| 58 | + translated.append(stats[1]) |
| 59 | + total.append(stats[2]) |
| 60 | + files.append((os.path.relpath(pofilename).replace("\\", "/"), stats[0])) |
| 61 | + return files, round(sum(translated) / sum(total) * 100, 1) |
54 | 62 |
|
55 | 63 |
|
56 | 64 | if __name__ == "__main__": |
57 | | - results = [f"{file[0]}: {file[1]}%" for file in main()] |
58 | | - |
59 | | - for result in results: |
60 | | - if args.completed and int(result.split(" ")[1].replace("%", "")) > min( |
61 | | - args.threshold, 100 |
62 | | - ): |
63 | | - print(result) |
64 | | - elif not args.completed: |
65 | | - print(result) |
| 65 | + files, weighted_progress = main() |
| 66 | + if not args.subject: |
| 67 | + print("No subject provided, showing general progress") |
| 68 | + print(f"{len([file for file in files if file[1] > min(args.threshold, 100)])} / {len(files)} files completed") |
| 69 | + print(f"Weighted progress: {weighted_progress}%\n") |
| 70 | + |
| 71 | + if args.completed: |
| 72 | + print("Completed files:") |
| 73 | + completed_files = [file for file in files if file[1] > min(args.threshold, 100)] |
| 74 | + for file, percentage in completed_files: |
| 75 | + print(f"{file}: {percentage}%") |
| 76 | + elif is_file: |
| 77 | + print(f"{files}: {weighted_progress}%") |
| 78 | + |
| 79 | + else: |
| 80 | + print(f"{len([file for file in files if file[1] > min(args.threshold, 100)])} / {len(files)} files completed") |
| 81 | + print(f"Weighted progress: {weighted_progress}%\n") |
| 82 | + |
| 83 | + if args.completed: |
| 84 | + print("Completed files:") |
| 85 | + completed_files = [file for file in files if file[1] > min(args.threshold, 100)] |
| 86 | + for file, percentage in completed_files: |
| 87 | + print(f"{file}: {percentage}%") |
0 commit comments