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