-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtranslations_helper.py
50 lines (35 loc) · 1.21 KB
/
translations_helper.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
# -*- coding: utf-8 -*-
import os
import click
@click.group()
def translate():
"""Translation and localization commands."""
...
@translate.command()
@click.argument("locale")
def init(locale):
"""Initialize a new language."""
if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."):
raise RuntimeError("extract command failed")
if os.system("pybabel init -i messages.pot -d plugin/translations -l " + locale):
raise RuntimeError("init command failed")
os.remove("messages.pot")
click.echo("Done.")
@translate.command()
def update():
"""Update all languages."""
if os.system("pybabel extract -F babel.cfg -k _l -o messages.pot ."):
raise RuntimeError("extract command failed")
if os.system("pybabel update -i messages.pot -d plugin/translations"):
raise RuntimeError("update command failed")
os.remove("messages.pot")
click.echo("Done.")
@translate.command()
def compile():
"""Compile all languages."""
if os.system("pybabel compile -d plugin/translations"):
raise RuntimeError("compile command failed")
click.echo("Done.")
cli = click.CommandCollection(sources=[translate])
if __name__ == "__main__":
cli()