Skip to content

Commit 1ed065b

Browse files
committed
Add string count information
String count is a popular metric, used e.g. by Weblate tiers
1 parent 12499aa commit 1ed065b

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
import os
1+
from pathlib import Path
2+
23
from polib import pofile
34

45

5-
def _count_words(pot) -> int:
6+
def _count(pot) -> tuple[int, int]:
67
pot = pofile(pot)
8+
string_count = 0
79
word_count = 0
810
for entry in pot:
11+
string_count += 1
912
word_count += len(entry.msgid.split())
10-
return word_count
13+
return string_count, word_count
1114

1215

13-
def get_word_count(dir) -> int:
16+
def get_counts(dir: Path) -> tuple[int, int]:
17+
total_string_count = 0
1418
total_word_count = 0
15-
for root, dirs, files in os.walk(dir):
19+
for root, dirs, files in dir.walk():
1620
for file in files:
1721
if file.endswith('.pot'):
18-
pot = os.path.join(root, file)
19-
total_word_count += _count_words(pot)
20-
return total_word_count
22+
pot = root.joinpath(root, file)
23+
strings, words = _count(pot)
24+
total_string_count += strings
25+
total_word_count += words
26+
return total_string_count, total_word_count

0 commit comments

Comments
 (0)