-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation.py
78 lines (58 loc) · 1.55 KB
/
translation.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
"""Translation commands."""
import os
import click
# Replace with the name of the app package
PACKAGE = 'app'
@click.group()
def cli():
"""Translation and localization commands."""
pass
@cli.command()
def compile():
"""Compile all languages."""
compile_cmd = (
'pybabel compile '
f'-d {PACKAGE}/translations'
)
if os.system(compile_cmd):
raise RuntimeError('compile command failed')
@cli.command()
@click.argument('lang')
def init(lang):
"""Initialize a new language."""
extract_cmd = (
'pybabel extract '
'-F babel.cfg '
'-k "lazy_gettext _l" '
f'-o {PACKAGE}/translations/messages.pot .'
)
init_cmd = (
'pybabel init '
f'-i {PACKAGE}/translations/messages.pot '
f'-d {PACKAGE}/translations '
f'-l {lang}'
)
if os.system(extract_cmd):
raise RuntimeError('extract command failed')
if os.system(init_cmd):
raise RuntimeError('init command failed')
@cli.command()
def update():
"""Update message catalog."""
extract_cmd = (
'pybabel extract '
'-F babel.cfg '
'-k "lazy_gettext _l" '
f'-o {PACKAGE}/translations/messages.pot .'
)
update_cmd = (
'pybabel update '
f'-i {PACKAGE}/translations/messages.pot '
f'-d {PACKAGE}/translations'
)
if os.system(extract_cmd):
raise RuntimeError('extract command failed')
if os.system(update_cmd):
raise RuntimeError('update command failed')
if __name__ == '__main__':
cli()