@@ -34,7 +34,7 @@ def get_project_info() -> dict:
3434 return data ["project" ]
3535
3636
37- def extract_messages ():
37+ def extract_messages () -> None :
3838 """Extract messages from all source files into message catalog template"""
3939 Path (PROJECT_DIR , LOCALES_DIR ).mkdir (parents = True , exist_ok = True )
4040 project_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"""
6666 pofile = PROJECT_DIR / LOCALES_DIR / locale / "LC_MESSAGES" / f"{ DOMAIN } .po"
6767 if pofile .exists ():
@@ -71,23 +71,23 @@ def init_locale(locale: str):
7171 subprocess .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"""
7676 cmd = ["pybabel" , "update" , "-i" , POT_FILE , "-d" , LOCALES_DIR ]
77- if locale != "" :
77+ if locale :
7878 cmd .extend (["-l" , locale ])
7979 subprocess .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"""
8484 cmd = ["pybabel" , "compile" , "-d" , LOCALES_DIR ]
85- if locale != "" :
85+ if locale :
8686 cmd .extend (["-l" , locale ])
8787 subprocess .run (cmd , cwd = PROJECT_DIR , check = True )
8888
8989
90- def main ():
90+ def main () -> None :
9191 parser = argparse .ArgumentParser (description = __doc__ )
9292 parser .add_argument (
9393 "command" ,
@@ -97,16 +97,17 @@ def main():
9797 parser .add_argument (
9898 "-l" ,
9999 "--locale" ,
100+ default = "" ,
100101 help = "language code (needed for init, optional for update and compile)" ,
101102 )
102103
103104 args = parser .parse_args ()
104- locale = args .locale if args . locale else ""
105+ locale = args .locale
105106
106107 if args .command == "extract" :
107108 extract_messages ()
108109 elif args .command == "init" :
109- if locale == "" :
110+ if not locale :
110111 parser .error ("init requires passing the --locale option" )
111112 init_locale (locale )
112113 elif args .command == "update" :
0 commit comments