Mercurial > babel > old > mirror
changeset 209:22232d21dca0
Implement translations statistics, closes #18.
author | palgarvio |
---|---|
date | Wed, 04 Jul 2007 15:24:32 +0000 |
parents | 6cd31048eb5c |
children | b714a9bd4d0d |
files | babel/messages/frontend.py |
diffstat | 1 files changed, 35 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/babel/messages/frontend.py +++ b/babel/messages/frontend.py @@ -76,8 +76,10 @@ 'locale of the catalog to compile'), ('use-fuzzy', 'f', 'also include fuzzy translations'), + ('statistics', None, + 'print statistics about translations') ] - boolean_options = ['use-fuzzy'] + boolean_options = ['use-fuzzy', 'statistics'] def initialize_options(self): self.domain = 'messages' @@ -86,6 +88,7 @@ self.output_file = None self.locale = None self.use_fuzzy = False + self.statistics = False def finalize_options(self): if not self.input_file and not self.directory: @@ -133,6 +136,19 @@ finally: infile.close() + if self.statistics: + print repr(po_file), 'has', + translated = 0 + untranslated = 0 + for message in list(catalog)[1:]: + if message.string: + translated +=1 + else: + untranslated +=1 + stats_str = "%d translated strings and %d untranslated strings" + print stats_str % (translated, untranslated) + continue + if catalog.fuzzy and not self.use_fuzzy: print 'catalog %r is marked as fuzzy, skipping' % (po_file) continue @@ -634,10 +650,13 @@ parser.add_option('--use-fuzzy', '-f', dest='use_fuzzy', action='store_true', help='also include fuzzy translations (default ' - '%default)'), + '%default)') + parser.add_option('--statistics', dest='statistics', + action='store_true', + help='print statistics about translations') parser.set_defaults(domain='messages', use_fuzzy=False, - compile_all=False) + compile_all=False, statistics=False) options, args = parser.parse_args(argv) po_files = [] @@ -682,6 +701,19 @@ finally: infile.close() + if options.statistics: + print repr(po_file), 'has', + translated = 0 + untranslated = 0 + for message in list(catalog)[1:]: + if message.string: + translated +=1 + else: + untranslated +=1 + stats_str = "%d translated strings and %d untranslated strings" + print stats_str % (translated, untranslated) + continue + if catalog.fuzzy and not options.use_fuzzy: print 'catalog %r is marked as fuzzy, skipping' % (po_file) continue