@@ -34,7 +34,7 @@ def get_project_info() -> dict:
3434return data ["project" ]
3535
3636
37- def extract_messages ():
37+ def extract_messages ()-> None :
3838"""Extract messages from all source files into message catalog template"""
3939Path (PROJECT_DIR ,LOCALES_DIR ).mkdir (parents = True ,exist_ok = True )
4040project_data = get_project_info ()
@@ -61,7 +61,7 @@ def extract_messages():
6161 )
6262
6363
64- def init_locale (locale :str ):
64+ def init_locale (locale :str )-> None :
6565"""Initialize a new locale based on existing message catalog template"""
6666pofile = PROJECT_DIR / LOCALES_DIR / locale / "LC_MESSAGES" / f"{ DOMAIN } .po"
6767if pofile .exists ():
@@ -71,23 +71,23 @@ def init_locale(locale: str):
7171subprocess .run (cmd ,cwd = PROJECT_DIR ,check = True )
7272
7373
74- def update_catalogs (locale :str ):
74+ def update_catalogs (locale :str )-> None :
7575"""Update translations from existing message catalogs"""
7676cmd = ["pybabel" ,"update" ,"-i" ,POT_FILE ,"-d" ,LOCALES_DIR ]
77- if locale != "" :
77+ if locale :
7878cmd .extend (["-l" ,locale ])
7979subprocess .run (cmd ,cwd = PROJECT_DIR ,check = True )
8080
8181
82- def compile_catalogs (locale :str ):
82+ def compile_catalogs (locale :str )-> None :
8383"""Compile existing message catalogs"""
8484cmd = ["pybabel" ,"compile" ,"-d" ,LOCALES_DIR ]
85- if locale != "" :
85+ if locale :
8686cmd .extend (["-l" ,locale ])
8787subprocess .run (cmd ,cwd = PROJECT_DIR ,check = True )
8888
8989
90- def main ():
90+ def main ()-> None :
9191parser = argparse .ArgumentParser (description = __doc__ )
9292parser .add_argument (
9393"command" ,
@@ -97,16 +97,17 @@ def main():
9797parser .add_argument (
9898"-l" ,
9999"--locale" ,
100+ default = "" ,
100101help = "language code (needed for init, optional for update and compile)" ,
101102 )
102103
103104args = parser .parse_args ()
104- locale = args .locale if args . locale else ""
105+ locale = args .locale
105106
106107if args .command == "extract" :
107108extract_messages ()
108109elif args .command == "init" :
109- if locale == "" :
110+ if not locale :
110111parser .error ("init requires passing the --locale option" )
111112init_locale (locale )
112113elif args .command == "update" :