|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
use Modern::Perl; |
| 4 |
|
| 5 |
use File::Slurp; |
| 6 |
use File::Temp qw(tempdir); |
| 7 |
use FindBin qw($Bin); |
| 8 |
use Locale::PO; |
| 9 |
use Test::More tests => 20; |
| 10 |
|
| 11 |
my $tempdir = tempdir( CLEANUP => 1 ); |
| 12 |
|
| 13 |
write_file( "$tempdir/files", "$Bin/sample.tt" ); |
| 14 |
|
| 15 |
my $xgettext_cmd = "$Bin/../../../../misc/translator/xgettext.pl -o $tempdir/Koha.pot -f $tempdir/files"; |
| 16 |
|
| 17 |
system($xgettext_cmd); |
| 18 |
system("msgcat -o $tempdir/Koha.sorted.pot -s $tempdir/Koha.pot"); |
| 19 |
my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.sorted.pot"); |
| 20 |
|
| 21 |
my @expected = ( |
| 22 |
{ |
| 23 |
msgid => |
| 24 |
'"%s %s %s %s %s %s %s %s %s %s [%% # it also works on multiple lines tnpx ( \'context\', \'{count} item\', \'{count} items\', count, { count = count, } ) | $raw %%] [%% # and t* calls can be nested tx(\'status is {status}\', { status = active ? t(\'active\') : t(\'inactive\') }) | $raw %%] [%%# but a TT comment won\'t get picked t(\'not translatable\') %%] %s %s %s "', |
| 25 |
}, |
| 26 |
{ |
| 27 |
msgid => '"Foo"', |
| 28 |
}, |
| 29 |
{ |
| 30 |
msgid => '"This should be picked by xgettext.pl"', |
| 31 |
}, |
| 32 |
{ |
| 33 |
msgid => '"alt text"', |
| 34 |
}, |
| 35 |
{ |
| 36 |
msgid => '"but this is (thanks to space before attribute name)"', |
| 37 |
}, |
| 38 |
{ |
| 39 |
msgid => '"foo title"', |
| 40 |
}, |
| 41 |
); |
| 42 |
|
| 43 |
for ( my $i = 0 ; $i < @expected ; $i++ ) { |
| 44 |
for my $key (qw(msgid msgid_plural msgctxt)) { |
| 45 |
my $expected = $expected[$i]->{$key}; |
| 46 |
my $expected_str = defined $expected ? $expected : 'not defined'; |
| 47 |
my $msg = $pot->[ $i + 1 ]; |
| 48 |
if ($msg) { |
| 49 |
is( $msg->$key, $expected, "$i: $key is $expected_str" ); |
| 50 |
} else { |
| 51 |
fail("$i: $key is $expected_str (no corresponding message in POT)"); |
| 52 |
} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
is( scalar @$pot, 1 + scalar(@expected) ); |
| 57 |
|
| 58 |
write_file( "$tempdir/files", "$Bin/sample-not-working.tt" ); |
| 59 |
|
| 60 |
$xgettext_cmd = "$Bin/../../../../misc/translator/xgettext.pl -o $tempdir/Koha.pot -f $tempdir/files 2>/dev/null"; |
| 61 |
|
| 62 |
system($xgettext_cmd); |
| 63 |
$pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot"); |
| 64 |
is( scalar @$pot, 0, 'xgettext.pl failed to generate a POT file because of incorrect structure' ); |