French updates
[koha.git] / misc / translator / stats.pl
1 #!/usr/bin/perl
2
3 # Copyright 2003-2004 Nathan Walp <faceprint@faceprint.com>
4 # Adapted for Koha by Ambrose Li <acli@ada.dhs.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 50 Temple Place, Suite 330, Boston, MA 02111-1307  USA
19 #
20
21
22 my $PACKAGE="koha";
23
24
25 use Locale::Language;
26
27 $lang{en_AU} = "English (Australian)";
28 $lang{en_CA} = "English (Canadian)";
29 $lang{en_GB} = "English (British)";
30 $lang{es_AR} = "Spanish (Argentinian)";
31 $lang{fr_FR} = "French"; # FIXME: should be just "fr"
32 $lang{it_IT} = "Italian"; # FIXME: should be just "it"
33 $lang{my_MM} = "Burmese (Myanmar)";
34 $lang{pl_PL} = "Polish"; # FIXME: should be just "pl"
35 $lang{pt_BR} = "Portuguese (Brazilian)";
36 $lang{'sr@Latn'} = "Serbian (Latin)";
37 $lang{zh_CN} = "Chinese (Simplified)";
38 $lang{zh_TW} = "Chinese (Traditional)";
39
40 $ENV{LANG} = $ENV{LC_ALL} = 'C';
41
42 opendir(DIR, ".") || die "can't open directory: $!";
43 @pos = grep { /\.po$/ && -f } readdir(DIR);
44 foreach (@pos) { s/\.po$//; };
45 closedir DIR;
46
47 @pos = sort @pos;
48
49 $now = `date`;
50
51 system("./update.pl --pot > /dev/null");
52
53 print "<html>\n";
54 print "<head><title>$PACKAGE i18n statistics</title></head>\n";
55 print "<body>\n";
56
57 opendir(DIR, ".") || die "can't open directory: $!";
58 @templates = grep { /\.pot$/ && -f } readdir(DIR);
59 foreach (@templates) { s/\.pot$//; };
60 closedir DIR;
61 for my $PACKAGE (sort {
62             my($theme1, $module1) = ($1, $2) if $a =~ /^(.*)_([^_]+)$/;
63             my($theme2, $module2) = ($1, $2) if $b =~ /^(.*)_([^_]+)$/;
64             return $module1 cmp $module2 || $theme1 cmp $theme2
65         } @templates) {
66     my @pos_orig = @pos;
67     my @pos = grep { /^${PACKAGE}_/ } @pos_orig;
68     my($theme, $module) = ($1, $2) if $PACKAGE =~ /^(.*)_([^_]+)$/;
69
70 $_ = `msgfmt --statistics $PACKAGE.pot -o /dev/null 2>&1`;
71
72 die "unable to get total: $!" unless (/(\d+) untranslated messages/);
73
74 $total = $1;
75
76 print "<h1>Module $module, theme $theme</h1>\n";
77 print "<table cellspacing='0' cellpadding='0' border='0' bgcolor='#888888' width='100%'><tr><td><table cellspacing='1' cellpadding='2' border='0' width='100%'>\n";
78
79 print"<tr bgcolor='#e0e0e0'><th>language</th><th style='background: #339933;'>trans</th><th style='background: #339933;'>%</th><th style='background: #333399;'>fuzzy</th><th style='background: #333399;'>%</th><th style='background: #dd3333;'>untrans</th><th style='background: #dd3333;'>%</th><th>&nbsp;</th></tr>\n";
80
81 foreach $index (0 .. $#pos) {
82         $trans = $fuzz = $untrans = 0;
83         $po = $pos[$index];
84         next if $po =~ /_en_EN/; # Koha-specific
85         print STDERR "$po..." if($ARGV[0] eq '-v');
86         system("msgmerge $po.po $PACKAGE.pot -o $po.new 2>/dev/null");
87         $_ = `msgfmt --statistics $po.new -o /dev/null 2>&1`;
88         chomp;
89         if(/(\d+) translated message/) { $trans = $1; }
90         if(/(\d+) fuzzy translation/) { $fuzz = $1; }
91         if(/(\d+) untranslated message/) { $untrans = $1; }
92         $transp = 100 * $trans / $total;
93         $fuzzp = 100 * $fuzz / $total;
94         $untransp = 100 * $untrans / $total;
95         if($index % 2) {
96                 $color = " bgcolor='#e0e0e0'";
97         } else {
98                 $color = " bgcolor='#d0e0ff'";
99         }
100         my $lang = $1 if $po =~ /^${PACKAGE}_(.*)$/; # Koha-specific
101         $name = "";
102         $name = $lang{$lang}; # NOTE
103         $name = code2language($lang) unless $name ne ""; # NOTE
104         $name = "???" unless $name ne "";
105         printf "<tr$color><td>%s(%s.po)</td><td>%d</td><td>%0.2f</td><td>%d</td><td>%0.2f</td><td>%d</td><td>%0.2f</td><td>",
106         $name, $po, $trans, $transp, $fuzz, $fuzzp, $untrans, $untransp;
107         printf "<img src='bar_g.gif' height='15' width='%0.0f' />", $transp*2
108         unless $transp*2 < 0.5;
109         printf "<img src='bar_b.gif' height='15' width='%0.0f' />", $fuzzp*2
110         unless $fuzzp*2 < 0.5;
111         printf "<img src='bar_r.gif' height='15' width='%0.0f' />", $untransp*2
112         unless $untransp*2 < 0.5;
113         print "</tr>\n";
114         unlink("$po.new");
115         print STDERR "done ($untrans untranslated strings).\n" if($ARGV[0] eq '-v');
116 }
117 print "</table></td></tr></table>\n";
118 print "Latest $PACKAGE.pot generated $now: <a href='$PACKAGE.pot'>$PACKAGE.pot</a><br />\n";
119 }
120 print "</body>\n";
121 print "</html>\n";
122