re-adding .pngs as binary
[dia.git] / po-checktrans.py
blobb50d2a5af7933b9a4d869af2c66dfb9a2b1ad939
1 #!/usr/bin/python
3 # This quick hack gives translation statistics (from the core translation
4 # files).
6 # Copyright (C) 2001, Cyrille Chepelov <chepelov@calixo.net>
8 # This quick hack is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This quick hack is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this quick hack; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 import string,os,sys,math
25 collen = 1
27 def NoneStr(n):
28 if n is None: return (" " * maxlanglen)
29 return n
31 def slurp_po(fname):
32 """returns a tuple (language_name,ids,translations) of what has
33 been translated."""
34 base,ext = os.path.splitext(os.path.basename(fname))
35 language_name = base
37 idents = 0
38 translations = 0
40 st = ""
41 id = ""
43 fd = open(fname,"r")
44 while 1:
45 s = fd.readline()
46 if not s: break
48 s = string.strip(string.split(s,'#')[0])
49 if not s: continue # empty line.
51 sl = string.split(s)
52 if sl[0] == "msgid":
53 #print "id",id,"st",st
54 if st:
55 translations = translations + 1
56 id = sl[0]
57 st = ""
58 del sl[0]
59 elif sl[0] == "msgstr":
60 #print "id",id,"st",st
61 if st:
62 idents = idents + 1
63 id = sl[0]
64 st = ""
65 del sl[0]
67 for k in sl:
68 if k != '""':
69 st = st + k
70 #print "translations:",translations,"idents:",idents
71 return (language_name, idents, translations)
73 if len(sys.argv)<3:
74 print "Usage: %s <package.pot> <lang.po> ..." % sys.argv[0]
75 print
76 print " <package.pot>: file name of the identifier reference to check."
77 print " <lang.po>: file name of the translation to check"
78 sys.exit(1)
80 def maxlen(a,b):
81 if len(a) > len(b):
82 return a
83 return b
85 (t,idents,n) = slurp_po(sys.argv[1])
86 del t,n
88 translations = map(slurp_po,sys.argv[2:])
89 trans = map(lambda (l,i,t),ti=idents:
90 "%s:%3d%%(%d/%d)%s"%(l,
91 100*float(t)/idents,
92 t,idents,
93 "*" * (idents != i)),
94 translations)
95 maxlanglen = len(reduce(maxlen,trans,""))
96 trans = map(lambda s,mll=maxlanglen: string.ljust(s,mll),trans)
98 collen = maxlanglen + len(" ")
100 numcols = int(79 / collen)
101 ltnc = (len(trans) / numcols) + (len(trans) % numcols)
103 cols = []
104 while trans:
105 c,trans = trans[:ltnc],trans[ltnc:]
106 cols.append(c)
108 lines = apply(map,tuple([None]+cols))
110 result = string.join(map(lambda l:string.join(map(NoneStr,list(l))," "),
111 lines),
112 "\n")
113 print result