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