File: check_po.pl

package info (click to toggle)
apparmor 2.7.103-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,920 kB
  • sloc: ansic: 12,022; perl: 10,644; sh: 8,119; cpp: 2,505; yacc: 1,592; python: 1,489; makefile: 1,138; lex: 1,003; pascal: 399; ruby: 374; exp: 250; java: 212; xml: 159
file content (54 lines) | stat: -rwxr-xr-x 1,523 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl

# Look in the po directory and check the files for missing shortcuts - where the
# msgid has a string "(B)lah" and the msgstr contains no character surrounded by
# parens

use Data::Dumper;

my $dir = "./po";

opendir(PODIR, $dir) || die "Can't open  directory $dir.";
my $errors = {};
for my $file (grep { /.*\.po$/ && -f "$dir/$_" } readdir(PODIR)) {
    #print STDOUT "Processing $file\n";
    check_po_for_shortcuts( "$dir/$file", $errors );
    
}
my $msg = Data::Dumper->Dump([$errors], [qw(*ERRORS)]);
my $count = 0;
for my $f ( keys %$errors ) {
   for my $err ( keys %{$errors->{$f}} ) {
       $count++;
   }
} 
print STDOUT "$count missing shortcuts in the po files\n.$msg\n";
closedir(PODIR);


sub check_po_for_shortcuts {
    my ($filename, $errors)  = @_;
    my $line = 0;
    if (open(PO, "$filename")) {
        while (<PO>) {
            $line++;
            chomp;
            if ( /^.*msgid.*\(\w{1}?\)*/ ) {
              $looking_for_msgstr = 1;
              $msgid = $_;
            } 
            if ( /^.*msgstr*/ && $looking_for_msgstr ) {
                unless (/^.*msgstr.*\(\w{1}?\)*/) {
                    $errors->{$filename}{$line} =  {
                                             "msgid" => $msgid,
                                             "msgstr" => $_,
                                            };
                }
                $msgid = "";
                $looking_for_msgstr = 0;
             } 
        }
        close(PO);
    }
    return $config;
}