-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.py
81 lines (63 loc) · 1.54 KB
/
make.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
Generate translations and compile them!
"""
from pathlib import Path
import click
from babel.messages.frontend import CommandLineInterface as BabelCLI
BASE_DIR = Path(__file__).resolve().parent
TRANSLATION_DIR = BASE_DIR / 'locale'
TRANSLATION_DOMAIN = 'locale'
BABEL_CONFIG_FILE = BASE_DIR / 'babel.cfg'
MESSAGE_POT = TRANSLATION_DIR / 'message.pot'
@click.group()
def main():
pass
def pybabel(*args):
argv = [''] # Add "command name", because, initialy, it's a command line
for v in args:
if not isinstance(v, str):
argv.append(str(v))
else:
argv.append(v)
BabelCLI().run(
argv=argv
)
def babel_extract():
pybabel(
'extract',
'-F',
BABEL_CONFIG_FILE,
'-o',
MESSAGE_POT,
BASE_DIR,
)
@main.command()
@click.option('-l', multiple=True, type=str, help='Creates or updates the message files for the given locale(s) (e.g. '
'pt_BR). Can be used multiple times. ')
def collect(**options):
babel_extract()
args = [
'update',
'-i',
MESSAGE_POT,
'-D',
TRANSLATION_DOMAIN,
'-d',
TRANSLATION_DIR,
]
for lang in options['l']:
args.append('-l')
args.append(lang)
pybabel(*args)
# noinspection PyShadowingBuiltins
@main.command()
def compile():
pybabel(
'compile',
'-D',
TRANSLATION_DOMAIN,
'-d',
TRANSLATION_DIR,
)
if __name__ == '__main__':
main()