2005-08-30 [colin] 1.9.13cvs73
[claws.git] / tools / claws.i18n.status.pl
1 #!/usr/bin/perl -w
2 #
3 # claws.i18n.stats.pl - Generate statistics for Sylpheed Claws 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         'cs.po' => 'Czech',
14         'de.po' => 'German',
15         'el.po' => 'Greek',
16         'en_GB.po' => 'British English',
17         'es.po' => 'Spanish',
18         'fi.po' => 'Finnish',
19         'fr.po' => 'French',
20         'hr.po' => 'Croatian',
21         'hu.po' => 'Hungarian',
22         'it.po' => 'Italian',
23         'ja.po' => 'Japanese',
24         'ko.po' => 'Korean',
25         'nb.po' => 'Norwegian',
26         'nl.po' => 'Dutch',
27         'pl.po' => 'Polish',
28         'pt_BR.po' => 'Brazilian Portuguese',
29         'ru.po' => 'Russian',
30         'sk.po' => 'Slovak',
31         'sr.po' => 'Serbian',
32         'sv.po' => 'Swedish',
33         'zh_CN.po' => 'Simpilified Chinese',
34         'zh_TW.Big5.po' => 'Taiwanese',
35 );
36
37 %lasttranslator = (
38         'bg.po' => 'George Danchev <danchev@spnet.net>',
39         'ca.po' => 'Miquel Oliete <miqueloliete@softhome.net>',
40         'cs.po' => 'Radek Vybíral <Radek.Vybiral@vsb.cz>',
41         'de.po' => 'Thomas Gilgin <thg1@karate-muellheim.de>',
42         'el.po' => 'Michalis Kabrianis <Michalis@bigfoot.com>',
43         'en_GB.po' => 'Paul Mangan <claws@thewildbeast.co.uk>',
44         'es.po' => 'Ricardo Mones Lastra <mones@aic.uniovi.es>',
45         'fi.po' => 'Flammie Pirinen <flammie@iki.fi>',
46         'fr.po' => 'Fabien Vantard <fzzzzz@gmail.com>',
47         'hr.po' => 'Dragan Leskovar <drleskov@inet.hr>',
48         'hu.po' => 'Gál Zoltán <galzoli@hu.inter.net>',
49         'it.po' => 'Andrea Spadaccini <a.spadaccini@catania.linux.it>',
50         'ja.po' => 'Rui Hirokawa <rui_hirokawa@ybb.ne.jp>',
51         'ko.po' => 'ChiDeok, Hwang <hwang@mizi.co.kr>',
52         'nb.po' => 'Geir Helland <pjallabais@users.sourceforge.net>',
53         'nl.po' => 'Wilbert Berendsen <wbsoft@xs4all.nl>',
54         'pl.po' => 'Emilian Nowak <eminowbl@posejdon.wpk.p.lodz.pl>',
55         'pt_BR.po' => 'Frederico Goncalves Guimaraes <fggdebian@yahoo.com.br>',
56         'ru.po' => 'Pavlo Bohmat <bohm@ukr.net>',
57         'sk.po' => 'Andrej Kacian <andrej@kacian.sk>',
58         'sr.po' => 'urke <urke@users.sourceforge.net>',
59         'sv.po' => 'Joakim Andreasson <joakim.andreasson@gmx.net>',
60         'zh_CN.po' => 'Hansom Young <glyoung@users.sourceforge.net>',
61         'zh_TW.Big5.po' => 'Tsu-Fan Cheng <tscheng@ic.sunysb.edu>',
62 );
63
64 %barcolornorm = (
65         default => 'white',
66         partially => 'lightblue',       
67         completed => 'blue',            
68 );
69
70 %barcoloraged = (       
71         default => 'white',
72         partially => 'lightgrey',       # ligth red '#FFA0A0',
73         completed => 'grey',            # darker red '#FF7070',
74 );
75
76 %barcolorcheat = (      # remarks translations with revision dates in the future
77         default => 'white',
78         partially => 'yellow',
79         completed => 'red',
80 );
81
82 $barwidth = 300; # pixels
83 $barheight = 12; # pixels
84
85 $transolddays = 90;     # days to consider a translation is old, so probably unmaintained. 
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) = @_;
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>\n<td>\n";
128         if ($lang eq $averagestr) {
129                 print "<b>$lang</b>";
130         } else {
131                 print "<a href=\"mailto:%22$pname%22%20<$pemail>\">$lang</a>";
132         }
133         print "</td>\n";
134         print "<td>\n<table style='border: solid 1px black; width: $barwidth' border='0' cellspacing='0' cellpadding='0'><tr>\n";
135         $barlen = ($trans / $total) * $barwidth; 
136         print "<td style='width:$barlen", "px; height:$barheight", "px;' bgcolor=\"$$barcolor{completed}\"></td>\n";
137         $barlen2 = ($fuzzy / $total) * $barwidth;
138         print "<td style='width:$barlen2", "px' bgcolor=\"$$barcolor{partially}\"></td>\n";
139         $barlen3 = $barwidth - $barlen2 - $barlen;
140         print "<td style='width:$barlen3", "px' bgcolor=\"$$barcolor{default}\"></td>\n";
141         print "</tr>\n</table>\n</td>\n\n<td style='text-align: right'>", int(($trans / $total) * 10000) / 100,  "%</td>\n";
142         if (($lang eq $langname{'en_GB.po'}) or ($lang eq $averagestr)) { $trans = $total; } # hack for en_GB and average results
143         $transtatus = (($trans / $total) < $transneedthresold)? '<font size="+1" color="red"> * </font>': '';
144         print "<td>$transtatus</td>\n</tr>\n";
145 }
146
147 sub tens {
148         my ($i) = @_;
149         return (($i > 9)? "$i" : "0$i");
150 }
151
152 get_current_date();
153
154 # get project version from changelog (project dependent code :-/ )
155 $_ = `head -1 ../ChangeLog-gtk2.claws`;
156 if (/\S+\s+\S+\s+(\S+)/) { $genversion = $1; } else { $genversion = 'Unknown'; }
157
158 $numlang = keys(%langname);
159
160 # print `cat $pagehead`;
161 #
162 # make it a here-doc
163 #print <<ENDOFHEAD;
164 # removed for being included
165 #ENDOFHEAD
166
167 # start
168 print "<div class=indent>\n<b>Translation Status (on $datetimenow for $genversion)</b>\n<div class=indent>\n<table cellspacing=0 cellpadding=2>\n";
169
170 # table header
171 print "<tr bgcolor=#cccccc>\n<th align=left>Language</th>\n<th>Translated|Fuzzy|Untranslated</th>\n<th>Percent</th>\n<th>\n</th>\n</tr>\n";
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 = 0;
181 foreach $pofile (@sorted_pofiles) {
182         $_ = $pofile;
183         if (/.+\.po$/) {
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);
206         }
207 }
208
209 # average results for the project
210 print "<tr>\n<td colspan=3 height=8></td>\n<tr>";
211 print_lang($averagestr,'',$atran,$afuzz,$auntr,0);
212         
213 # table footer
214 print "</table>\n";
215
216 # end
217 # print "<br>Number of languages supported: $alang <br>";
218 print "<p>\nLanguages marked with <font size=\"+1\" color=\"red\"> *</font> really need your help to be completed.<br>";
219 print "<p>The ones with grey bars are <i>probably unmaintained</i> because translation is more than ", $transolddays / 30, " months old, anyway, trying to contact current translator first is usually a good idea before submitting an updated one.<p><b>NOTE</b>: if you are the translator of one of them and don't want to see your language bar in grey you should manually update the <tt>PO-Revision-Date</tt> field in the .po file header (or, alternatively, use a tool which does it for you).<br>";
220 # print "If you want to help those or contribute any new language please contact <a href=\"mailto:$contactaddress\">us</a>.";
221 print "</div></div>";
222
223 # print `cat $pagetail`;
224 #
225 # make it a here-doc
226 #print <<ENDOFTAIL;
227 # removed for being included
228 #ENDOFTAIL
229
230 # done