Skip to content

Commit 3cb3ca3

Browse files
Seluj78JulienPalard
authored andcommitted
Sorted the todo entries (#423)
1 parent bfca5ed commit 3cb3ca3

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.mo
22
.tx/**/*.po
3+
venv/
4+
.idea/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ progress:
5757

5858
.PHONY: todo
5959
todo:
60-
for file in *.po */*.po; do echo $$(msgattrib --untranslated $$file | grep ^msgid | sed 1d | wc -l ) $$file; done | grep -v ^0 | sort -gr
60+
python3 scripts/todo.py
6161

6262

6363
.PHONY: merge

scripts/todo.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)