Skip to content

Commit 3e245a6

Browse files
committed
Track number of translators
1 parent 6e803e5 commit 3e245a6

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

completion.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import git
77
from potodo import potodo
88

9+
import translators
10+
11+
912
@cache
1013
def branches_from_devguide(devguide_dir: Path) -> list[str]:
1114
p = devguide_dir.joinpath('include/release-cycle.json')
@@ -15,7 +18,7 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
1518
]
1619

1720

18-
def get_completion(clones_dir: str, repo: str) -> float:
21+
def get_completion(clones_dir: str, repo: str) -> tuple[float, int]:
1922
clone_path = Path(clones_dir, repo)
2023
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
2124
try:
@@ -31,4 +34,5 @@ def get_completion(clones_dir: str, repo: str) -> float:
3134
completion = potodo.merge_and_scan_path(
3235
clone_path, pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=Path(tmpdir), hide_reserved=False, api_url=''
3336
).completion
34-
return completion
37+
translators_number = translators.get_number_of_translators(clone_path)
38+
return completion, translators_number

generate.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
3333
for language, repo in repositories.get_languages_and_repos(devguide_dir):
3434
if repo:
35-
completion_number = get_completion(clones_dir, repo)
35+
completion_number, translators_number = get_completion(clones_dir, repo)
3636
visitors_number = visitors.get_number_of_visitors(language)
3737
else:
3838
completion_number, visitors_number = 0.0, 0
39-
completion_progress.append((language, repo, completion_number, visitors_number))
39+
completion_progress.append((language, repo, completion_number, translators_number, visitors_number))
4040
print(completion_progress[-1])
4141

4242
template = Template(
@@ -53,11 +53,12 @@
5353
<tr>
5454
<th>language</th>
5555
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies">visitors<a/></th>
56+
<th>translators</th>
5657
<th>completion</th>
5758
</tr>
5859
</thead>
5960
<tbody>
60-
{% for language, repo, completion, visitors in completion_progress | sort(attribute=2) | reverse %}
61+
{% for language, repo, completion, translators, visitors in completion_progress | sort(attribute=2) | reverse %}
6162
<tr>
6263
{% if repo %}
6364
<td data-label="language">
@@ -70,9 +71,11 @@
7071
{{ '{:,}'.format(visitors) }}
7172
</a>
7273
</td>
74+
<td data-label="translators">{{ '{:,}'.format(translators) }}</td>
7375
{% else %}
7476
<td data-label="language">{{ language }}</td>
7577
<td data-label="visitors">0</td>
78+
<td data-label="translators">0</td>
7679
{% endif %}
7780
<td data-label="completion">
7881
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>

translators.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from collections.abc import Generator
2+
from pathlib import Path
3+
4+
from polib import pofile
5+
6+
7+
def get_number_of_translators(path: Path) -> int:
8+
translators = set(_fetch_translators(path))
9+
return len(translators)
10+
11+
12+
def _fetch_translators(path: Path) -> Generator[str, None, None]:
13+
for file in path.rglob('*.po'):
14+
try:
15+
header = pofile(file).header.splitlines()
16+
except IOError:
17+
continue
18+
if 'Translators:' not in header:
19+
continue
20+
for translator_record in header[header.index('Translators:') + 1:]:
21+
translator, _year = translator_record.split(', ')
22+
yield translator

0 commit comments

Comments
 (0)