line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Locale::PO; |
2
|
|
|
|
|
|
|
# ABSTRACT: check PO files for empty/fuzzy translations |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
19966
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
100
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.02'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
10
|
use base 'Test::Builder::Module'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1150
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT = qw( po_file_ok ); |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
2662
|
use Locale::PO; |
|
2
|
|
|
|
|
9299
|
|
|
2
|
|
|
|
|
922
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $CLASS = __PACKAGE__; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub po_file_ok { |
17
|
5
|
|
|
5
|
1
|
3217
|
my $file = shift; |
18
|
5
|
|
|
|
|
19
|
my $opts = { empty => 1, fuzzy => 1, @_ }; |
19
|
5
|
|
|
|
|
26
|
my $tb = $CLASS->builder; |
20
|
|
|
|
|
|
|
|
21
|
5
|
50
|
|
|
|
133
|
if( ! -f $file ) { |
22
|
0
|
|
|
|
|
0
|
$tb->ok(0, $file.' does not exist!'); |
23
|
0
|
|
|
|
|
0
|
return; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
5
|
|
|
|
|
7
|
my $content; |
27
|
5
|
|
|
|
|
6
|
eval { |
28
|
5
|
|
|
|
|
23
|
$content = Locale::PO->load_file_asarray( $file ); |
29
|
|
|
|
|
|
|
}; |
30
|
5
|
50
|
|
|
|
3574
|
if( $@ ) { |
31
|
0
|
|
|
|
|
0
|
$tb->ok(0, 'could not load PO file!'); |
32
|
0
|
|
|
|
|
0
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
5
|
50
|
|
|
|
15
|
if( scalar(@$content) == 0 ) { |
35
|
0
|
|
|
|
|
0
|
$tb->ok(0, 'PO file has no entries!'); |
36
|
0
|
|
|
|
|
0
|
return; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
5
|
|
|
|
|
8
|
my @no_msgstr; |
40
|
|
|
|
|
|
|
my @fuzzy; |
41
|
5
|
|
|
|
|
11
|
foreach my $po ( @$content ) { |
42
|
20
|
100
|
|
|
|
180
|
if( $opts->{'empty'} ) { |
43
|
|
|
|
|
|
|
# check for a simple translation |
44
|
16
|
100
|
66
|
|
|
37
|
if ( defined $po->msgstr && $po->msgstr !~ m/^["\- ]*$/ ) { |
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
# check if plurals are involved |
47
|
|
|
|
|
|
|
elsif( defined $po->msgid_plural |
48
|
|
|
|
|
|
|
&& defined $po->msgstr_n->{"0"} |
49
|
|
|
|
|
|
|
&& $po->msgstr_n->{"0"} !~ m/^["\- ]*$/ ) { |
50
|
|
|
|
|
|
|
} else { |
51
|
1
|
|
|
|
|
29
|
push( @no_msgstr, $po ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
20
|
100
|
100
|
|
|
323
|
if( $opts->{'fuzzy'} && $po->has_flag('fuzzy') ) { |
55
|
1
|
|
|
|
|
13
|
push( @fuzzy, $po ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
5
|
100
|
100
|
|
|
60
|
if( scalar(@no_msgstr) != 0 || scalar(@fuzzy) != 0 ) { |
60
|
2
|
|
|
|
|
11
|
$tb->ok(0, 'check PO file '.$file.' for errors'); |
61
|
2
|
|
|
|
|
1034
|
foreach my $po ( @no_msgstr ) { |
62
|
1
|
|
|
|
|
4
|
$tb->diag('no translation for '.$po->msgid.' on line '.$po->loaded_line_number); |
63
|
|
|
|
|
|
|
} |
64
|
2
|
|
|
|
|
85
|
foreach my $po ( @fuzzy ) { |
65
|
1
|
|
|
|
|
5
|
$tb->diag('fuzzy translation for '.$po->msgid.' on line '.$po->loaded_line_number); |
66
|
|
|
|
|
|
|
} |
67
|
2
|
|
|
|
|
87
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
17
|
$tb->ok(1, 'PO file '.$file.' is okay'); |
71
|
3
|
|
|
|
|
864
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |