#! /usr/bin/perl # Prerequisites: # Input files given as argument (e.g., *.po) # set URL with -U option use strict; use warnings; use File::Basename; use Getopt::Std; use POSIX qw(:math_h); use I18N::LangTags::List; our $QUALIFIED_CUTOFF = 80; my %opts; getopts('U:l:', \%opts) or die; my $po_url = $opts{'U'} || 'po'; my $list_filename = $opts{'l'}; open my $list_fh, '>', $opts{'l'} if $list_filename; my $everything; my $errors; my $new; if (!@ARGV) { die "gotta give me at least one file\n"; } # read in counts my @catalogs; my %catalog_count; foreach (@ARGV) { /(\w+).pot/ && do { my $catname = $1; push @catalogs, $catname; my $tmp = `LC_ALL=C msgfmt -o /dev/null -v $_ 2>&1`; $tmp =~ /(\d+) untranslated/ and $catalog_count{$catname} = $1; next; }; /(\w+)-(\w+).po/ || next; my $catalogname = $1; my $lang = $2; my $tmp; if (-e "$_.old") { $tmp = `LC_ALL=C msgfmt -o /dev/null -v $_.old 2>&1`; } else { $tmp = `LC_ALL=C msgfmt -o /dev/null -v $_ 2>&1`; $new->{$catalogname}{$lang} = 1; } $tmp =~ /(\d+) translated/ and $everything->{"$catalogname"}{"$lang"} = $1; if (-f "$_.err") { $errors->{"$catalogname"}{"$lang"} = 1; } } # compute all distinct languages available my @all_lang = (); foreach my $catalog (@catalogs) { foreach my $lang (keys %{ $everything->{$catalog} }) { if (not grep($_ eq $lang, @all_lang)) { push @all_lang, $lang; } # Convert count to percentage here; can't do it above in case we # hadn't seen the pot file yet. $everything->{$catalog}{$lang} = floor($everything->{$catalog}{$lang} / $catalog_count{$catalog} * 100); } } @all_lang = sort @all_lang; print "
Last update:
\n"; print "\n"; foreach (@all_lang) { my $c; ($c = $_) =~ tr/_/-/; print " | $_ | \n"; } print "" . scalar(@all_lang) . " | \n"; print "
---|---|---|
";
print "$catalog";
print " (" . $catalog_count{$catalog} . " strings)"; print " | \n";
foreach my $lang (@all_lang) {
my $pct = $everything->{$catalog}{$lang};
print "{"$catalog"}{"$lang"}) { print " class='errorpo'"; } elsif (defined $pct and int($pct) == 100) { print " class='fullpo'"; } elsif (defined $pct and $pct >= $QUALIFIED_CUTOFF) { print " class='qualifiedpo'"; } print ">"; if (defined $pct and $pct > 0) { if (!$new->{$catalog}{$lang}) { printf "%.0f", $pct; push @{ $langavg{"$lang"} }, $pct; push @catavg, $pct; } else { printf "%.0f", $pct; } if ($errors->{"$catalog"}{"$lang"}) { print " (E)"; } } elsif ($errors->{"$catalog"}{"$lang"}) { print " (E)"; } else { print " "; } print " | \n"; print $list_fh "$catalog/$lang\n" if $list_filename and defined $pct and $pct >= $QUALIFIED_CUTOFF; } print ""; printf "%d", scalar(@catavg); if (@catavg) { printf " (%.0f)", floor(list_sum(@catavg) / scalar(@catavg)); } print " | \n"; print "
" . scalar(@catalogs) . " | \n"; foreach my $lang (@all_lang) { print ""; if (@{ $langavg{$lang} }) { printf "%d (%.0f)", scalar(@{ $langavg{$lang} }), floor(list_sum(@{ $langavg{$lang} }) / scalar(@{ $langavg{$lang} })); push @totalavg, @{ $langavg{$lang} }; } print " | \n"; } print ""; printf "%d (%.0f)", scalar(@totalavg), floor(list_sum(@totalavg) / scalar(@totalavg)); print " | \n"; print "