diff --git a/generate.py b/generate.py index 611914034..1d7493d85 100644 --- a/generate.py +++ b/generate.py @@ -25,6 +25,7 @@ import contribute from completion import branches_from_devguide, get_completion, TranslatorsData from repositories import Language, get_languages_and_repos +from word_count import get_word_count generation_time = datetime.now(timezone.utc) @@ -107,6 +108,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')), ) Path('index.html').write_text(output) diff --git a/template.html.jinja b/template.html.jinja index 252e07d32..fc37ab1e4 100644 --- a/template.html.jinja +++ b/template.html.jinja @@ -53,6 +53,7 @@ main | meta

* the number in parentheses shows change in the last 30 days, included in the total completion

+

The Python documentation currently has a word count of {{ '{:,}'.format(word_count) }}.

For more information about translations, see the Python Developer’s Guide.

Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).

diff --git a/word_count.py b/word_count.py new file mode 100644 index 000000000..b7c9f1972 --- /dev/null +++ b/word_count.py @@ -0,0 +1,20 @@ +import os +from polib import pofile + + +def _count_words(pot) -> int: + pot = pofile(pot) + word_count = 0 + for entry in pot: + word_count += len(entry.msgid.split()) + return word_count + + +def get_word_count(dir) -> int: + total_word_count = 0 + for root, dirs, files in os.walk(dir): + for file in files: + if file.endswith('.pot'): + pot = os.path.join(root, file) + total_word_count += _count_words(pot) + return total_word_count