-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
37 lines (31 loc) · 1.15 KB
/
cli.py
File metadata and controls
37 lines (31 loc) · 1.15 KB
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
import os
import click
def register(app):
@app.cli.group()
def translate():
"""Translation and localization commands."""
pass
@translate.command()
@click.argument("lang")
def init(lang):
"""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(
f"pybabel init -i messages.pot -d app/translations -l {lang}"
):
raise RuntimeError("init command failed")
os.remove("messages.pot")
@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 app/translations"):
raise RuntimeError("update command failed")
os.remove("messages.pot")
@translate.command()
def compile():
"""Compile all languages."""
if os.system("pybabel compile -d app/translations"):
raise RuntimeError("compile command failed")