-
Notifications
You must be signed in to change notification settings - Fork 351
/
languagechecker.py
59 lines (46 loc) · 1.6 KB
/
languagechecker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
Parse gettext pot files and extract path:line and msgid information
compare this with downloaded files from localazy
the output are the elements which are downloaded but not needed anymore.
TODO: better output
'''
import os
from babel.messages.pofile import read_po
def extract_content(file):
content = []
with open(file) as f:
data = read_po(f)
for message in data:
if message.id:
content.append(message)
return content
gettext_dir = "docs/_build/gettext"
gettext_ext = ".pot"
original_content = list()
language_dir = "docs/_locale"
language_ext = ".pot"
language_content = dict()
# get gettext filepath
for (dirpath, dirnames, filenames) in os.walk(gettext_dir):
for file in filenames:
if gettext_ext in file:
original_content.extend(extract_content(f"{dirpath}/{file}"))
# get filepath per language
languages = next(os.walk(language_dir))[1]
for language in languages:
language_content[language] = list()
for (dirpath, dirnames, filenames) in os.walk(f"{language_dir}/{language}"):
for file in filenames:
if language_ext in file:
language_content[language].extend(extract_content(f"{dirpath}/{file}"))
for lang in language_content.keys():
for message in language_content[lang]:
found = False
for ori_message in original_content:
if ori_message.id == message.id:
found = True
if not found:
print()
print(f"{lang}: {message.id}")
for loc in message.locations:
print(f"{loc[0]}:{loc[1]}")