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