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