Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions counts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path

from polib import pofile


def _count(pot) -> tuple[int, int]:
pot = pofile(pot)
word_count = 0
for entry in pot:
word_count += len(entry.msgid.split())
return len(pot), word_count


def get_counts(dir: Path) -> tuple[int, int]:
total_string_count = 0
total_word_count = 0
for root, dirs, files in dir.walk():
for file in files:
if file.endswith('.pot'):
pot = root.joinpath(file)
strings, words = _count(pot.read_text())
total_string_count += strings
total_word_count += words
return total_string_count, total_word_count


if __name__ == '__main__':
print(
get_counts(Path(__file__).parent.joinpath('clones/cpython/Doc/build/gettext'))
)
4 changes: 2 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import build_status
import contribute
from completion import branches_from_devguide, get_completion, TranslatorsData
from counts import get_counts
from repositories import Language, get_languages_and_repos
from word_count import get_word_count

generation_time = datetime.now(timezone.utc)

Expand Down Expand Up @@ -99,7 +99,7 @@ class LanguageProjectData:
completion_progress=(completion_progress := list(get_completion_progress())),
generation_time=generation_time,
duration=(datetime.now(timezone.utc) - generation_time).seconds,
word_count=get_word_count(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
counts=get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
)

Path('index.html').write_text(output)
Expand Down
2 changes: 1 addition & 1 deletion template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ main | <a href="metadata.html" target="_self">meta</a>
<p>* the number in parentheses shows change in the last 30 days, included in the total completion</p>
<p>
Currently being translated into {{ completion_progress|length }} languages.
The documentation has a total word count of {{ '{:,}'.format(word_count) }}.
The documentation has a total string count of {{ '{:,}'.format(counts[0]) }} ({{ '{:,}'.format(counts[1]) }} words).
For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.
</p>
<hr>
Expand Down
20 changes: 0 additions & 20 deletions word_count.py

This file was deleted.

Loading