View | Details | Raw Unified | Return to bug 39130
Collapse All | Expand All

(-)a/t/db_dependent/misc/translator/sample-not-working.tt (+3 lines)
Line 0 Link Here
1
<p>The whole file won't be translatable because of the following line:</p>
2
<span [% IF 0 > 1 %]title="Don't use > in TT directives that are inside HTML tags"></span>
3
<p>Still not translatable</p>
(-)a/t/db_dependent/misc/translator/sample.tt (+9 lines)
Lines 34-36 Link Here
34
[% BLOCK %]
34
[% BLOCK %]
35
    [% t('Inside block') | $raw %]
35
    [% t('Inside block') | $raw %]
36
[% END %]
36
[% END %]
37
38
<span>This should be picked by xgettext.pl</span>
39
40
<img alt="alt text">
41
42
<option [% IF value = expected %]selected[% END %] title="foo title" value="foo">Foo</option>
43
44
<span [% IF show_title %]title="this is not translatable (known bug)"[% END %]></span>
45
<span [% IF show_title %] title="but this is (thanks to space before attribute name)"[% END %]></span>
(-)a/t/db_dependent/misc/translator/xgettext.pl.t (-1 / +64 lines)
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' );

Return to bug 39130