/[webwml]/webwml/stattrans.pl
ViewVC logotype

Contents of /webwml/stattrans.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.98 - (hide annotations) (download)
Mon Mar 7 20:02:36 2011 UTC (2 years, 2 months ago) by toddy
Branch: MAIN
Changes since 1.97: +4 -2 lines
File MIME type: text/plain
Correct output directories and give error information
1 joy 1.1 #! /usr/bin/perl
2    
3 joy 1.38 # webwml-stattrans - Debian web site translation statistics
4 joy 1.1 # Copyright (c) 2001 Martin Schulze <joey@debian.org> and others
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 djpig 1.69 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 joy 1.1
20     use POSIX qw(strftime);
21 joy 1.6 use Getopt::Std;
22 barbier 1.24
23     # These modules reside under webwml/Perl
24     use lib ($0 =~ m|(.*)/|, $1 or ".") ."/Perl";
25     use Local::Cvsinfo;
26     use Webwml::Langs;
27     use Webwml::TransCheck;
28     use Webwml::TransIgnore;
29    
30 porridge 1.95 BEGIN {
31     $udd_available = 0;
32     eval {
33     require JSON;
34     require LWP::Simple;
35     LWP::Simple->import;
36     $udd_available = 1;
37     }; if ($@) {
38     warn "One or more modules required for DDE support failed to load: $@\n";
39     }
40     }
41    
42    
43 joy 1.7 $| = 1;
44 joy 1.1
45 toddy 1.98 $opt_h = "/srv/www.debian.org/webwml/devel/website/stats";
46     $opt_w = "/srv/www.debian.org/webwml";
47 djpig 1.57 $opt_p = "*.(wml|src)";
48 joy 1.38 $opt_t = "Debian web site translation statistics";
49 joy 1.6 $opt_v = 0;
50 joy 1.12 $opt_d = "u";
51 joy 1.14 $opt_l = undef;
52 witch 1.72 $opt_b = ""; # Base URL, if not debian.org
53 porridge 1.95 # URL of JSON data or path to plaintext file with lines: "1299999 /doc/index\n"
54     $opt_f = "http://dde.debian.net/dde/q/static/porridge/stats?t=json";
55 porridge 1.94 getopts('h:w:b:p:t:vd:l:f:') || die;
56 barbier 1.24 # Replace filename globbing by Perl regexps
57 djpig 1.54 $opt_p =~ s/\./\\./g;
58 barbier 1.24 $opt_p =~ s/\?/./g;
59     $opt_p =~ s/\*/.*/g;
60     $opt_p =~ s/$/\$/g;
61 joy 1.1 %config = (
62 joy 1.6 'htmldir' => $opt_h,
63     'wmldir' => $opt_w,
64     'wmlpat' => $opt_p,
65     'title' => $opt_t,
66     'verbose' => $opt_v,
67 joy 1.36 'difftype'=> $opt_d,
68 porridge 1.94 'hit_file'=> $opt_f,
69 joy 1.1 );
70    
71 barbier 1.24 my $l = Webwml::Langs->new($opt_w);
72     my %langs = $l->name_iso();
73    
74     my $transignore = Webwml::TransIgnore->new($opt_w);
75    
76     my $cvs = Local::Cvsinfo->new();
77     $cvs->options(
78     recursive => 1,
79     matchfile => [ $config{'wmlpat'} ],
80     skipdir => [ "template" ],
81     );
82     $cvs->readinfo("$config{'wmldir'}/english");
83     foreach (@{$transignore->global()}) {
84     $cvs->removefile("$config{'wmldir'}/english/$_");
85     }
86    
87     my $altcvs = Local::Cvsinfo->new();
88     $altcvs->options(
89     recursive => 1,
90     matchfile => [ $config{'wmlpat'} ],
91     skipdir => [ "template" ],
92     );
93    
94 joy 1.1 $max_versions = 5;
95     $min_versions = 1;
96    
97    
98     $date = strftime "%a %b %e %H:%M:%S %Y %z", localtime;
99    
100 barbier 1.24 my %original;
101 barbier 1.25 my %transversion;
102     my %version;
103 kraai 1.27 my %files;
104 bertol 1.70 my %sizes;
105 joy 1.1
106     # Count wml files in given directory
107     #
108     sub getwmlfiles
109     {
110     my $lang = shift;
111 joy 1.14 my $dir = "$config{'wmldir'}/$lang";
112 joy 1.1 my $cutfrom = length ($config{'wmldir'})+length($lang)+2;
113     my $count = 0;
114 bertol 1.70 my $size = 0;
115 joy 1.1 my $is_english = ($lang eq "english")?1:0;
116 djpig 1.55 my ( $file, $v );
117 barbier 1.24 my @listfiles;
118 joy 1.1
119 joy 1.7 print "$lang " if ($config{verbose});
120 jseidel 1.87 if (! -d "$dir") {
121     print "$0: can't find $dir! Skipping ...\n";
122     return;
123     }
124 barbier 1.24 if ($is_english) {
125     @listfiles = @{$cvs->files()};
126     } else {
127     $altcvs->reset();
128     $altcvs->readinfo($dir);
129     @listfiles = @{$altcvs->files()};
130     }
131     foreach my $f (@listfiles) {
132     $file = substr ($f, $cutfrom);
133     next if $transignore->is_global($file);
134 kraai 1.27 $files{$file} = 1;
135 joy 1.7 $wmlfiles{$lang} .= " " . $file;
136 djpig 1.57 my $transcheck = Webwml::TransCheck->new("$dir/$file");
137 barbier 1.25 if ($transcheck->revision()) {
138     $transversion{"$lang/$file"} = $transcheck->revision();
139     $original{"$lang/$file"} ||= $transcheck->original();
140     }
141 joy 1.1 if ($is_english) {
142 barbier 1.25 $version{"$lang/$file"} = $cvs->revision($f);
143     } else {
144     $version{"$lang/$file"} = $altcvs->revision($f);
145     if (!$transcheck->revision()) {
146 thuriaux 1.65 $transcheckenglish = Webwml::TransCheck->new("english/$file");
147     if (!$transcheckenglish->revision() and (-e "english/$file")) {
148     $transversion{"$lang/$file"} = "1.1";
149     $original{"$lang/$file"} = "english";
150     } else {
151     $original{"english/$file"} = $lang;
152     $transversion{"english/$file"} ||= "1.1";
153     }
154 barbier 1.24 }
155 joy 1.1 }
156 french 1.50 if ($transcheck->maintainer()) {
157     $maintainer{"$lang/$file"} = $transcheck->maintainer();
158     }
159 joy 1.1 $count++;
160 bertol 1.70 $sizes{$file} = (stat "".($original{"english/$file"}||"english")."/".$file)[7];
161     $size += $sizes{$file};
162 joy 1.1 }
163 joy 1.7 $wmlfiles{$lang} .= " ";
164     $wml{$lang} = $count;
165 bertol 1.70 $wml_s{$lang} = $size;
166 barbier 1.25 }
167 joy 1.1
168     sub get_color
169     {
170     my $percent = shift;
171    
172 kraai 1.17 if ($percent < 50) {
173     return sprintf ("#FF%02x00", (255/50) * $percent);
174 joy 1.1 } else {
175 kraai 1.17 return sprintf ("#%02xFF00", (255/50) * (100 - $percent));
176 joy 1.1 }
177     }
178    
179     sub check_translation
180     {
181     my ($translation, $version, $file) = @_;
182 djpig 1.55 my ( @version_numbers, $major_number, $last_number );
183     my ( @translation_numbers, $major_translated_number, $last_translated_number );
184 joy 1.1
185 djpig 1.55 if ( $version && $translation ) {
186 joy 1.1 @version_numbers = split /\./,$version;
187 djpig 1.55 $major_number = $version_numbers[0];
188 joy 1.1 $last_number = pop @version_numbers;
189     die "Invalid CVS revision for $file: $version\n"
190     unless ($major_number =~ /\d+/ && $last_number =~ /\d+/);
191    
192     @translation_numbers = split /\./,$translation;
193 djpig 1.55 $major_translated_number = $translation_numbers[0];
194 joy 1.1 $last_translated_number = pop @translation_numbers;
195     die "Invalid translation revision for $file: $translation\n"
196     unless ($major_translated_number =~ /\d+/ && $last_translated_number =~ /\d+/);
197    
198     # Here we compare the original version with the translated one and print
199     # a note for the user if their first or last numbers are too far apart
200     # From translation-check.wml
201    
202 djpig 1.55 if ( $major_number != $major_translated_number ) {
203 joy 1.1 return "This translation is too out of date";
204 thuriaux 1.65 } elsif ( $last_number - $last_translated_number < 0 ) {
205     return "Wrong translation version";
206 joy 1.1 } elsif ( $last_number - $last_translated_number >= $max_versions ) {
207     return "This translation is too out of date";
208     } elsif ( $last_number - $last_translated_number >= $min_versions ) {
209     return "The original is newer than this translation";
210     }
211 thuriaux 1.65 } elsif ( !$version && $translation) {
212 djpig 1.55 return "The original no longer exists";
213 joy 1.1 }
214     return "";
215     }
216    
217 joy 1.7 print "Collecting data in: " if ($config{'verbose'});
218 joy 1.14 if ($opt_l) {
219 barbier 1.24 getwmlfiles ($opt_l);
220 joy 1.14 getwmlfiles ('english');
221     } else {
222     foreach $lang (keys %langs) {
223 joy 1.7 getwmlfiles ($lang);
224 joy 1.14 }
225 joy 1.1 }
226     print "\n" if ($config{'verbose'});
227    
228 barbier 1.40 my @search_in;
229     if ($opt_l) {
230     @search_in = ( 'english', $opt_l );
231     } else {
232     @search_in = sort keys %langs;
233     }
234    
235 french 1.43 # Compute stats about gettext files
236 joy 1.45 print "Computing statistics in gettext files... " if ($config{'verbose'});
237 djpig 1.55 my ( %po_translated, %po_fuzzy, %po_untranslated, %po_total );
238     my ( %percent_po_t, %percent_po_u, %percent_po_f );
239 barbier 1.40 foreach $lang (@search_in) {
240     next if $lang eq 'english';
241 french 1.43 $po_translated{"total"}{$lang} = $po_fuzzy{"total"}{$lang} = $po_untranslated{"total"}{$lang} = 0;
242 jseidel 1.87 $percent_po_t{'total'}{$lang} = 0;
243     $percent_po_f{'total'}{$lang} = 0;
244     $percent_po_u{'total'}{$lang} = 100;
245     if (! -d "$opt_w/$lang/po") {
246     print "$0: can't find $opt_w/$lang/po! Skipping ...\n";
247     next;
248     }
249 french 1.43 my @status = qx,LC_ALL=C make -C $opt_w/$lang/po stats 2>&1 1>/dev/null,;
250 barbier 1.40 foreach $line (@status) {
251     chomp $line;
252     ($domain = $line) =~ s/\..*//;
253     $po_translated{$domain}{$lang} = ($line =~ /(\d+) translated/ ? $1 : "0");
254     $po_fuzzy{$domain}{$lang} = ($line =~ /(\d+) fuzzy/ ? $1 : "0");
255     $po_untranslated{$domain}{$lang} = ($line =~ /(\d+) untranslated/ ? $1 : "0");
256 french 1.43
257 barbier 1.40 $po_total{$domain} = $po_translated{$domain}{$lang} + $po_fuzzy{$domain}{$lang} + $po_untranslated{$domain}{$lang};
258 toddy 1.74
259 french 1.43 $po_translated{"total"}{$lang} += $po_translated{$domain}{$lang};
260     $po_fuzzy{"total"}{$lang} += $po_fuzzy{$domain}{$lang};
261     $po_untranslated{"total"}{$lang} += $po_untranslated{$domain}{$lang};
262 toddy 1.74
263 barbier 1.42 if ($po_total{$domain} > 0) {
264     $percent_po_t{$domain}{$lang} = int ($po_translated{$domain}{$lang}/$po_total{$domain} * 100 + .5);
265     $percent_po_f{$domain}{$lang} = int ($po_fuzzy{$domain}{$lang}/$po_total{$domain} * 100 + .5);
266     $percent_po_u{$domain}{$lang} = int ($po_untranslated{$domain}{$lang}/$po_total{$domain} * 100 + .5);
267     } else {
268     $percent_po_t{$domain}{$lang} = 0;
269     $percent_po_f{$domain}{$lang} = 0;
270 jseidel 1.87 $percent_po_u{$domain}{$lang} = 0; # or 100 if po/ doesn't exist
271 barbier 1.42 }
272 barbier 1.40 }
273 french 1.43 $po_total{"total"} = $po_translated{"total"}{$lang} + $po_fuzzy{"total"}{$lang} + $po_untranslated{"total"}{$lang};
274 toddy 1.74
275 french 1.43 if ($po_total{'total'} > 0) {
276     $percent_po_t{'total'}{$lang} = int ($po_translated{'total'}{$lang}/$po_total{'total'} * 100 + .5);
277     $percent_po_f{'total'}{$lang} = int ($po_fuzzy{'total'}{$lang}/$po_total{'total'} * 100 + .5);
278     $percent_po_u{'total'}{$lang} = int ($po_untranslated{'total'}{$lang}/$po_total{'total'} * 100 + .5);
279     }
280 barbier 1.40 }
281 french 1.43 print "done.\n" if ($config{'verbose'});
282 barbier 1.40
283 joy 1.1 # =============== Create HTML files ===============
284 joy 1.14 mkdir ($config{'htmldir'}, 02775) if (! -d $config{'htmldir'});
285 joy 1.1
286 porridge 1.94 # Read website hit statistics, if available
287     my %hits;
288 porridge 1.95 my $file_sorter = sub($$) { $_[0] cmp $_[1] };
289     if ($config{'hit_file'} and $config{'hit_file'} =~ m{^(f|ht)tps?://} and ! $udd_available) {
290     warn "Disabling fetching of hit data.\n";
291     $config{'hit_file'} = undef;
292     }
293 porridge 1.94 if ($config{'hit_file'}) {
294 porridge 1.95 if ($config{'hit_file'} =~ m{^(f|ht)tps?://}) {
295     printf("Retrieving hit data from [%s].\n", $config{'hit_file'}) if ($config{'verbose'});
296     my $json = LWP::Simple::get($config{'hit_file'});
297     if ($json) {
298     my $perl = JSON::from_json($json, {utf8 => 1});
299     foreach my $e (@{$perl->{'r'}}) {
300     my ($count, $url) = @$e;
301     last if $count < 3; # URLS with 2 or 1 hits are most likely mistakes; let's not waste RAM on them
302     $hits{substr($url, 1)} = $count;
303     }
304     } else {
305     warn "Retrieving hit data failed.\n";
306     }
307     } else {
308     open(HITS, $config{'hit_file'}) or die sprintf("Opening hit file [%s] failed: $!", $config{'hit_file'});
309     printf "Reading hit file [%s]\n", $config{'hit_file'} if ($config{'verbose'});
310     foreach my $hit_line (<HITS>) {
311     chomp $hit_line;
312     $hit_line =~ /^\s*(\d+)\s+(.*)/ or warn sprintf("unrecognized hit file [%s] line [%s]", $config{'hit_file'}, $hit_line);
313     my ($count, $url) = ($1, $2);
314     last if $count < 3; # URLS with 2 or 1 hits are most likely mistakes; let's not waste RAM on them
315     $hits{substr($url, 1)} = $count;
316     }
317     close(HITS) or die sprintf("Closing hit file [%s] failed: $!", $config{'hit_file'});
318     }
319     if (%hits) {
320     $file_sorter = sub($$) {
321     my ($a, $b) = @_;
322     $a =~ s/\.wml$//o;
323     $b =~ s/\.wml$//o;
324     $hits{$b} <=> $hits{$a}
325     };
326     } else {
327     print "Tables will be sorted alphabetically.\n" if ($config{'verbose'});
328     }
329 porridge 1.94 } else {
330     print "No hit file specified. Tables will be sorted alphabetically.\n" if ($config{'verbose'});
331     }
332    
333     my @filenames = sort $file_sorter keys %files;
334 kraai 1.27 my $nfiles = scalar @filenames;
335 bertol 1.70 $nsize += $sizes{$_} foreach (@filenames);
336 joy 1.1
337 joy 1.85 my $firstdifftype;
338     my $seconddifftype;
339     if ($config{'difftype'} eq 'u') {
340     $firstdifftype = 'u';
341     $seconddifftype = 'h';
342     } else {
343     $firstdifftype = 'h';
344     $seconddifftype = 'u';
345     }
346    
347 joy 1.7 print "Creating files: " if ($config{'verbose'});
348 joy 1.14 foreach $lang (@search_in) {
349 barbier 1.59 my @processed_langs = ($langs{$lang});
350     @processed_langs = ("zh-cn", "zh-tw") if $langs{$lang} eq "zh";
351     foreach $l (@processed_langs) {
352 toddy 1.97 print "$l.wml " if ($config{'verbose'});
353 joy 1.8
354 spaillard 1.89 $charset{$lang};
355     open (wmlrc,"$opt_w/$lang/.wmlrc") ;
356     while (<wmlrc>) {
357     if ( /^-D CHARSET=(.*)$/ ) {
358     $charset{$lang} = $1;
359     }
360     }
361     close wmlrc ;
362    
363 fjp 1.82 $t_body = $u_body = $ui_body = $un_body = $uu_body = $o_body = "";
364 thuriaux 1.64 $translated{$lang} = $outdated{$lang} = $untranslated{$lang} = 0;
365 joy 1.4
366 barbier 1.60 # get stats about files
367     foreach $file (@filenames) {
368     next if ($file eq "");
369 porridge 1.94 (my $base = $file) =~ s/\.wml$//;
370     my $hits = exists $hits{$base} ? $hits{$base}.' hits' : 'hit count N/A';
371 barbier 1.60 # Translated pages
372     if (index ($wmlfiles{$lang}, " $file ") >= 0) {
373     $translated{$lang}++;
374 bertol 1.70 $translated_s{$lang} += $sizes{$file};
375 barbier 1.60 $orig = $original{"$lang/$file"} || "english";
376     # Outdated translations
377     $msg = check_translation ($transversion{"$lang/$file"}, $version{"$orig/$file"}, "$lang/$file");
378     if (length ($msg)) {
379     $o_body .= "<tr>";
380 toddy 1.74 if (($file !~ /\.wml$/)
381 barbier 1.60 || ($file eq "devel/wnpp/wnpp.wml")) {
382     $o_body .= sprintf "<td>%s</td>", $file;
383     } else {
384 porridge 1.94 $o_body .= sprintf "<td><a title=\"%s\" href=\"$opt_b/%s.%s.html\">%s</a></td>", $hits, $base, $l, $base;
385 barbier 1.60 }
386     $o_body .= sprintf "<td>%s</td>", $transversion{"$lang/$file"};
387     $o_body .= sprintf "<td>%s</td>", $version{"$orig/$file"};
388     $o_body .= sprintf "<td>%s</td>", $msg;
389 thuriaux 1.65 if ($msg eq "Wrong translation version" || $msg eq "The original no longer exists") {
390     $o_body .= "<td></td><td></td>";
391     } else {
392 toddy 1.90 $o_body .= sprintf "<td><a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/$orig/%s?root=webwml\&amp;view=diff\&amp;r1=%s\&amp;r2=%s\&amp;diff_format=%s\">%s\&nbsp;->\&nbsp;%s</a></td>",
393 joy 1.85 $file, $transversion{"$lang/$file"}, $version{"$orig/$file"}, $firstdifftype, $transversion{"$lang/$file"}, $version{"$orig/$file"};
394 toddy 1.90 $o_body .= sprintf "<td><a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/$orig/%s?root=webwml\&amp;view=diff\&amp;r1=%s\&amp;r2=%s\&amp;diff_format=%s\">%s\&nbsp;->\&nbsp;%s</a></td>",
395 joy 1.85 $file, $transversion{"$lang/$file"}, $version{"$orig/$file"}, $seconddifftype, $transversion{"$lang/$file"}, $version{"$orig/$file"};
396 thuriaux 1.65 }
397 toddy 1.91 $o_body .= sprintf "<td><a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/$orig/%s?root=webwml#rev%s\">[L]</a></td>", $file, $version{"$orig/$file"};
398 toddy 1.92 $o_body .= sprintf "<td><a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/%s/%s?root=webwml\&amp;view=markup\&amp;revision=%s\">[V]</a>\&nbsp;", $lang, $file, $version{"$orig/$file"};
399     $o_body .= sprintf "<a href=\"http://alioth.debian.org/scm/viewvc.php/*checkout*/webwml/%s/%s?root=webwml\&amp;revision=%s\">[F]</a></td>", $lang, $file, $version{"$orig/$file"};
400 barbier 1.60 $o_body .= sprintf "<td align=center>%s</td>", $maintainer{"$lang/$file"} || "";
401     $o_body .= "</tr>\n";
402     $outdated{$lang}++;
403 bertol 1.70 $outdated_s{$lang} += $sizes{$file};
404 barbier 1.60 # Up-to-date translations
405     } else {
406 toddy 1.74 if (($file !~ /\.wml$/)
407 barbier 1.60 || ($file eq "devel/wnpp/wnpp.wml")) {
408 witch 1.72 $t_body .= sprintf "<li>%s</li>\n", $file;
409 barbier 1.60 } else {
410 porridge 1.94 $t_body .= sprintf "<li><a title=\"%s\" href=\"$opt_b/%s.%s.html\">%s</a></li>\n", $hits, $base, $l, $base;
411 barbier 1.60 }
412     }
413     }
414     # Untranslated pages
415     else {
416 fjp 1.79 my $u_tmp;
417 barbier 1.60 if (($file !~ /\.wml$/)
418     || ($file eq "devel/wnpp/wnpp.wml")) {
419 fjp 1.79 $u_tmp = sprintf "<tr><td>%s</td><td>&nbsp;</td></tr>\n", $file;
420 barbier 1.60 } else {
421 porridge 1.94 $u_tmp = sprintf "<tr><td><a title=\"%s\" href=\"$opt_b/%s\">%s&nbsp;&nbsp;(%s)</a></td><td align=\"right\">%d</td><td>(%.2f&nbsp;&permil;)</td></tr>\n", $hits, $base, $base, $version{"$orig/$file"}, $sizes{$file}, $sizes{$file}/$nsize * 1000;
422 barbier 1.60 }
423 fjp 1.82 if (($file =~ /international\//) &&
424 fjp 1.83 (($file !~ /international\/index.wml$/) ||
425     ($file !~ /international\/l10n\//))) {
426 fjp 1.82 $ui_body .=$u_tmp;
427     } elsif ((($file =~ /(News|events|security|vote)\/[0-9]{4}\//) &&
428     ($file !~ /index.wml$/)) ||
429     ($file =~ /(News\/weekly\/[0-9]{4}\/|security\/undated)/)) {
430 fjp 1.79 $un_body .= $u_tmp;
431     } elsif (($file =~ /(consultants|users\/(com|edu|gov|org))\//) &&
432     ($file !~ /index.wml$/)) {
433     $uu_body .=$u_tmp;
434     } else {
435     $u_body .= $u_tmp;
436     }
437 barbier 1.60 $untranslated{$lang}++;
438 bertol 1.70 $untranslated_s{$lang} += $sizes{$file};
439 barbier 1.60 }
440     }
441 toddy 1.74
442    
443 barbier 1.60 # this is where we discard the files that the translation directory contains
444     # but which don't exist in the English directory
445     # print "extra files: ".$wml{$lang}-$translated{$lang}."\n";
446     $wml{$lang} = $translated{$lang};
447 bertol 1.70 $wml_s{$lang} = $translated_s{$lang};
448 barbier 1.60 $translated{$lang} = $translated{$lang} - $outdated{$lang};
449 bertol 1.70 $translated_s{$lang} = $translated_s{$lang} - $outdated_s{$lang};
450 toddy 1.74
451 barbier 1.60 if ($nfiles > 0) {
452 toddy 1.78 $percent_a{$lang} = $wml{$lang}/$nfiles * 100;
453 barbier 1.60 } else {
454     $percent_a{$lang} = 0;
455 toddy 1.78 }
456     if ($nsize > 0) {
457     $percent_as{$lang} = $wml_s{$lang}/$nsize * 100;
458     } else {
459 bertol 1.70 $percent_as{$lang} = 0;
460 barbier 1.60 }
461     if ($wml{$lang} > 0) {
462 toddy 1.78 $percent_t{$lang} = $translated{$lang}/$wml{$lang} * 100;
463 barbier 1.60 } else {
464     $percent_t{$lang} = 0;
465 toddy 1.78 }
466     if ($wml_s{$lang} > 0) {
467     $percent_ts{$lang} = $translated_s{$lang}/$wml_s{$lang} * 100;
468     } else {
469 bertol 1.70 $percent_ts{$lang} = 0;
470 barbier 1.60 }
471     $percent_o{$lang} = 100 - $percent_t{$lang};
472 bertol 1.70 $percent_os{$lang} = 100 - $percent_ts{$lang};
473 barbier 1.60 $percent_u{$lang} = 100 - $percent_a{$lang};
474 bertol 1.70 $percent_us{$lang} = 100 - $percent_as{$lang};
475 toddy 1.74
476 toddy 1.97 if (open (HTML, ">$config{'htmldir'}/$l.wml")) {
477     printf HTML "#use wml::debian::template title=\"%s\"\n", ucfirst $lang;
478     print HTML "#use wml::debian::toc\n\n";
479 barbier 1.60 $color = get_color ($percent_a{$lang});
480 toddy 1.74
481 toddy 1.97 printf HTML "<table summary=\"Translation summary for $lang\" style=\"background-color: %s\; width: 100%\; font-weight: bold\; margin: 0\; text-align: center\;\">\n", $color;
482 witch 1.72 print HTML "<colgroup span=\"4\" width=\"25%\"></colgroup>\n";
483 toddy 1.74
484 witch 1.72 print HTML "<tr><th>Translated</th><th>Up-to-date</th><th>Outdated</th><th>Not translated</th></tr>\n<tr>";
485 fjp 1.79 printf HTML "<td>%d files (%.1f%%)</td>", $wml{$lang}, $percent_a{$lang};
486     printf HTML "<td>%d files (%.1f%%)</td>", $translated{$lang}, $percent_t{$lang};
487     printf HTML "<td>%d files (%.1f%%)</td>", $outdated{$lang}, $percent_o{$lang};
488 toddy 1.78 printf HTML "<td>%d files (%.1f%%)</td>", $untranslated{$lang}, $percent_u{$lang};
489 barbier 1.60 print HTML "</tr>\n";
490 bertol 1.70 print HTML "<tr>\n";
491 fjp 1.79 printf HTML "<td>%d bytes (%.1f%%)</td>", $wml_s{$lang}, $percent_as{$lang};
492     printf HTML "<td>%d bytes (%.1f%%)</td>", $translated_s{$lang}, $percent_ts{$lang};
493     printf HTML "<td>%d bytes (%.1f%%)</td>", $outdated_s{$lang}, $percent_os{$lang};
494 witch 1.72 printf HTML "<td>%d bytes (%.1f%%)</td>", $nsize-$wml_s{$lang}, $percent_us{$lang};
495 bertol 1.70 print HTML "</tr>\n";
496 barbier 1.60 print HTML "</table>\n";
497 toddy 1.74
498 barbier 1.60 # Make the table of content
499 toddy 1.97 print HTML "<toc-display/>\n";
500 porridge 1.95 if (%hits) {
501     print HTML "<p>Note: The lists of pages are sorted by popularity. Hover over the page name to see the number of hits.</p>\n";
502     }
503    
504 barbier 1.60 # outputs the content
505     if ($o_body) {
506 toddy 1.97 print HTML "<toc-add-entry name=\"outdated\">Outdated translations</toc-add-entry>\n";
507 fjp 1.80 print HTML "<table summary=\"Outdated translations\" border=0 cellpadding=1 cellspacing=1>\n";
508 barbier 1.60 print HTML "<tr><th>File</th><th>Translated</th><th>Origin</th><th>Comment</th>";
509 joy 1.85 if ($opt_d eq "u") { print HTML "<th>Unified diff</th><th>Colored diff</th>"; }
510     elsif ($opt_d eq "h") { print HTML "<th>Colored diff</th><th>Unified diff</th>"; }
511 barbier 1.60 else { print HTML "<th>Diff</th>"; }
512     print HTML "<th>Log</th>";
513 spaillar 1.86 print HTML "<th>Translation</th>";
514 barbier 1.60 print HTML "<th>Maintainer</th>";
515     print HTML "</tr>\n";
516     print HTML $o_body;
517     print HTML "</table>\n";
518     }
519     if ($u_body) {
520 toddy 1.97 print HTML "<toc-add-entry name=\"untranslated\">General pages not translated</toc-add-entry>\n";
521 fjp 1.80 print HTML "<table summary=\"Untranslated general pages\">\n";
522 barbier 1.60 print HTML $u_body;
523 fjp 1.80 print HTML "</table>\n";
524 barbier 1.60 }
525 fjp 1.79 if ($un_body) {
526 toddy 1.97 print HTML "<toc-add-entry name=\"untranslated-news\">News items not translated</toc-add-entry>\n";
527 fjp 1.80 print HTML "<table summary=\"Untranslated news items\">\n";
528 fjp 1.79 print HTML $un_body;
529 fjp 1.80 print HTML "</table>\n";
530 fjp 1.79 }
531     if ($uu_body) {
532 toddy 1.97 print HTML "<toc-add-entry name=\"untranslated-user\">Consultant/user pages not translated</toc-add-entry>\n";
533 fjp 1.80 print HTML "<table summary=\"Untranslated consultant/user pages\">\n";
534 fjp 1.79 print HTML $uu_body;
535 fjp 1.80 print HTML "</table>\n";
536 fjp 1.79 }
537 taffit-guest 1.96 if ($ui_body) {
538 toddy 1.97 print HTML "<toc-add-entry name=\"untranslated-l10n\"'>International pages not translated</toc-add-entry>\n";
539 taffit-guest 1.96 print HTML "<table summary=\"Untranslated international pages\">\n";
540     print HTML $ui_body;
541     print HTML "</table>\n";
542     }
543 barbier 1.60 if ($t_body) {
544 toddy 1.97 print HTML "<toc-add-entry name=\"uptodate\">Translated pages (up-to-date)</toc-add-entry>\n";
545 fjp 1.80 print HTML "<ul class=\"discless\">\n";
546 barbier 1.60 print HTML $t_body;
547 fjp 1.80 print HTML "</ul>\n";
548 barbier 1.60 }
549     # outputs the gettext stats
550     if ($lang ne 'english') {
551 toddy 1.97 print HTML "<toc-add-entry name=\"gettext\">Translation of templates (gettext files)</toc-add-entry>\n";
552 fjp 1.79 print HTML "<table summary=\"Gettext statistics\" width=\"100%\">\n";
553 barbier 1.60 print HTML "<tr><th>File</th><th>Up to date</th><th>Fuzzy</th><th>Untranslated</th><th>Total</th></tr>\n";
554     foreach my $domain (sort keys %po_total) {
555     next if $domain eq 'total';
556     print HTML "<tr>";
557 toddy 1.74
558 barbier 1.60 $color_t = get_color ($percent_po_t{$domain}{$lang});
559     $color_f = get_color (100 - $percent_po_f{$domain}{$lang});
560     $color_u = get_color (100 - $percent_po_u{$domain}{$lang});
561 toddy 1.74
562 barbier 1.60 print HTML "<td>$domain.$langs{$lang}.po</td>";
563 witch 1.72 printf HTML "<td style=\"background-color: %s\" align=right>%d (%s%%)</td>", $color_t, $po_translated{$domain}{$lang}, $percent_po_t{$domain}{$lang};
564     printf HTML "<td style=\"background-color: %s\" align=right>%d (%s%%)</td>", $color_f, $po_fuzzy{$domain}{$lang}, $percent_po_f{$domain}{$lang};
565     printf HTML "<td style=\"background-color: %s\" align=right>%d (%s%%)</td>", $color_u, $po_untranslated{$domain}{$lang}, $percent_po_u{$domain}{$lang};
566 barbier 1.60 printf HTML "<td align=right>%d</td>", $po_total{$domain};
567     print HTML "</tr>\n";
568     }
569     print HTML "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr><tr><th>Total:</th>";
570     $color_t = get_color ($percent_po_t{'total'}{$lang});
571     $color_f = get_color (100 - $percent_po_f{'total'}{$lang});
572     $color_u = get_color (100 - $percent_po_u{'total'}{$lang});
573 witch 1.72 printf HTML "<td style=\"background-color: %s\" align=right>%d (%d%%)</td>", $color_t, $po_translated{'total'}{$lang}, $percent_po_t{'total'}{$lang};
574     printf HTML "<td style=\"background-color: %s\" align=right>%d (%d%%)</td>", $color_f, $po_fuzzy{'total'}{$lang}, $percent_po_f{'total'}{$lang};
575     printf HTML "<td style=\"background-color: %s\" align=right>%d (%d%%)</td>", $color_u, $po_untranslated{'total'}{$lang}, $percent_po_u{'total'}{$lang};
576 barbier 1.60 printf HTML "<td align=right>%d</td>", $po_total{'total'};
577     print HTML "</tr>\n";
578 fjp 1.84 print HTML "</table>\n";
579 barbier 1.60 }
580 toddy 1.74
581 toddy 1.97 print HTML "<p><address>Created with <a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/stattrans.pl?view=markup\&amp;root=webwml\">webwml-stattrans</a></address></p>\n";
582 barbier 1.60 close (HTML);
583 toddy 1.98 } else {
584     print "Can't open $config{'htmldir'}/$l.wml\n";
585 barbier 1.60 }
586 joy 1.1 }
587     }
588 joy 1.7 print "\n" if ($config{'verbose'});
589 joy 1.1
590     # =============== Creating index.html ===============
591 toddy 1.97 print "Creating index.wml... " if ($config{'verbose'});
592 joy 1.1
593 toddy 1.97 open (HTMLI, ">$config{'htmldir'}/index.wml")
594     || die "Can't open $config{'htmldir'}/index.wml";
595 joy 1.1
596 toddy 1.97 printf HTMLI "#use wml::debian::template title=\"%s\"\n\n", $config{'title'};
597 witch 1.72 print HTMLI "<h2>Translated web pages</h2>\n";
598     printf HTMLI "<p>There are %d pages to translate.</p>\n",($wml{'english'}+$untranslated{'english'});
599    
600 witch 1.73 print HTMLI "<table summary=\"Translation Statistics by Page Count\" class=\"stattrans\">\n";
601 witch 1.72 print HTMLI "<colgroup width=\"20%\">\n";
602     print HTMLI "<col>\n";
603     print HTMLI "</colgroup>";
604     print HTMLI "<colgroup width=\"10%\">\n";
605     print HTMLI "<col width=\"10%\">\n";
606     print HTMLI "<col width=\"10%\">\n";
607     print HTMLI "<col width=\"10%\">\n";
608     print HTMLI "<col width=\"10%\">\n";
609     print HTMLI "<col width=\"10%\">\n";
610     print HTMLI "<col width=\"10%\">\n";
611     print HTMLI "<col width=\"10%\">\n";
612     print HTMLI "<col width=\"10%\">\n";
613     print HTMLI "</colgroup>";
614     print HTMLI "<thead>";
615     print HTMLI "<tr><th>Language</th><th colspan=\"2\">Translations</th><th colspan=\"2\">Up to date</th><th colspan=\"2\">Outdated</th><th colspan=\"2\">Not translated</th></tr>\n";
616     print HTMLI "</thead>";
617     print HTMLI "<tbody>";
618 joy 1.14 foreach $lang (@search_in) {
619 barbier 1.61 my @processed_langs = ($langs{$lang});
620     @processed_langs = ("zh-cn", "zh-tw") if $langs{$lang} eq "zh";
621     foreach $l (@processed_langs) {
622 barbier 1.62 $color_a = get_color ($percent_a{$lang});
623     $color_t = get_color ($percent_t{$lang});
624     $color_o = get_color (100 - $percent_o{$lang});
625     $color_u = get_color (100 - $percent_u{$lang});
626    
627 witch 1.72 print HTMLI "<tr>";
628 toddy 1.97 printf HTMLI "<th><a href=\"%s\">%s</a> (%s)</th>", $l, ucfirst $lang, $l;
629 toddy 1.78 printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_a, $wml{$lang}, $percent_a{$lang};
630     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_t, $translated{$lang}, $percent_t{$lang};
631     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_o, $outdated{$lang}, $percent_o{$lang};
632     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_u, $untranslated{$lang}, $percent_u{$lang};
633 witch 1.72 print HTMLI "</tr>\n";
634 barbier 1.61 }
635 joy 1.1 }
636 witch 1.72 print HTMLI "</tbody>";
637     print HTMLI "</table>\n";
638    
639     print HTMLI "<h2>Translated web pages (by size)</h2>\n";
640     printf HTMLI "<p>There are %d bytes to translate.</p>\n",($wml_s{'english'}+$untranslated_s{'english'});
641    
642 witch 1.73 print HTMLI "<table summary=\"Translation Statistics by Page Size\" class=\"stattrans\">\n";
643 witch 1.72 print HTMLI "<colgroup span=\"1\">\n";
644     print HTMLI "<col width=\"20%\">\n";
645     print HTMLI "</colgroup>";
646     print HTMLI "<colgroup span=\"8\">\n";
647     print HTMLI "<col width=\"13%\">\n";
648     print HTMLI "<col width=\"7%\">\n";
649     print HTMLI "<col width=\"13%\">\n";
650     print HTMLI "<col width=\"7%\">\n";
651     print HTMLI "<col width=\"13%\">\n";
652     print HTMLI "<col width=\"7%\">\n";
653     print HTMLI "<col width=\"13%\">\n";
654     print HTMLI "<col width=\"7%\">\n";
655     print HTMLI "</colgroup>";
656     print HTMLI "<thead>";
657     print HTMLI "<tr><th>Language</th><th colspan=\"2\">Translations</th><th colspan=\"2\">Up to date</th><th colspan=\"2\">Outdated</th><th colspan=\"2\">Not translated</th></tr>\n";
658     print HTMLI "</thead>";
659     print HTMLI "<tbody>";
660 bertol 1.70
661     foreach $lang (@search_in) {
662     my @processed_langs = ($langs{$lang});
663     @processed_langs = ("zh-cn", "zh-tw") if $langs{$lang} eq "zh";
664     foreach $l (@processed_langs) {
665     $color_a = get_color ($percent_a{$lang});
666     $color_t = get_color ($percent_t{$lang});
667     $color_o = get_color (100 - $percent_o{$lang});
668     $color_u = get_color (100 - $percent_u{$lang});
669    
670 witch 1.72 print HTMLI "<tr>";
671 toddy 1.97 printf HTMLI "<th><a href=\"%s\">%s</a> (%s)</th>", $l, ucfirst $lang, $l;
672 toddy 1.77 printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_a, $wml_s{$lang}, $percent_as{$lang};
673     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_t, $translated_s{$lang}, $percent_ts{$lang};
674     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_o, $outdated_s{$lang}, $percent_os{$lang};
675     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%.1f%%)</td>", $color_u, $wml_s{"english"}+$untranslated_s{'english'}-$wml_s{$lang}, $percent_us{$lang};
676 witch 1.72 print HTMLI "</tr>\n";
677 bertol 1.70 }
678     }
679 witch 1.72 print HTMLI "</tbody>";
680     print HTMLI "</table>\n";
681    
682     print HTMLI "<h2>Translated templates (gettext files)</h2>\n";
683     printf HTMLI "<p>There are %d strings to translate.</p>\n",$po_total{'total'};
684 porridge 1.93 print HTMLI "<table summary=\"Gettext Translation Statistics\"class=\"stattrans\">\n";
685 witch 1.72 print HTMLI "<colgroup span=\"1\"width=\"28%\">\n";
686     print HTMLI "</colgroup>";
687     print HTMLI "<colgroup span=\"6\" width=\"12%\">\n";
688     print HTMLI "<col width=\"12%\">\n";
689     print HTMLI "<col width=\"12%\">\n";
690     print HTMLI "<col width=\"12%\">\n";
691     print HTMLI "<col width=\"12%\">\n";
692     print HTMLI "<col width=\"12%\">\n";
693     print HTMLI "<col width=\"12%\">\n";
694     print HTMLI "</colgroup>";
695     print HTMLI "<thead>";
696     print HTMLI "<tr><th>Language</th><th colspan=\"2\">Up to date</th><th colspan=\"2\">Fuzzy</th><th colspan=\"2\">Not translated</th></tr>\n";
697     print HTMLI "</thead>";
698     print HTMLI "<tbody>";
699 barbier 1.40 foreach $lang (@search_in) {
700     next if $lang eq 'english';
701 barbier 1.61 my @processed_langs = ($langs{$lang});
702     @processed_langs = ("zh-cn", "zh-tw") if $langs{$lang} eq "zh";
703     foreach $l (@processed_langs) {
704 witch 1.72 print HTMLI "<tr>";
705 toddy 1.97 printf HTMLI "<th><a href=\"%s#gettext\">%s</a> (%s)</th>", $l, ucfirst $lang, $l;
706 barbier 1.62 $color_t = get_color ($percent_po_t{'total'}{$lang});
707     $color_f = get_color (100 - $percent_po_f{'total'}{$lang});
708     $color_u = get_color (100 - $percent_po_u{'total'}{$lang});
709 toddy 1.77 printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%d%%)</td>", $color_t, $po_translated{'total'}{$lang}, $percent_po_t{'total'}{$lang};
710     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%d%%)</td>", $color_f, $po_fuzzy{'total'}{$lang}, $percent_po_f{'total'}{$lang};
711     printf HTMLI "<td style=\"background-color: %s\">%d</td><td>(%d%%)</td>", $color_u, $po_untranslated{'total'}{$lang}, $percent_po_u{'total'}{$lang};
712 witch 1.72 print HTMLI "</tr>\n";
713 barbier 1.61 }
714 french 1.43 }
715 barbier 1.40
716 witch 1.72 print HTMLI "</tbody>";
717     print HTMLI "</table>\n";
718    
719 toddy 1.97 print HTMLI "<p><address>Created with <a href=\"http://alioth.debian.org/scm/viewvc.php/webwml/stattrans.pl?view=markup\&amp;root=webwml\">webwml-stattrans</a></address></p>\n";
720 witch 1.72 close (HTMLI);
721 joy 1.1
722 joy 1.7 print "done.\n" if ($config{'verbose'});
723 joy 1.1
724     # Note:
725     # Translated pages on ll.html may be higher than in index.html.
726     # This is due to the fact that some english pages were removed.
727    
728     # printf "%s\n", join ("\n", keys %version);
729     # printf "%s - %s\n", $version{'german/devel/index'}, $version{'english/devel/index'};

  ViewVC Help
Powered by ViewVC 1.1.5