10
10
# ==================================
11
11
# utility functions
12
12
13
+
13
14
def 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
+ ]
17
20
return (tuple (dirs ),)
18
21
19
22
20
23
# ==================================
21
24
# commands
22
25
26
+
23
27
def update (locale_dir , pot_dir , languages , line_width = 76 , ignore_obsolete = False ):
24
28
"""
25
29
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)
33
37
:rtype: dict
34
38
"""
35
39
status = {
36
- ' create' : 0 ,
37
- ' update' : 0 ,
38
- ' notchanged' : 0 ,
40
+ " create" : 0 ,
41
+ " update" : 0 ,
42
+ " notchanged" : 0 ,
39
43
}
40
44
41
45
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)
46
50
continue
47
51
basename = relpath (base , pot_dir )
48
52
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" )
50
54
po_file = os .path .join (po_dir , basename + ".po" )
51
55
cat_pot = c .load_po (pot_file )
52
56
if os .path .exists (po_file ):
@@ -57,20 +61,31 @@ def update(locale_dir, pot_dir, languages, line_width=76, ignore_obsolete=False)
57
61
if msgids != new_msgids :
58
62
added = new_msgids - msgids
59
63
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
+ )
65
76
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 } " )
68
79
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 } " )
71
82
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
+ )
74
89
75
90
return status
76
91
@@ -87,7 +102,9 @@ def build(locale_dir, output_dir, languages):
87
102
for lang in languages :
88
103
lang_dir = os .path .join (locale_dir , lang )
89
104
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
+ )
91
108
92
109
for filename in filenames :
93
110
base , ext = os .path .splitext (filename )
@@ -97,10 +114,11 @@ def build(locale_dir, output_dir, languages):
97
114
mo_file = os .path .join (dirpath_output , base + ".mo" )
98
115
po_file = os .path .join (dirpath , filename )
99
116
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 ):
102
120
continue
103
- click .echo (f' Build: { mo_file } ' )
121
+ click .echo (f" Build: { mo_file } " )
104
122
cat = c .load_po (po_file )
105
123
c .write_mo (mo_file , cat )
106
124
@@ -126,17 +144,17 @@ def stat(locale_dir, languages):
126
144
continue
127
145
128
146
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 )),
133
151
}
134
152
click .echo (
135
- ' {}: {} translated, {} fuzzy, {} untranslated.' .format (
153
+ " {}: {} translated, {} fuzzy, {} untranslated." .format (
136
154
po_file ,
137
- r [' translated' ],
138
- r [' fuzzy' ],
139
- r [' untranslated' ],
155
+ r [" translated" ],
156
+ r [" fuzzy" ],
157
+ r [" untranslated" ],
140
158
)
141
159
)
142
160
0 commit comments