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