Commits

Takeshi Komiya  committed ebb4782

Add --statistics option

  • Participants
  • Parent commits 1833699

Comments (0)

Files changed (1)

File sphinx_gettext_helper/command.py

                  help='target language')
     p.add_option('-p', '--potdir',
                  help='pot files directory which is generated by sphinx')
+    p.add_option('-s', '--statistics', action='store_true',
+                 help='show translation statistics')
     p.add_option('-u', '--update', action='store_true',
                  help='update message catalogs')
     options, args = p.parse_args()
         p.print_help()
         sys.exit(0)
 
-    if not options.build and not options.update:
-        msg = "Specify --build or --update option"
+    if not options.build and not options.update and not options.statistics:
+        msg = "Specify --build or --update or --statistics option"
         raise RuntimeError(msg)
 
     if not options.potdir:
             os.system(cmd)
 
 
+def show_statistics(options):
+    for file in os.listdir(options.locale_dir):
+        file = os.path.join(options.locale_dir, file)
+
+        if re.search('\.po$', file):
+            sys.stdout.write("%s: " % os.path.basename(file))
+            sys.stdout.flush()
+            cmd = "msgfmt --statistics %s" % file
+            os.system(cmd)
+
+
 def main():
     try:
         options, args = parse_option()
 
     if options.build:
         do_build(options)
+
+    if options.statistics:
+        show_statistics(options)