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