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