forked from internetarchive/openlibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n-messages
executable file
·70 lines (60 loc) · 2.1 KB
/
i18n-messages
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
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Utility script to extract all translatable messages from templates and
macros and write to openlibrary/i18n/messages.pot file.
"""
import _init_path # noqa: F401 Imported for its side effect of setting PYTHONPATH
import sys
from openlibrary import i18n
def help():
print("utility to manage i18n messages")
print()
print("USAGE: %s [extract|compile|update|validate]" % sys.argv[0])
print()
print("Available Commands:")
print(" compile - compile the message files (.po) to .mo")
print(" extract - extract i18n messages from templates and macros")
print(
" update - update the existing translations by adding newly added string to it."
)
print(" status - check completeness and warnings/error summary of translations")
print(" validate - check message file for errors")
print(" help - display this help message")
def main(cmd, args):
if cmd == 'extract':
message_sources = [
'openlibrary/templates/',
'openlibrary/macros/',
# TODO: We should check all python files somehow, but too slow
'openlibrary/plugins/upstream',
]
i18n.extract_messages(message_sources)
elif cmd == 'compile':
i18n.compile_translations(args)
elif cmd == 'update':
i18n.update_translations(args)
elif cmd == 'add':
i18n.generate_po(args)
elif cmd == 'status':
i18n.check_status(args)
elif cmd == 'validate':
results = i18n.validate_translations(args)
num_errors = 0
for error_count in results.values():
num_errors = num_errors + error_count
if num_errors == 0:
print("Validation passed!")
else:
print(f'Validation failed.\n{num_errors} errors found...')
sys.exit(1)
sys.exit(0)
elif cmd == 'help':
help()
else:
print("unknown command: %s" % repr(cmd), file=sys.stderr)
sys.exit(2)
if __name__ == "__main__":
if len(sys.argv) >= 2:
main(sys.argv[1], sys.argv[2:])
else:
help()
sys.exit(1)