3 # This quick hack gives translation statistics (from the core translation
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
28 if n
is None: return (" " * maxlanglen
)
32 """returns a tuple (language_name,ids,translations) of what has
34 base
,ext
= os
.path
.splitext(os
.path
.basename(fname
))
48 s
= string
.strip(string
.split(s
,'#')[0])
49 if not s
: continue # empty line.
53 #print "id",id,"st",st
55 translations
= translations
+ 1
59 elif sl
[0] == "msgstr":
60 #print "id",id,"st",st
70 #print "translations:",translations,"idents:",idents
71 return (language_name
, idents
, translations
)
74 print "Usage: %s <package.pot> <lang.po> ..." % sys
.argv
[0]
76 print " <package.pot>: file name of the identifier reference to check."
77 print " <lang.po>: file name of the translation to check"
85 (t
,idents
,n
) = slurp_po(sys
.argv
[1])
88 translations
= map(slurp_po
,sys
.argv
[2:])
89 trans
= map(lambda (l
,i
,t
),ti
=idents
:
90 "%s:%3d%%(%d/%d)%s"%(l
,
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
)
105 c
,trans
= trans
[:ltnc
],trans
[ltnc
:]
108 lines
= apply(map,tuple([None]+cols
))
110 result
= string
.join(map(lambda l
:string
.join(map(NoneStr
,list(l
))," "),