Skip to content

Commit a0e5d79

Browse files
authored
Calculate total string count (#102)
Presented in main dashboard footer, along with existing total word count.
1 parent 12499aa commit a0e5d79

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

counts.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from pathlib import Path
2+
3+
from polib import pofile
4+
5+
6+
def _count(pot) -> tuple[int, int]:
7+
pot = pofile(pot)
8+
word_count = 0
9+
for entry in pot:
10+
word_count += len(entry.msgid.split())
11+
return len(pot), word_count
12+
13+
14+
def get_counts(dir: Path) -> tuple[int, int]:
15+
total_string_count = 0
16+
total_word_count = 0
17+
for root, dirs, files in dir.walk():
18+
for file in files:
19+
if file.endswith('.pot'):
20+
pot = root.joinpath(file)
21+
strings, words = _count(pot.read_text())
22+
total_string_count += strings
23+
total_word_count += words
24+
return total_string_count, total_word_count
25+
26+
27+
if __name__ == '__main__':
28+
print(
29+
get_counts(Path(__file__).parent.joinpath('clones/cpython/Doc/build/gettext'))
30+
)

generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import build_status
1616
import contribute
1717
from completion import branches_from_devguide, get_completion, TranslatorsData
18+
from counts import get_counts
1819
from repositories import Language, get_languages_and_repos
19-
from word_count import get_word_count
2020

2121
generation_time = datetime.now(timezone.utc)
2222

@@ -99,7 +99,7 @@ class LanguageProjectData:
9999
completion_progress=(completion_progress := list(get_completion_progress())),
100100
generation_time=generation_time,
101101
duration=(datetime.now(timezone.utc) - generation_time).seconds,
102-
word_count=get_word_count(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
102+
counts=get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
103103
)
104104

105105
Path('index.html').write_text(output)

template.html.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ main | <a href="metadata.html" target="_self">meta</a>
5555
<p>* the number in parentheses shows change in the last 30 days, included in the total completion</p>
5656
<p>
5757
Currently being translated into {{ completion_progress|length }} languages.
58-
The documentation has a total word count of {{ '{:,}'.format(word_count) }}.
58+
The documentation has a total string count of {{ '{:,}'.format(counts[0]) }} ({{ '{:,}'.format(counts[1]) }} words).
5959
For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.
6060
</p>
6161
<hr>

word_count.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)