Skip to content

Commit 492cfbe

Browse files
authored
Create list-translators.py
1 parent 45abdcf commit 492cfbe

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

list-translators.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/python3
2+
# Extract translation credits from the PO files within the directory
3+
4+
from pathlib import Path
5+
6+
# Get all PO files in the current directory and its subdirectories
7+
p = Path(r'.').glob('**/*.po')
8+
pofiles = list(p)
9+
10+
translators_credits_list = []
11+
12+
# Exclude bot account, duplicated entry and hashes for deleted accounts
13+
ignore_entries = [
14+
'i17obot <i17obot@rougeth.com>',
15+
'Willian Lopes',
16+
'01419cbcade949a3bc5433893a160e74',
17+
'2c4b5a73177ea5ea1d3324f10df471a7_b8aeba7 <7df8a60bac356f3b148ac94f3c2796f6_834576>',
18+
'82596da39877db21448335599650eb68_ac09920 <1d2e18e2f37f0ba6c4f06b239e0670bd_848591>',
19+
]
20+
21+
for po in pofiles:
22+
with po.open() as f:
23+
24+
# If true, it means it is between "# Translators:\n" and "#\n",
25+
# and it is a translator credit. Start with False
26+
is_translator_credits = False
27+
28+
# Start looping through the file, line by line, looking for the
29+
# translation credits block, and then quit without going any
30+
# further down.
31+
for line in f:
32+
33+
# if true, translator credits block finished; quit file
34+
if line == '#\n' and is_translator_credits:
35+
break
36+
37+
# if true, we are in the translator credits block; extract info
38+
if is_translator_credits:
39+
# remove leading sharp sign, and trailing comma and year
40+
line = line.strip('# ')
41+
line = line[:-7]
42+
43+
# Skip entries we do not want to add
44+
if line in ignore_entries:
45+
continue
46+
47+
# Add entry to the set
48+
if line not in translators_credits_list:
49+
translators_credits_list.append(line)
50+
51+
# if true, this is the start of the translation credits block;
52+
# flag is_translator_credits and go to the next line
53+
if line == '# Translators:\n':
54+
is_translator_credits = True
55+
continue
56+
57+
# if true, it means the loop went down until it found the first msgid.
58+
# This means there is no translator credits block (i.e. no one started
59+
# translating this file). Therefore we should stop looking at this file.
60+
# Quit this file and go to the next one.
61+
if line == 'msgid "':
62+
break
63+
64+
# Remove parentheses that messes the reorder of the list.
65+
edit_index = translators_credits_list.index('(Douglas da Silva) <dementikovalev@yandex.ru>')
66+
translators_credits_list[edit_index] = 'Douglas da Silva <dementikovalev@yandex.ru>'
67+
68+
# Reordered in a case-insensitive way as some names were set lowercase
69+
translators_credits_list_reordered = sorted(translators_credits_list, key=str.casefold)
70+
71+
# Print the resulting list to the standard output
72+
for t in translators_credits_list_reordered:
73+
print(t)

0 commit comments

Comments
 (0)