Mercurial > pyntnclick
comparison scripts/msgfmt.py @ 839:99e1e67f3916 pyntnclick
Add fuzzy/untranslated stats infowhen producing mo files
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Wed, 30 Jan 2013 10:33:21 +0200 |
parents | 087d3ff0aa08 |
children | 72aa6ca3fddc |
comparison
equal
deleted
inserted
replaced
838:f12b187a3d5f | 839:99e1e67f3916 |
---|---|
21 Print this message and exit. | 21 Print this message and exit. |
22 | 22 |
23 -V | 23 -V |
24 --version | 24 --version |
25 Display version information and exit. | 25 Display version information and exit. |
26 | |
27 -s | |
28 --statistics | |
29 Display fuzzy and untranslated counts | |
26 """ | 30 """ |
27 | 31 |
28 import os | 32 import os |
29 import sys | 33 import sys |
30 import ast | 34 import ast |
34 | 38 |
35 __version__ = "1.1" | 39 __version__ = "1.1" |
36 | 40 |
37 MESSAGES = {} | 41 MESSAGES = {} |
38 | 42 |
43 total_fuzzy = 0 | |
44 total_untrans = 0 | |
39 | 45 |
40 | 46 |
41 def usage(code, msg=''): | 47 def usage(code, msg=''): |
42 print >> sys.stderr, __doc__ | 48 print >> sys.stderr, __doc__ |
43 if msg: | 49 if msg: |
47 | 53 |
48 | 54 |
49 def add(id, str, fuzzy): | 55 def add(id, str, fuzzy): |
50 "Add a non-fuzzy translation to the dictionary." | 56 "Add a non-fuzzy translation to the dictionary." |
51 global MESSAGES | 57 global MESSAGES |
58 global total_fuzzy | |
59 global total_untrans | |
52 if not fuzzy and str: | 60 if not fuzzy and str: |
53 MESSAGES[id] = str | 61 MESSAGES[id] = str |
62 if fuzzy and str: | |
63 print 'fuzzy', str | |
64 total_fuzzy += 1 | |
65 elif not str: | |
66 total_untrans += 1 | |
54 | 67 |
55 | 68 |
56 | 69 |
57 def generate(): | 70 def generate(): |
58 "Return the generated output." | 71 "Return the generated output." |
195 | 208 |
196 | 209 |
197 | 210 |
198 def main(): | 211 def main(): |
199 try: | 212 try: |
200 opts, args = getopt.getopt(sys.argv[1:], 'hVo:', | 213 opts, args = getopt.getopt(sys.argv[1:], 'hVso:', |
201 ['help', 'version', 'output-file=']) | 214 ['help', 'version', 'output-file=', |
215 'statistics']) | |
202 except getopt.error, msg: | 216 except getopt.error, msg: |
203 usage(1, msg) | 217 usage(1, msg) |
204 | 218 |
205 outfile = None | 219 outfile = None |
206 # parse options | 220 # parse options |
221 stats = False | |
222 global total_fuzzy | |
223 global total_untrans | |
224 | |
207 for opt, arg in opts: | 225 for opt, arg in opts: |
208 if opt in ('-h', '--help'): | 226 if opt in ('-h', '--help'): |
209 usage(0) | 227 usage(0) |
210 elif opt in ('-V', '--version'): | 228 elif opt in ('-V', '--version'): |
211 print >> sys.stderr, "msgfmt.py", __version__ | 229 print >> sys.stderr, "msgfmt.py", __version__ |
212 sys.exit(0) | 230 sys.exit(0) |
213 elif opt in ('-o', '--output-file'): | 231 elif opt in ('-o', '--output-file'): |
214 outfile = arg | 232 outfile = arg |
233 elif opt in ('-s', '--statistics'): | |
234 stats = True | |
215 # do it | 235 # do it |
216 if not args: | 236 if not args: |
217 print >> sys.stderr, 'No input file given' | 237 print >> sys.stderr, 'No input file given' |
218 print >> sys.stderr, "Try `msgfmt --help' for more information." | 238 print >> sys.stderr, "Try `msgfmt --help' for more information." |
219 return | 239 return |
220 | 240 |
221 for filename in args: | 241 for filename in args: |
222 make(filename, outfile) | 242 make(filename, outfile) |
223 | 243 |
244 if stats: | |
245 print '%s: %d fuzzy strings, %d untranslated strings' % (filename, | |
246 total_fuzzy, total_untrans) | |
247 | |
224 | 248 |
225 if __name__ == '__main__': | 249 if __name__ == '__main__': |
226 main() | 250 main() |