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