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