1010# ==================================
1111# utility functions
1212
13+
1314def get_lang_dirs (path ):
14- dirs = [relpath (d , path )
15- for d in glob (path + '/[a-z]*' )
16- if os .path .isdir (d ) and not d .endswith ('pot' )]
15+ dirs = [
16+ relpath (d , path )
17+ for d in glob (path + "/[a-z]*" )
18+ if os .path .isdir (d ) and not d .endswith ("pot" )
19+ ]
1720 return (tuple (dirs ),)
1821
1922
2023# ==================================
2124# commands
2225
26+
2327def update (locale_dir , pot_dir , languages , line_width = 76 , ignore_obsolete = False ):
2428 """
2529 Update specified language's po files from pot.
@@ -33,9 +37,9 @@ def update(locale_dir, pot_dir, languages, line_width=76, ignore_obsolete=False)
3337 :rtype: dict
3438 """
3539 status = {
36- ' create' : 0 ,
37- ' update' : 0 ,
38- ' notchanged' : 0 ,
40+ " create" : 0 ,
41+ " update" : 0 ,
42+ " notchanged" : 0 ,
3943 }
4044
4145 for dirpath , dirnames , filenames in os .walk (pot_dir ):
@@ -46,7 +50,7 @@ def update(locale_dir, pot_dir, languages, line_width=76, ignore_obsolete=False)
4650 continue
4751 basename = relpath (base , pot_dir )
4852 for lang in languages :
49- po_dir = os .path .join (locale_dir , lang , ' LC_MESSAGES' )
53+ po_dir = os .path .join (locale_dir , lang , " LC_MESSAGES" )
5054 po_file = os .path .join (po_dir , basename + ".po" )
5155 cat_pot = c .load_po (pot_file )
5256 if os .path .exists (po_file ):
@@ -57,20 +61,31 @@ def update(locale_dir, pot_dir, languages, line_width=76, ignore_obsolete=False)
5761 if msgids != new_msgids :
5862 added = new_msgids - msgids
5963 deleted = msgids - new_msgids
60- status ['update' ] += 1
61- click .echo ('Update: {} +{}, -{}' .format (
62- po_file , len (added ), len (deleted )))
63- c .dump_po (po_file , cat , width = line_width ,
64- ignore_obsolete = ignore_obsolete )
64+ status ["update" ] += 1
65+ click .echo (
66+ "Update: {} +{}, -{}" .format (
67+ po_file , len (added ), len (deleted )
68+ )
69+ )
70+ c .dump_po (
71+ po_file ,
72+ cat ,
73+ width = line_width ,
74+ ignore_obsolete = ignore_obsolete ,
75+ )
6576 else :
66- status [' notchanged' ] += 1
67- click .echo (f' Not Changed: { po_file } ' )
77+ status [" notchanged" ] += 1
78+ click .echo (f" Not Changed: { po_file } " )
6879 else : # new po file
69- status [' create' ] += 1
70- click .echo (f' Create: { po_file } ' )
80+ status [" create" ] += 1
81+ click .echo (f" Create: { po_file } " )
7182 cat_pot .locale = lang
72- c .dump_po (po_file , cat_pot , width = line_width ,
73- ignore_obsolete = ignore_obsolete )
83+ c .dump_po (
84+ po_file ,
85+ cat_pot ,
86+ width = line_width ,
87+ ignore_obsolete = ignore_obsolete ,
88+ )
7489
7590 return status
7691
@@ -87,7 +102,9 @@ def build(locale_dir, output_dir, languages):
87102 for lang in languages :
88103 lang_dir = os .path .join (locale_dir , lang )
89104 for dirpath , dirnames , filenames in os .walk (lang_dir ):
90- dirpath_output = os .path .join (output_dir , os .path .relpath (dirpath , locale_dir ))
105+ dirpath_output = os .path .join (
106+ output_dir , os .path .relpath (dirpath , locale_dir )
107+ )
91108
92109 for filename in filenames :
93110 base , ext = os .path .splitext (filename )
@@ -97,10 +114,11 @@ def build(locale_dir, output_dir, languages):
97114 mo_file = os .path .join (dirpath_output , base + ".mo" )
98115 po_file = os .path .join (dirpath , filename )
99116
100- if (os .path .exists (mo_file ) and
101- os .path .getmtime (mo_file ) > os .path .getmtime (po_file )):
117+ if os .path .exists (mo_file ) and os .path .getmtime (
118+ mo_file
119+ ) > os .path .getmtime (po_file ):
102120 continue
103- click .echo (f' Build: { mo_file } ' )
121+ click .echo (f" Build: { mo_file } " )
104122 cat = c .load_po (po_file )
105123 c .write_mo (mo_file , cat )
106124
@@ -126,17 +144,17 @@ def stat(locale_dir, languages):
126144 continue
127145
128146 cat = c .load_po (po_file )
129- r = result [po_file .replace (' \\ ' , '/' )] = {
130- ' translated' : len (c .translated_entries (cat )),
131- ' fuzzy' : len (c .fuzzy_entries (cat )),
132- ' untranslated' : len (c .untranslated_entries (cat )),
147+ r = result [po_file .replace (" \\ " , "/" )] = {
148+ " translated" : len (c .translated_entries (cat )),
149+ " fuzzy" : len (c .fuzzy_entries (cat )),
150+ " untranslated" : len (c .untranslated_entries (cat )),
133151 }
134152 click .echo (
135- ' {}: {} translated, {} fuzzy, {} untranslated.' .format (
153+ " {}: {} translated, {} fuzzy, {} untranslated." .format (
136154 po_file ,
137- r [' translated' ],
138- r [' fuzzy' ],
139- r [' untranslated' ],
155+ r [" translated" ],
156+ r [" fuzzy" ],
157+ r [" untranslated" ],
140158 )
141159 )
142160
0 commit comments