| 1 | package Test::Locale::PO; | ||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: check PO files for empty/fuzzy translations | ||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '1.02'; # VERSION | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base 'Test::Builder::Module'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||
| 10 | 2 | our @EXPORT = qw( po_file_ok ); | |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Locale::PO; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||
| 14 | 2 | my $CLASS = __PACKAGE__; | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 5 | ▶ | sub po_file_ok { | ||||||||||||||||||||||||||||||||
|
Subroutine
po_file_ok: called CC=17 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 17 | 5 | my $file = shift; | |||||||||||||||||||||||||||||||||
| 18 | 5 | my $opts = { empty => 1, fuzzy => 1, @_ }; | |||||||||||||||||||||||||||||||||
| 19 | 5 | my $tb = $CLASS->builder; | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 5 | ▶ | if( ! -f $file ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 22 | 0 | $tb->ok(0, $file.' does not exist!'); | |||||||||||||||||||||||||||||||||
| 23 | 0 | return; | |||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 5 | my $content; | |||||||||||||||||||||||||||||||||
| 27 | 5 | eval { | |||||||||||||||||||||||||||||||||
| 28 | 5 | $content = Locale::PO->load_file_asarray( $file ); | |||||||||||||||||||||||||||||||||
| 29 | }; | ||||||||||||||||||||||||||||||||||
| 30 | 5 | ▶ | if( $@ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | 0 | $tb->ok(0, 'could not load PO file!'); | |||||||||||||||||||||||||||||||||
| 32 | 0 | return; | |||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | if( scalar(@$content) == 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | 0 | $tb->ok(0, 'PO file has no entries!'); | |||||||||||||||||||||||||||||||||
| 36 | 0 | return; | |||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | 5 | my @no_msgstr; | |||||||||||||||||||||||||||||||||
| 40 | my @fuzzy; | ||||||||||||||||||||||||||||||||||
| 41 | 5 | foreach my $po ( @$content ) { | |||||||||||||||||||||||||||||||||
| 42 | 20 | ▶ | if( $opts->{'empty'} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 43 | # check for a simple translation | ||||||||||||||||||||||||||||||||||
| 44 | 16 | ▶ | if ( defined $po->msgstr && $po->msgstr !~ m/^["\- ]*$/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
defined $po->msgstr and not $po->msgstr =~ /^["\- ]*$/
MC/DC50%1/2
defined $po->msgstr and not $po->msgstr =~ /^["\- ]*$/
defined $po->msgstr
not $po->msgstr =~ /^["\- ]*$/
Truth table66%2/3
A and not(B)
A= defined $po->msgstrB= not $po->msgstr =~ /^["\- ]*$/
| |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | # check if plurals are involved | ||||||||||||||||||||||||||||||||||
| 47 | ▶ | elsif( defined $po->msgid_plural | |||||||||||||||||||||||||||||||||
|
Condition33%2/6
defined $po->msgid_plural and defined $po->msgstr_n->{0} and not $po->msgstr_n->{0} =~ /^["\- ]*$/
defined $po->msgid_plural and defined $po->msgstr_n->{0}
MC/DC0%0/3
defined $po->msgid_plural and defined $po->msgstr_n->{0} and not $po->msgstr_n->{0} =~ /^["\- ]*$/
defined $po->msgid_plural
defined $po->msgstr_n->{0}
not $po->msgstr_n->{0} =~ /^["\- ]*$/
Truth table25%1/4
A and B and not(C)
A= defined $po->msgid_pluralB= defined $po->msgstr_n->{0}C= not $po->msgstr_n->{0} =~ /^["\- ]*$/
| |||||||||||||||||||||||||||||||||||
| 48 | && defined $po->msgstr_n->{"0"} | ||||||||||||||||||||||||||||||||||
| 49 | && $po->msgstr_n->{"0"} !~ m/^["\- ]*$/ ) { | ||||||||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||||||||
| 51 | 1 | push( @no_msgstr, $po ); | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | if( $opts->{'fuzzy'} && $po->has_flag('fuzzy') ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts->{"fuzzy"} and $po->has_flag("fuzzy")
MC/DC100%2/2
$opts->{"fuzzy"} and $po->has_flag("fuzzy")
$opts->{"fuzzy"}
$po->has_flag("fuzzy")
Truth table100%3/3
A and B
A= $opts->{"fuzzy"}B= $po->has_flag("fuzzy")
| |||||||||||||||||||||||||||||||||||
| 55 | 1 | push( @fuzzy, $po ); | |||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||
| 59 | 5 | ▶ | if( scalar(@no_msgstr) != 0 || scalar(@fuzzy) != 0 ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
scalar @no_msgstr != 0 or scalar @fuzzy != 0
MC/DC100%2/2
scalar @no_msgstr != 0 or scalar @fuzzy != 0
scalar @no_msgstr != 0
scalar @fuzzy != 0
Truth table100%3/3
A or B
A= scalar @no_msgstr != 0B= scalar @fuzzy != 0
| |||||||||||||||||||||||||||||||||||
| 60 | 2 | $tb->ok(0, 'check PO file '.$file.' for errors'); | |||||||||||||||||||||||||||||||||
| 61 | 2 | foreach my $po ( @no_msgstr ) { | |||||||||||||||||||||||||||||||||
| 62 | 1 | $tb->diag('no translation for '.$po->msgid.' on line '.$po->loaded_line_number); | |||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||
| 64 | 2 | foreach my $po ( @fuzzy ) { | |||||||||||||||||||||||||||||||||
| 65 | 1 | $tb->diag('fuzzy translation for '.$po->msgid.' on line '.$po->loaded_line_number); | |||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | 2 | return; | |||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 3 | $tb->ok(1, 'PO file '.$file.' is okay'); | |||||||||||||||||||||||||||||||||
| 71 | 3 | return; | |||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||||||||