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