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