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