# HG changeset patch # User palgarvio # Date 1183562672 0 # Node ID c0b9679daf88d4a048addf42e2dfbb79969c4f02 # Parent 2fe58051569592cdb5391d90c4058d838b6de455 Implement translations statistics, closes #18. diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py --- 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