* src/po/check_po: Support for multiple files as command line arguments; untranslated strings dont need mismatch tests

svn: r5162
This commit is contained in:
Martin Hawlisch
2005-09-01 10:48:39 +00:00
parent 603deacb68
commit 5a3fcbd65b
2 changed files with 127 additions and 91 deletions

View File

@@ -1,3 +1,7 @@
2005-09-01 Martin Hawlisch <Martin.Hawlisch@gmx.de>
* src/po/check_po: Support for multiple files as command line
arguments; untranslated strings dont need mismatch tests
2005-08-31 Don Allingham <don@gramps-project.org> 2005-08-31 Don Allingham <don@gramps-project.org>
* src/plugins/RelCalc.py: use PeopleModel instead of ListModel, * src/plugins/RelCalc.py: use PeopleModel instead of ListModel,
check to the person being compared to him/herself check to the person being compared to him/herself

View File

@@ -6,98 +6,130 @@ MSGSTR = 2
import sys import sys
import re import re
f = open(sys.argv[1],"r")
all_total = {}
all_untranslated = {}
all_percent_s = {}
all_named_s = {}
all_bnamed_s = {}
all_coverage = {}
mode = NONE args = sys.argv
while len(args) > 1:
args = args[1:]
string_map = {} f = open(args[0],"r")
current_msgid = ""
current_msgstr = "" mode = NONE
for line in f.readlines(): string_map = {}
data = line.split(None,1) current_msgid = ""
if mode == NONE: current_msgstr = ""
if len(data) > 0 and data[0] == "msgid":
mode = MSGID for line in f.readlines():
data = line.split(None,1)
current_msgid = data[1].split('"')[1] if mode == NONE:
elif mode == MSGID: if len(data) > 0 and data[0] == "msgid":
if data[0][0] == '"': mode = MSGID
current_msgid += line.split('"')[1]
elif data[0] == "msgstr": current_msgid = data[1].split('"')[1]
mode = MSGSTR elif mode == MSGID:
current_msgstr = data[1].split('"')[1] if data[0][0] == '"':
elif mode == MSGSTR: current_msgid += line.split('"')[1]
if line == "" or line[0] == "#": elif data[0] == "msgstr":
mode = NONE mode = MSGSTR
string_map[current_msgid] = current_msgstr current_msgstr = data[1].split('"')[1]
elif len(data) > 0 and data[0][0] == '"': elif mode == MSGSTR:
current_msgstr += line.split('"')[1] if line == "" or line[0] == "#":
mode = NONE
f.close() string_map[current_msgid] = current_msgstr
elif len(data) > 0 and data[0][0] == '"':
named = re.compile('%\((\w+)\)\d*s') current_msgstr += line.split('"')[1]
bnamed = re.compile('%\((\w+)\)\d*[^sd]')
f.close()
total = len(string_map)
untranslated = 0 named = re.compile('%\((\w+)\)\d*s')
percent_s = 0 bnamed = re.compile('%\((\w+)\)\d*[^sd]')
percent_s_list = []
named_s = 0 total = len(string_map)
named_s_list = [] untranslated = 0
bnamed_s = 0 percent_s = 0
bnamed_s_list = [] percent_s_list = []
named_s = 0
named_s_list = []
for i in string_map.keys(): bnamed_s = 0
if string_map[i] == "": bnamed_s_list = []
untranslated += 1
cnt1 = i.count('%s') for i in string_map.keys():
cnt2 = string_map[i].count('%s') if string_map[i] == "":
if cnt1 != cnt2: untranslated += 1
percent_s += 1 continue
percent_s_list.append(i)
cnt1 = i.count('%s')
list1 = named.findall(i) cnt2 = string_map[i].count('%s')
list2 = named.findall(string_map[i]) if cnt1 != cnt2:
if len(list1) != len(list2): percent_s += 1
percent_s += 1 percent_s_list.append(i)
percent_s_list.append(i)
list1 = named.findall(i)
list1.sort() list2 = named.findall(string_map[i])
list2.sort() if len(list1) != len(list2):
if list1 != list2: percent_s += 1
named_s += 1 percent_s_list.append(i)
named_s_list.append(i)
list1.sort()
match = bnamed.match(string_map[i]) list2.sort()
if match: if list1 != list2:
bnamed_s +=1 named_s += 1
bnamed_s_list.append(i) named_s_list.append(i)
coverage = (1.0 - (float(untranslated)/float(total))) * 100 match = bnamed.match(string_map[i])
if match:
print "Total: %d" % total bnamed_s +=1
print "Untranslated: %d" % untranslated bnamed_s_list.append(i)
print "%%s mismatches: %d" % percent_s
print "%%()s mismatches: %d" % named_s coverage = (1.0 - (float(untranslated)/float(total))) * 100
print "%%() missing s/d: %d" % bnamed_s
print "Coverage: %5.2f%%" % coverage print "File: %s" % args[0]
print "Total: %d" % total
if percent_s: all_total[args[0]] = total
print "\n-------- %s mismatches --------------" print "Untranslated: %d" % untranslated
for i in percent_s_list: all_untranslated[args[0]] = untranslated
print "'%s' : '%s'" % (i, string_map[i]) print "%%s mismatches: %d" % percent_s
all_percent_s[args[0]] = percent_s
if named_s: print "%%()s mismatches: %d" % named_s
print "\n-------- %()s mismatches ------------" all_named_s[args[0]] = named_s
for i in named_s_list: print "%%() missing s/d: %d" % bnamed_s
print "'%s' : '%s'" % (i, string_map[i]) all_bnamed_s[args[0]] = bnamed_s
print "Coverage: %5.2f%%" % coverage
if bnamed_s: all_coverage[args[0]] = coverage
print "\n-------- %() missing s or d ---------"
for i in bnamed_s_list: if percent_s:
print "'%s' : '%s'" % (i, string_map[i]) print "\n-------- %s mismatches --------------"
for i in percent_s_list:
print "'%s' : '%s'" % (i, string_map[i])
if named_s:
print "\n-------- %()s mismatches ------------"
for i in named_s_list:
print "'%s' : '%s'" % (i, string_map[i])
if bnamed_s:
print "\n-------- %() missing s or d ---------"
for i in bnamed_s_list:
print "'%s' : '%s'" % (i, string_map[i])
print ""
if len(sys.argv) > 2:
print "\n\nFile \tTotal \tUntranslated. \t%s mismatch \t%()s mismatch \tmissing s/d \tCoverage"
for pofile in sys.argv[1:]:
print "%s \t%5d \t%7d \t%7d \t%7d \t%7d \t%3.2f%%" %\
(pofile,
all_total[pofile],
all_untranslated[pofile],
all_percent_s[pofile],
all_named_s[pofile],
all_bnamed_s[pofile],
all_coverage[pofile])