SCM

SCM Repository

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

Annotation of /webwml/stattrans.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (view) (download) (as text)

1 : joy 1.1 #! /usr/bin/perl
2 :    
3 :     # webwml-stattrans - Website Translation Statistics
4 :     # 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 :     # Foundation, Inc.,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 :    
20 :     use POSIX qw(strftime);
21 :    
22 :     %config = (
23 : joy 1.2 'htmldir' => '/org/www.debian.org/debian.org/devel/website/stats', #fixme
24 : joy 1.1 #'htmldir' => '/home/users/joey/public_html/webwml/', #fixme
25 :     #'wmldir' => '/home/project/Debian/CVS/webwml', #fixme
26 :     'wmldir' => '/org/www.debian.org/webwml', #fixme
27 :     'wmlpat' => '*.wml',
28 :     'title' => 'Website Translation Statistics',
29 :     'verbose' => 0,
30 :     );
31 :    
32 :     $max_versions = 5;
33 :     $min_versions = 1;
34 :    
35 :     # from ../webwml/english/template/debian/languages.wml
36 :     # Needs to be synced frequently
37 :     my %langs = ( english => "en",
38 :     hellas => "el",
39 :     turkish => "tr",
40 :     romanian => "ro",
41 :     esperanto => "eo",
42 :     finnish => "fi",
43 :     portuguese => "pt",
44 :     danish => "da",
45 :     french => "fr",
46 :     dutch => "nl",
47 :     german => "de",
48 :     italian => "it",
49 :     spanish => "es",
50 :     korean => "ko",
51 :     japanese => "ja",
52 :     croatian => "hr",
53 :     chinese => "zh",
54 :     swedish => "sv",
55 :     polish => "pl",
56 :     norwegian => "no",
57 :     russian => "ru",
58 :     hungarian => "hu",
59 :     );
60 :    
61 :     $border_head = "<table border=0 cellpadding=0 cellspacing=0><tr bgcolor=#000000><td>"
62 :     ."<table width=100% border=0 cellpadding=0 cellspacing=1><tr bgcolor=#ffffff><td>";
63 :     $border_foot = "</td></tr></table></td></tr></table>";
64 :    
65 :    
66 :     $date = strftime "%a %b %e %H:%M:%S %Y %z", localtime;
67 :    
68 :     sub get_cvs_version
69 :     {
70 :     my ($dir, $wmlfile) = @_;
71 :     my $file;
72 :     my @comp;
73 :     my $version;
74 :    
75 :     @comp = split (/\//, "$dir/$wmlfile");
76 :     pop @comp;
77 :     $dir = join ("/", @comp);
78 :    
79 :     @comp = split (/\//, "$wmlfile");
80 :     $file = pop @comp;
81 :    
82 :     if (open (CVS,"$dir/CVS/Entries")) {
83 :     while (<CVS>) {
84 :     ($version) = $_ =~ m,/\Q$file\E/([\d\.]*),;
85 :     last if $version;
86 :     }
87 :     }
88 :    
89 :     return $version;
90 :     }
91 :    
92 :     sub get_translation_version
93 :     {
94 :     my ($dir, $file) = @_;
95 :     my $checktrans;
96 :    
97 :     if (open (F, "$dir/$file")) {
98 :     $checktrans = 0;
99 :     while (<F>) {
100 :     chomp;
101 :     if (/^\#use wml::debian::translation-check/) {
102 :     $checktrans = 1;
103 :     return $1 if ($_ =~ /translation="([^\" ]+)"/);
104 :     last;
105 :     }
106 :     }
107 :     close (F);
108 :     }
109 :     return "";
110 :     }
111 :    
112 :     # Count wml files in given directory
113 :     #
114 :     sub getwmlfiles
115 :     {
116 :     my $lang = shift;
117 :     my $cmd = "find $config{'wmldir'}/$lang -name \"$config{'wmlpat'}\"";
118 :     my $cutfrom = length ($config{'wmldir'})+length($lang)+2;
119 :     my $count = 0;
120 :     my $is_english = ($lang eq "english")?1:0;
121 :     my $file, $v;
122 :    
123 :     return if (! -d "$config{'wmldir'}/$lang");
124 :     open (FIND, "$cmd|") || die "Can't read from $cmd";
125 :     while (<FIND>) {
126 :     next if (/\/sitemap\.wml/);
127 :     next if (/\/template\//);
128 :     next if (/\/MailingLists\/(un)?subscribe\.wml/);
129 :     chomp;
130 :     $file = substr ($_, $cutfrom);
131 :     $file =~ s/\.wml$//;
132 :     $wmlfiles{$langs{$lang}} .= " " . $file;
133 :     if ($is_english) {
134 :     $version{"$lang/$file"} = get_cvs_version ("$config{'wmldir'}/$lang", "$file.wml");
135 :     } else {
136 :     $version{"$lang/$file"} = get_translation_version ("$config{'wmldir'}/$lang", "$file.wml");
137 :     }
138 :     $count++;
139 :     }
140 :     close (FIND);
141 :     $wmlfiles{$langs{$lang}} .= " ";
142 :     $wml{$langs{$lang}} = $count;
143 :     }
144 :    
145 :     sub get_color
146 :     {
147 :     my $percent = shift;
148 :     my $per;
149 :    
150 :     if ((255 - ($percent * (255/75))) < 0) {
151 :     return sprintf ("#%02x%02x00", 255 - ($percent * (255/100)), $percent * (255/100));
152 :     } else {
153 :     return sprintf ("#%02x%02x00", 255 - ($percent * (255/75)), $percent * (255/100));
154 :     }
155 :     }
156 :    
157 :     sub check_translation
158 :     {
159 :     my ($translation, $version, $file) = @_;
160 :     my @version_numbers, $major_number, $last_number;
161 :     my @translation_numbers, $major_translated_number, $last_translated_number;
162 :    
163 :     if ($version ne "" && $translation ne "") {
164 :     @version_numbers = split /\./,$version;
165 :     $major_number = @version_numbers[0];
166 :     $last_number = pop @version_numbers;
167 :     die "Invalid CVS revision for $file: $version\n"
168 :     unless ($major_number =~ /\d+/ && $last_number =~ /\d+/);
169 :    
170 :     @translation_numbers = split /\./,$translation;
171 :     $major_translated_number = @translation_numbers[0];
172 :     $last_translated_number = pop @translation_numbers;
173 :     die "Invalid translation revision for $file: $translation\n"
174 :     unless ($major_translated_number =~ /\d+/ && $last_translated_number =~ /\d+/);
175 :    
176 :     # Here we compare the original version with the translated one and print
177 :     # a note for the user if their first or last numbers are too far apart
178 :     # From translation-check.wml
179 :    
180 :     if ($version eq "") {
181 :     return "The original no longer exists";
182 :     } elsif ( $major_number != $major_translated_number ) {
183 :     return "This translation is too out of date";
184 :     } elsif ( $last_number - $last_translated_number >= $max_versions ) {
185 :     return "This translation is too out of date";
186 :     } elsif ( $last_number - $last_translated_number >= $min_versions ) {
187 :     return "The original is newer than this translation";
188 :     }
189 :     }
190 :     return "";
191 :     }
192 :    
193 :     print "Investigating english \n" if ($config{'verbose'});
194 :    
195 :     getwmlfiles ('english');
196 :    
197 :     foreach $l (keys %langs) {
198 :     next if ($l eq "english");
199 :     print "$l " if ($config{'verbose'});
200 :     getwmlfiles ($l);
201 :     }
202 :     print "\n" if ($config{'verbose'});
203 :    
204 :     # =============== Create HTML files ===============
205 :     mkdir ($config{'htmldir'}, 0755) if (! -d $config{'htmldir'});
206 :    
207 :     @sorted_english = sort (split (/ /, $wmlfiles{'en'}));
208 :    
209 :     foreach $lang (sort (keys %langs)) {
210 :     $l = $langs{$lang};
211 :     printf "Creating %s.html...\n", $l if ($config{'verbose'});
212 :     if (open (HTML, ">$config{'htmldir'}/$l.html")) {
213 :     printf HTML "<html><head><title>%s: %s</title></head><body bgcolor=#ffffff>\n", $config{'title'}, $l;
214 :    
215 :     $percent = $wml{$l}/$wml{'en'} * 100;
216 :     $color = get_color ($percent);
217 :    
218 :     printf HTML "<table width=100%% cellpadding=2 cellspacing=0 bgcolor=%s>\n", $color;
219 :    
220 :     printf HTML "<tr><td colspan=2><h1 align=center>%s: %s</h1></td></tr>", $config{'title'}, $l;
221 :    
222 :     printf HTML "<tr><td align=center width=50%%><b>%d files (%d%%) translated</b></td>", $wml{$l}, $percent;
223 :     printf HTML "<td align=center width=50%%><b>%d files untranslated</b></td></tr></table>", $wml{'en'} - $wml{$l};
224 :    
225 : joy 1.3 print HTML "<p><a href=\"./\">Index</a><p>\n";
226 :     print HTML "<p><a href=\"../\">Working on the website</a><p>\n";
227 : joy 1.1
228 :     $body = '';
229 :     foreach $file (@sorted_english) {
230 :     next if ($file eq "");
231 :     $msg = check_translation ($version{"$lang/$file"}, $version{"english/$file"}, "$lang/$file");
232 :     if (length ($msg)) {
233 : joy 1.3 $body .= sprintf ("<tr><td><a href=\"/%s.%s.html\">%s</a></td><td>%s</td><td>%s</td>"
234 : joy 1.1 ."<td>%s</td></tr>\n",
235 :     $file, $l, $file, $version{"$lang/$file"}, $version{"english/$file"}, $msg);
236 :     $outdated{$lang}++;
237 :     }
238 :     }
239 :     if ($body) {
240 :     print HTML "<h3>Out-dated pages:</h3>";
241 :     print HTML "<table border=0 cellpadding=1 cellspacing=1>\n";
242 :     print HTML "<tr><th>File</th><th>Translated</th><th>English</th><th>Comment</th></tr>\n";
243 :     print HTML $body;
244 :     print HTML "</table>\n";
245 :     }
246 :    
247 :     # Untranslated pages
248 :     $body = '';
249 :     foreach $file (@sorted_english) {
250 :     next if ($file eq "");
251 :     if (index ($wmlfiles{$l}, " $file ") < 0) {
252 : joy 1.3 $body .= sprintf ("<a href=\"/%s\">%s</a><br>", $file, $file);
253 : joy 1.1 $untranslated{$lang}++;
254 :     }
255 :     }
256 :     if ($body) {
257 :     print HTML "<h3>Untranslated pages:</h3>";
258 :     print HTML $body;
259 :     }
260 :    
261 :     # Translated pages
262 :     $body = '';
263 :     foreach $file (@sorted_english) {
264 :     next if ($file eq "");
265 :     if (index ($wmlfiles{$l}, " $file ") >= 0) {
266 : joy 1.3 $body .= sprintf ("<a href=\"/%s.%s.html\">%s</a><br>\n",
267 : joy 1.1 $file, $l, $file);
268 :     $translated{$lang}++;
269 :     }
270 :     }
271 :     if ($body) {
272 :     print HTML "<h3>Translated pages:</h3>";
273 :     print HTML $body;
274 :     }
275 :    
276 :     print HTML "</table>\n";
277 :     print HTML "<hr><address>Compiled at $date</address>\n";
278 :     print HTML "</body></html>";
279 :     close (HTML);
280 :     }
281 :     }
282 :    
283 :     # =============== Creating index.html ===============
284 :     print "Creating index.html...\n" if ($config{'verbose'});
285 :    
286 :     open (HTML, ">$config{'htmldir'}/index.html")
287 :     || die "Can't open $config{'htmldir'}/index.html";
288 :    
289 : joy 1.3 printf HTML "<html>\n<head><title>%s</title></head>\n<body bgcolor=#ffffff>\n", $config{'title'};
290 :     printf HTML "<h1>%s</h1>\n", $config{'title'};
291 : joy 1.1
292 :     print HTML $border_head;
293 : joy 1.3 print HTML "<table border=0 bgcolor=\"#cdc9c9\">\n";
294 : joy 1.1 print HTML "<tr><th>Language</th><th>Percent</th><th>Translated</th><th>Out-dated</th><th>Untranslated</th></tr>\n";
295 :     foreach $lang (sort (keys %langs)) {
296 :     $l = $langs{$lang};
297 :     $percent = $wml{$l}/$wml{'en'} * 100;
298 :     $color = get_color ($percent);
299 :     printf HTML "<tr bgcolor=\"%s\"><td><a href=\"%s.html\">%s</a> (%s)</td><td align=right>%d%%</td>"
300 :     ."<td align=right>%d</td><td align=right>%d</td><td align=right>%d</td></tr>\n",
301 :     $color, $l, $lang, $l, $percent, $translated{$lang}, $outdated{$lang}, $untranslated{$lang};
302 :     }
303 :    
304 :     print HTML "</tr></table>";
305 :     print HTML $border_foot;
306 :    
307 : joy 1.3 print HTML "</table>\n";
308 :     print HTML "<p>Made with <a href=\"http://cvs.debian.org/webwml/stattrans.pl?cvsroot=webwml\">webwml-stattrans</a>\n";
309 :     print HTML "<p><hr><address>Compiled at $date</address>\n";
310 :     print HTML "</body></html>\n";
311 : joy 1.1 close (HTML);
312 :    
313 :    
314 :     # Note:
315 :     # Translated pages on ll.html may be higher than in index.html.
316 :     # This is due to the fact that some english pages were removed.
317 :    
318 :     # printf "%s\n", join ("\n", keys %version);
319 :     # printf "%s - %s\n", $version{'german/devel/index'}, $version{'english/devel/index'};

root@alioth.debian.org
ViewVC Help
Powered by ViewVC 1.0.0  
Powered By FusionForge
Show source