Coverage for heritrace/cli.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-18 11:10 +0000

1import os 

2 

3import click 

4from flask import Flask 

5 

6 

7def register_cli_commands(app: Flask): 

8 @app.cli.group() 

9 def translate(): 

10 """Translation and localization commands.""" 

11 pass 

12 

13 @translate.command() 

14 def update(): 

15 """Update all languages.""" 

16 if os.system( 

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

18 ): 

19 raise RuntimeError("extract command failed") 

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

21 raise RuntimeError("update command failed") 

22 os.remove("babel/messages.pot") 

23 

24 @translate.command() 

25 def compile(): 

26 """Compile all languages.""" 

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

28 raise RuntimeError("compile command failed") 

29 

30 @translate.command() 

31 @click.argument("lang") 

32 def init(lang): 

33 """Initialize a new language.""" 

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

35 raise RuntimeError("extract command failed") 

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

37 raise RuntimeError("init command failed") 

38 os.remove("messages.pot")