2008-11-06 [mones] 3.6.1cvs19
[claws.git] / tools / claws.i18n.status.pl
1 #!/usr/bin/perl -w
2 #
3 # claws.i18n.stats.pl - Generate statistics for Claws Mail po directory.
4
5 # Copyright (C) 2003-2008 by Ricardo Mones <ricardo@mones.org>, 
6 #                            Paul Mangan <paul@claws-mail.org>
7 # This program is released under the GNU General Public License.
8 #
9 # constants -----------------------------------------------------------------
10
11 %langname = (
12         'bg.po' => 'Bulgarian',
13         'ca.po' => 'Catalan',
14         'de.po' => 'German',
15         'en_GB.po' => 'British English',
16         'es.po' => 'Spanish',
17         'fi.po' => 'Finnish',
18         'fr.po' => 'French',
19         'hu.po' => 'Hungarian',
20         'it.po' => 'Italian',
21         'nl.po' => 'Dutch',
22         'pl.po' => 'Polish',
23         'pt_BR.po' => 'Brazilian Portuguese',
24         'ru.po' => 'Russian',
25         'sk.po' => 'Slovak',
26         'sr.po' => 'Serbian',
27         'sv.po' => 'Swedish',
28         'zh_CN.po' => 'Simpilified Chinese',
29 );
30
31 %lasttranslator = (
32         'bg.po' => 'Yasen Pramatarov <yasen@lindeas.com>',
33         'ca.po' => 'Miquel Oliete <ktalanet@yahoo.es>',
34         'de.po' => 'Stephan Sachse <white@dev-zero.com>',
35         'en_GB.po' => 'Paul Mangan <paul@claws-mail.org>',
36         'es.po' => 'Ricardo Mones Lastra <ricardo@mones.org>',
37         'fi.po' => 'Flammie Pirinen <flammie@iki.fi>',
38         'fr.po' => 'Tristan Chabredier <wwp@claws-mail.org>',
39         'hu.po' => 'P&aacute;der Rezs&#337; <rezso@rezso.net>',
40         'it.po' => 'Andrea Spadaccini <a.spadaccini@catania.linux.it>',
41         'nl.po' => 'Marcel Pol <mpol@gmx.net>',
42         'pl.po' => 'Emilian Nowak <emil5@go2.pl>',
43         'pt_BR.po' => 'Frederico Goncalves Guimaraes <fggdebian@yahoo.com.br>',
44         'ru.po' => 'Aleksei Miheev <aleksei@miheev.info>',
45         'sk.po' => 'Andrej Kacian <andrej@kacian.sk>',
46         'sr.po' => 'Aleksandar Urosevic <urke@users.sf.net>',
47         'sv.po' => 'Lars Persson Fink <lars.p.fink@gmail.com>',
48         'zh_CN.po' => 'Ralgh Young <bamanzi@gmail.com>',
49 );
50
51 %barcolornorm = (
52         default => 'white',
53         partially => 'lightblue',       
54         completed => 'blue',            
55 );
56
57 %barcoloraged = (       
58         default => 'white',
59         partially => 'lightgrey',       # ligth red '#FFA0A0',
60         completed => 'grey',            # darker red '#FF7070',
61 );
62
63 %barcolorcheat = (      # remarks translations with revision dates in the future
64         default => 'white',
65         partially => 'yellow',
66         completed => 'red',
67 );
68
69 $barwidth = 500; # pixels
70 $barheight = 12; # pixels
71
72 $transolddays = 90;     # days to consider a translation is old, so probably unmaintained.
73 $transoldmonths = $transolddays / 30;
74 $transneedthresold = 0.75; # percent/100
75
76 $msgfmt = '/usr/bin/msgfmt';
77
78 $averagestr = 'Project average';
79 $contactaddress = 'translations@thewildbeast.co.uk';
80
81 # $pagehead = '../../claws.i18n.head.php';
82 # $pagetail = '../../claws.i18n.tail.php';
83
84 # code begins here ----------------------------------------------------------
85 sub get_current_date {
86         $date = `date --utc`;
87         chop $date;
88         $date =~ /(\S+)(\s+)(\S+)(\s+)(\S+)(\s+)(\S+)(\D+)(\d+)/;
89         $datetimenow   = "$5-$3-$9 at $7"."$8";
90 }
91
92 sub get_trans_age {
93         my ($y, $m, $d) = @_;
94         return ($y * 365) + ($m * 31) + $d;
95 }
96
97 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime(time);
98 $year += 1900;
99 $mon++;
100 $cage = get_trans_age($year,$mon,$mday); # get current "age"
101
102 # drawing a language status row
103 sub print_lang {
104         my ($lang, $person, $trans, $fuzzy, $untrans, $tage, $oddeven) = @_;
105         $total = $trans + $fuzzy + $untrans;
106         if ($tage == 0) { $tage = $cage; } # hack for average translation
107         print STDERR $cage, " ",  $tage, "\n";
108         if (($cage - $tage) < 0) {
109                 $barcolor = \%barcolorcheat;
110         } else {
111                 $barcolor = (($cage - $tage) > $transolddays)? \%barcoloraged : \%barcolornorm ;
112         }
113         $_ = $person;
114         if (/(.+)\s+\<(.+)\>/) { $pname = $1; $pemail = $2; } else { $pname = $pemail = $contactaddress; }
115         print "<tr";
116         if ($oddeven > 0) { print " bgcolor=#EFEFEF"; }
117         print ">\n<td>\n";
118         if ($lang eq $averagestr) {
119                 print "<b>$lang</b>";
120         } else {
121                 print "<a href=\"mailto:%22$pname%22%20<$pemail>\">$lang</a>";
122         }
123         print "</td>\n";
124         print "<td>\n<table style='border: solid 1px black; width: $barwidth' border='0' cellspacing='0' cellpadding='0'><tr>\n";
125         $barlen = ($trans / $total) * $barwidth; 
126         print "<td style='width:$barlen", "px; height:$barheight", "px;' bgcolor=\"$$barcolor{completed}\"></td>\n";
127         $barlen2 = ($fuzzy / $total) * $barwidth;
128         print "<td style='width:$barlen2", "px' bgcolor=\"$$barcolor{partially}\"></td>\n";
129         $barlen3 = $barwidth - $barlen2 - $barlen;
130         print "<td style='width:$barlen3", "px' bgcolor=\"$$barcolor{default}\"></td>\n";
131         print "</tr>\n</table>\n</td>\n\n<td style='text-align: right'>", int(($trans / $total) * 10000) / 100,  "%</td>\n";
132         if (($lang eq $langname{'en_GB.po'}) or ($lang eq $averagestr)) { $trans = $total; } # hack for en_GB and average results
133         $transtatus = (($trans / $total) < $transneedthresold)? '<font size="+1" color="red"> * </font>': '';
134         print "<td>$transtatus</td>\n</tr>\n";
135 }
136
137 sub tens {
138         my ($i) = @_;
139         return (($i > 9)? "$i" : "0$i");
140 }
141
142 get_current_date();
143
144 # get project version from changelog (project dependent code :-/ )
145 $_ = `head -1 ../ChangeLog`;
146 if (/\S+\s+\S+\s+(\S+)/) { $genversion = $1; } else { $genversion = 'Unknown'; }
147
148 $numlang = keys(%langname);
149
150 # print `cat $pagehead`;
151 #
152 # make it a here-doc
153 #print <<ENDOFHEAD;
154 # removed for being included
155 #ENDOFHEAD
156
157 # start
158 print qq ~<div class=indent>
159           <b>Translation Status (on $datetimenow for $genversion)</b>
160           <div class=indent>
161                 <table cellspacing=0 cellpadding=2>~;
162
163 # table header
164 print qq ~<tr bgcolor=#cccccc>
165           <th align=left>Language</th>
166           <th>Translated|Fuzzy|Untranslated</th>
167           <th>Percent</th>
168           <th></th>
169           </tr>~;
170
171 # get files
172 opendir(PODIR, ".") || die("Error: can't open current directory\n");
173 push(@pofiles,(readdir(PODIR)));
174 closedir(PODIR);
175
176 @sorted_pofiles = sort(@pofiles);
177 # iterate them
178 $alang = $atran = $afuzz = $auntr = $oddeven = 0;
179 foreach $pofile (@sorted_pofiles) {
180         $_ = $pofile;
181         if (/.+\.po$/ && defined($langname{$pofile}) ) {
182                 print STDERR "Processing $_\n"; # be a little informative
183                 ++$alang;
184                 $transage = $tran = $fuzz = $untr = 0;
185                 $_ = `$msgfmt -c --statistics -o /dev/null $pofile 2>&1`;
186                 if (/([0-9]+)\s+translated/) {
187                         $tran = $1;
188                 }
189                 if (/([0-9]+)\s+fuzzy/) {
190                         $fuzz = $1;
191                 }
192                 if (/([0-9]+)\s+untranslated/) {
193                         $untr = $1;
194                 }
195                 # print STDERR "Translated [$tran] Fuzzy [$fuzz] Untranslated [$untr]\n";
196                 $atran += $tran;
197                 $afuzz += $fuzz;
198                 $auntr += $untr;
199                 $_ = `grep 'PO-Revision-Date:' $pofile | cut -f2 -d:`;
200                 if (/\s+(\d+)\-(\d+)\-(\d+)/) { 
201                         $transage = get_trans_age($1,$2,$3); 
202                 }
203                 print_lang($langname{$pofile},$lasttranslator{$pofile},$tran,$fuzz,$untr,$transage, $oddeven);
204                 if ($oddeven == 1) { $oddeven = 0 } else { $oddeven++; } 
205         }
206 }
207
208 # average results for the project
209 print "<tr>\n<td colspan=3 height=8></td>\n<tr>";
210 print_lang($averagestr,'',$atran,$afuzz,$auntr,0,0);
211         
212 # table footer
213 print "</table>\n";
214
215 # end
216 # print "<br>Number of languages supported: $alang <br>";
217 print qq ~<p>
218           Languages marked with <font size="+1" color="red"> *</font>
219           really need your help to be completed.
220           <p>
221           The ones with grey bars are <i>probably unmaintained</i> because
222           translation is more than $transoldmonths months old, anyway, trying
223           to contact current translator first is usually a good idea before
224           submitting an updated one.<p><b>NOTE</b>: if you are the translator
225           of one of them and don't want to see your language bar in grey you
226           should manually update the <tt>PO-Revision-Date</tt> field in the .po
227           file header (or, alternatively, use a tool which does it for you).
228           <br>
229           </div>
230           </div>~;
231
232 # print `cat $pagetail`;
233 #
234 # make it a here-doc
235 #print <<ENDOFTAIL;
236 # removed for being included
237 #ENDOFTAIL
238
239 # done