]> git.ipfire.org Git - thirdparty/babel.git/commitdiff
Implement translations statistics, closes #18.
authorPedro Algarvio <pedro@algarvio.me>
Wed, 4 Jul 2007 15:24:32 +0000 (15:24 +0000)
committerPedro Algarvio <pedro@algarvio.me>
Wed, 4 Jul 2007 15:24:32 +0000 (15:24 +0000)
babel/messages/frontend.py

index 4cf90c3cf003f6c98eedb85cf60079bf75e37aba..b7e8d3ce26fd72202ecbf8d7b86b259e43deb699 100755 (executable)
@@ -76,8 +76,10 @@ class compile_catalog(Command):
          '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 @@ class compile_catalog(Command):
         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 @@ class compile_catalog(Command):
             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 @@ class CommandLineInterface(object):
         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 @@ class CommandLineInterface(object):
             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