@@ -34,7 +34,7 @@ def get_project_info() -> dict:
34
34
return data ["project" ]
35
35
36
36
37
- def extract_messages ():
37
+ def extract_messages () -> None :
38
38
"""Extract messages from all source files into message catalog template"""
39
39
Path (PROJECT_DIR , LOCALES_DIR ).mkdir (parents = True , exist_ok = True )
40
40
project_data = get_project_info ()
@@ -61,7 +61,7 @@ def extract_messages():
61
61
)
62
62
63
63
64
- def init_locale (locale : str ):
64
+ def init_locale (locale : str ) -> None :
65
65
"""Initialize a new locale based on existing message catalog template"""
66
66
pofile = PROJECT_DIR / LOCALES_DIR / locale / "LC_MESSAGES" / f"{ DOMAIN } .po"
67
67
if pofile .exists ():
@@ -71,23 +71,23 @@ def init_locale(locale: str):
71
71
subprocess .run (cmd , cwd = PROJECT_DIR , check = True )
72
72
73
73
74
- def update_catalogs (locale : str ):
74
+ def update_catalogs (locale : str ) -> None :
75
75
"""Update translations from existing message catalogs"""
76
76
cmd = ["pybabel" , "update" , "-i" , POT_FILE , "-d" , LOCALES_DIR ]
77
- if locale != "" :
77
+ if locale :
78
78
cmd .extend (["-l" , locale ])
79
79
subprocess .run (cmd , cwd = PROJECT_DIR , check = True )
80
80
81
81
82
- def compile_catalogs (locale : str ):
82
+ def compile_catalogs (locale : str ) -> None :
83
83
"""Compile existing message catalogs"""
84
84
cmd = ["pybabel" , "compile" , "-d" , LOCALES_DIR ]
85
- if locale != "" :
85
+ if locale :
86
86
cmd .extend (["-l" , locale ])
87
87
subprocess .run (cmd , cwd = PROJECT_DIR , check = True )
88
88
89
89
90
- def main ():
90
+ def main () -> None :
91
91
parser = argparse .ArgumentParser (description = __doc__ )
92
92
parser .add_argument (
93
93
"command" ,
@@ -97,16 +97,17 @@ def main():
97
97
parser .add_argument (
98
98
"-l" ,
99
99
"--locale" ,
100
+ default = "" ,
100
101
help = "language code (needed for init, optional for update and compile)" ,
101
102
)
102
103
103
104
args = parser .parse_args ()
104
- locale = args .locale if args . locale else ""
105
+ locale = args .locale
105
106
106
107
if args .command == "extract" :
107
108
extract_messages ()
108
109
elif args .command == "init" :
109
- if locale == "" :
110
+ if not locale :
110
111
parser .error ("init requires passing the --locale option" )
111
112
init_locale (locale )
112
113
elif args .command == "update" :
0 commit comments