File: check_I18N.pl

package info (click to toggle)
libhtml-formhandler-perl 0.40057-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,320 kB
  • ctags: 685
  • sloc: perl: 8,849; makefile: 2
file content (61 lines) | stat: -rwxr-xr-x 1,542 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env perl

#============================================================
# util/check_I18N.pl
#
# pull messages file, and check the I18N lexicons for
# coverage
#============================================================

use strict;
use warnings;

use utf8;
use Encode;
use Cwd;
use File::Find;
use Class::Load ':all';
use Data::Dumper;
use lib ( getcwd() . '/lib');
use HTML::FormHandler::I18N;

my @directories = ( getcwd() . "/lib/HTML/FormHandler/I18N" );
my @lexicons;
find(\&wanted, @directories);

my $infile = getcwd() . '/util/messages';
open( my $fh, '<:utf8', $infile ) or die "Unable to open $infile";
my $line = 1;
my @lines = <$fh>;
my $msgs_from_file = join( ' ', @lines );
my $messages = eval $msgs_from_file;
my @builtin_messages = map { values %{$_} } (map { values %{$_}} @$messages);

binmode STDOUT, ":utf8";
foreach my $lexicon (@lexicons) {
    print "\n\n========== $lexicon ================\n";
    my $lh = HTML::FormHandler::I18N->get_handle($lexicon);
    foreach my $msg (@builtin_messages) {
        my $translated = $lh->maketext($msg, '[_1]', '[_2]');
        print $msg, "  ==>  ", $translated, "\n";
    }

}

# you can pull in the arrayref of hashrefs that's written out
#my $recovered = eval $output;

sub wanted {
    my $type = $_;
    return if $type eq '.';
    $type =~ s/\.pm$//;
    my $class = "HTML::FormHandler::I18N::$type";
    if( try_load_class( $class ) ) {
        push @lexicons, $type;
        print "$type\n";
    }
    else {
        print "did not load $type\n";
    }

}