changeset 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 f12b187a3d5f
children f5f998fb698f
files scripts/install-po.sh scripts/msgfmt.py
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/install-po.sh	Tue Jan 29 21:46:53 2013 +0200
+++ b/scripts/install-po.sh	Wed Jan 30 10:33:21 2013 +0200
@@ -8,12 +8,12 @@
   molang=`echo $pofile | sed -e 's#data/po/\(.*\)\\.po#\\1#'`;
   mofile=`echo $pofile | sed -e 's/\\.po/.mo/'`;
   mkdir -p data/locale/$molang/LC_MESSAGES
-  scripts/msgfmt.py -o data/locale/$molang/LC_MESSAGES/suspended-sentence.mo $pofile
+  scripts/msgfmt.py -s -o data/locale/$molang/LC_MESSAGES/suspended-sentence.mo $pofile
 done
 
 for pofile in pyntnclick/data/po/*.po; do
   molang=`echo $pofile | sed -e 's#pyntnclick/data/po/\(.*\)\\.po#\\1#'`;
   mofile=`echo $pofile | sed -e 's/\\.po/.mo/'`;
   mkdir -p pyntnclick/data/locale/$molang/LC_MESSAGES
-  scripts/msgfmt.py -o pyntnclick/data/locale/$molang/LC_MESSAGES/pyntnclick-tools.mo $pofile
+  scripts/msgfmt.py -s -o pyntnclick/data/locale/$molang/LC_MESSAGES/pyntnclick-tools.mo $pofile
 done
--- a/scripts/msgfmt.py	Tue Jan 29 21:46:53 2013 +0200
+++ b/scripts/msgfmt.py	Wed Jan 30 10:33:21 2013 +0200
@@ -23,6 +23,10 @@
     -V
     --version
         Display version information and exit.
+
+    -s
+    --statistics
+        Display fuzzy and untranslated counts
 """
 
 import os
@@ -36,6 +40,8 @@
 
 MESSAGES = {}
 
+total_fuzzy = 0
+total_untrans = 0
 
 
 def usage(code, msg=''):
@@ -49,8 +55,15 @@
 def add(id, str, fuzzy):
     "Add a non-fuzzy translation to the dictionary."
     global MESSAGES
+    global total_fuzzy
+    global total_untrans
     if not fuzzy and str:
         MESSAGES[id] = str
+    if fuzzy and str:
+        print 'fuzzy', str
+        total_fuzzy += 1
+    elif not str:
+        total_untrans += 1
 
 
 
@@ -197,13 +210,18 @@
 
 def main():
     try:
-        opts, args = getopt.getopt(sys.argv[1:], 'hVo:',
-                                   ['help', 'version', 'output-file='])
+        opts, args = getopt.getopt(sys.argv[1:], 'hVso:',
+                                   ['help', 'version', 'output-file=',
+                                       'statistics'])
     except getopt.error, msg:
         usage(1, msg)
 
     outfile = None
     # parse options
+    stats = False
+    global total_fuzzy
+    global total_untrans
+
     for opt, arg in opts:
         if opt in ('-h', '--help'):
             usage(0)
@@ -212,6 +230,8 @@
             sys.exit(0)
         elif opt in ('-o', '--output-file'):
             outfile = arg
+        elif opt in ('-s', '--statistics'):
+            stats = True
     # do it
     if not args:
         print >> sys.stderr, 'No input file given'
@@ -221,6 +241,10 @@
     for filename in args:
         make(filename, outfile)
 
+    if stats:
+        print '%s: %d fuzzy strings, %d untranslated strings' % (filename,
+                total_fuzzy, total_untrans)
+
 
 if __name__ == '__main__':
     main()