]> git.lyx.org Git - lyx.git/blobdiff - po/postats.py
de.po
[lyx.git] / po / postats.py
index 52690967da5f24758f209f8aa1cdb407ff1955a5..9c85e5cbf2e91828fefb4e3977baf6e874a5bf68 100755 (executable)
@@ -28,9 +28,8 @@ Invocation:
 """
 from __future__ import print_function
 
-# modify this when you change branch
-# Note that an empty lyx_branch variable (ie svn trunk)
-# will "do the right thing".
+# Modify this when you change branch (e.g. stats for stable branch).
+# Note that an empty lyx_branch variable will "do the right thing" for master.
 lyx_branch=""
 # these po-files will be skipped:
 ommitted = ('en.po')
@@ -38,6 +37,7 @@ ommitted = ('en.po')
 import os
 import sys
 import codecs
+import subprocess
 from subprocess import Popen, PIPE
 
 # Reset the locale
@@ -112,17 +112,14 @@ def run_msgfmt(pofile):
     prop["email"] = header['Last-Translator'].split('<')[1][:-1]
     prop["email"] = prop["email"].replace("@", " () ")
     prop["email"] = prop["email"].replace(".", " ! ")
-    translator = header['Last-Translator'].split('<')[0].strip()
-    try:
-        prop["translator"] = translator.encode('ascii','xmlcharrefreplace')
-    except LookupError:
-        prop["translator"] = translator
-
-    P = Popen("msgfmt --statistics -o %s %s" % (gmofile, pofile),
-              shell=True, stdin=PIPE, stdout=PIPE, close_fds=True)
-    extract_number(P.stdout.readline().decode(),
-                   ('translated', 'fuzzy', 'untranslated'),
-                   prop)
+    prop["translator"] = header['Last-Translator'].split('<')[0].strip()
+
+    msg = subprocess.check_output(["msgfmt", "--statistics",
+            "-o", gmofile, # FIXME: do we really want a gmofile as side-effect?
+            pofile], stderr=subprocess.STDOUT)
+    if sys.version_info[0] > 2:
+        msg = msg.decode('utf8')
+    extract_number(msg, ('translated', 'fuzzy', 'untranslated'), prop)
     return """
 array ( 'langcode' => '%(langcode)s', "date" => "%(date)s",
 "msg_tr" => %(translated)d, "msg_fu" => %(fuzzy)d, "msg_nt" => %(untranslated)d,
@@ -144,4 +141,6 @@ $branch_tag = "%s";
 
 // The data itself
 $podata = array (%s
-)?>""" % (sys.argv[1], branch_tag, ",".join([run_msgfmt(po) for po in sys.argv[2:] if po not in ommitted])))
+)?>""" % (sys.argv[1], branch_tag, 
+          ",".join([run_msgfmt(po) for po in sys.argv[2:] 
+                                   if po not in ommitted])))