X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=po%2Fpostats.py;h=bca7380af9c7ae8f66621df5e3dd40cf9840ea79;hb=c732f7df09618bed5f7d9019385d276ea46b960b;hp=8c5f058642c87acc01096d3129af73a333a3e78a;hpb=8663a371f31dc7bb888071c15a0b2cd4c3669c60;p=lyx.git diff --git a/po/postats.py b/po/postats.py index 8c5f058642..bca7380af9 100755 --- a/po/postats.py +++ b/po/postats.py @@ -37,6 +37,9 @@ ommitted = ('en.po') import os import sys +import codecs +import subprocess +from subprocess import Popen, PIPE # Reset the locale import locale @@ -69,7 +72,7 @@ def read_pofile(pofile): """ Read the header of the pofile and return it as a dictionary""" header = {} read_header = False - for line in open(pofile): + for line in codecs.open(pofile, encoding='utf8'): line = line[:-1] if line[:5] == 'msgid': if read_header: @@ -110,16 +113,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.decode(charset).encode('ascii','xmlcharrefreplace') - except LookupError: - prop["translator"] = translator - - p_in, p_out = os.popen4("msgfmt --statistics -o %s %s" % (gmofile, pofile)) - extract_number(p_out.readline(), - ('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, @@ -141,4 +142,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])))