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