Coverage for heritrace / cli.py: 100%

31 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-07-02 10:16 +0000

1# SPDX-FileCopyrightText: 2024-2025 Arcangelo Massari <arcangelo.massari@unibo.it> 

2# 

3# SPDX-License-Identifier: ISC 

4 

5import os 

6from pathlib import Path 

7 

8import click 

9from flask import Flask 

10 

11 

12def register_cli_commands(app: Flask) -> None: 

13 @app.cli.group() 

14 def translate() -> None: 

15 """Translation and localization commands.""" 

16 

17 @translate.command() 

18 def update() -> None: 

19 """Update all languages.""" 

20 if os.system( 

21 "pybabel extract -F babel/babel.cfg -k lazy_gettext -o babel/messages.pot ." 

22 ): 

23 msg = "extract command failed" 

24 raise RuntimeError(msg) 

25 if os.system("pybabel update -i babel/messages.pot -d babel/translations"): 

26 msg = "update command failed" 

27 raise RuntimeError(msg) 

28 Path("babel/messages.pot").unlink() 

29 

30 @translate.command("compile") 

31 def compile_translations() -> None: 

32 """Compile all languages.""" 

33 if os.system("pybabel compile -d babel/translations"): 

34 msg = "compile command failed" 

35 raise RuntimeError(msg) 

36 

37 @translate.command() 

38 @click.argument("lang") 

39 def init(lang: str) -> None: 

40 """Initialize a new language.""" 

41 if os.system("pybabel extract -F babel/babel.cfg -k _l -o messages.pot ."): 

42 msg = "extract command failed" 

43 raise RuntimeError(msg) 

44 if os.system("pybabel init -i messages.pot -d babel/translations -l " + lang): 

45 msg = "init command failed" 

46 raise RuntimeError(msg) 

47 Path("messages.pot").unlink()