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