| 1 |
#!/usr/bin/env perl |
| 2 |
|
| 3 |
#============================================================ |
| 4 |
# util/check_I18N.pl |
| 5 |
# |
| 6 |
# pull messages file, and check the I18N lexicons for |
| 7 |
# coverage |
| 8 |
#============================================================ |
| 9 |
|
| 10 |
use strict; |
| 11 |
use warnings; |
| 12 |
|
| 13 |
use utf8; |
| 14 |
use Encode; |
| 15 |
use Cwd; |
| 16 |
use File::Find; |
| 17 |
use Class::Load ':all'; |
| 18 |
use Data::Dumper; |
| 19 |
use lib ( getcwd() . '/lib'); |
| 20 |
use HTML::FormHandler::I18N; |
| 21 |
|
| 22 |
my @directories = ( getcwd() . "/lib/HTML/FormHandler/I18N" ); |
| 23 |
my @lexicons; |
| 24 |
find(\&wanted, @directories); |
| 25 |
|
| 26 |
my $infile = getcwd() . '/util/messages'; |
| 27 |
open( my $fh, '<:utf8', $infile ) or die "Unable to open $infile"; |
| 28 |
my $line = 1; |
| 29 |
my @lines = <$fh>; |
| 30 |
my $msgs_from_file = join( ' ', @lines ); |
| 31 |
my $messages = eval $msgs_from_file; |
| 32 |
my @builtin_messages = map { values %{$_} } (map { values %{$_}} @$messages); |
| 33 |
|
| 34 |
binmode STDOUT, ":utf8"; |
| 35 |
foreach my $lexicon (@lexicons) { |
| 36 |
print "\n\n========== $lexicon ================\n"; |
| 37 |
my $lh = HTML::FormHandler::I18N->get_handle($lexicon); |
| 38 |
foreach my $msg (@builtin_messages) { |
| 39 |
my $translated = $lh->maketext($msg, '[_1]', '[_2]'); |
| 40 |
print $msg, " ==> ", $translated, "\n"; |
| 41 |
} |
| 42 |
|
| 43 |
} |
| 44 |
|
| 45 |
# you can pull in the arrayref of hashrefs that's written out |
| 46 |
#my $recovered = eval $output; |
| 47 |
|
| 48 |
sub wanted { |
| 49 |
my $type = $_; |
| 50 |
return if $type eq '.'; |
| 51 |
$type =~ s/\.pm$//; |
| 52 |
my $class = "HTML::FormHandler::I18N::$type"; |
| 53 |
if( try_load_class( $class ) ) { |
| 54 |
push @lexicons, $type; |
| 55 |
print "$type\n"; |
| 56 |
} |
| 57 |
else { |
| 58 |
print "did not load $type\n"; |
| 59 |
} |
| 60 |
|
| 61 |
} |