Coverage for heritrace / cli.py: 100%
26 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-21 12:56 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-21 12:56 +0000
1# SPDX-FileCopyrightText: 2024-2025 Arcangelo Massari <arcangelo.massari@unibo.it>
2#
3# SPDX-License-Identifier: ISC
5import os
7import click
8from flask import Flask
11def register_cli_commands(app: Flask):
12 @app.cli.group()
13 def translate():
14 """Translation and localization commands."""
15 pass
17 @translate.command()
18 def update():
19 """Update all languages."""
20 if os.system(
21 "pybabel extract -F babel/babel.cfg -k lazy_gettext -o babel/messages.pot ."
22 ):
23 raise RuntimeError("extract command failed")
24 if os.system("pybabel update -i babel/messages.pot -d babel/translations"):
25 raise RuntimeError("update command failed")
26 os.remove("babel/messages.pot")
28 @translate.command()
29 def compile():
30 """Compile all languages."""
31 if os.system("pybabel compile -d babel/translations"):
32 raise RuntimeError("compile command failed")
34 @translate.command()
35 @click.argument("lang")
36 def init(lang):
37 """Initialize a new language."""
38 if os.system("pybabel extract -F babel/babel.cfg -k _l -o messages.pot ."):
39 raise RuntimeError("extract command failed")
40 if os.system("pybabel init -i messages.pot -d babel/translations -l " + lang):
41 raise RuntimeError("init command failed")
42 os.remove("messages.pot")