4 use lib "$Bin/../misc/translator";
6 use Test::More tests => 39;
7 use File::Temp qw(tempdir);
13 use_ok('LangInstaller');
15 my $installer = LangInstaller->new();
17 my $tempdir = tempdir(CLEANUP => 0);
18 t::lib::Mocks::mock_config('intranetdir', "$Bin/LangInstaller/templates");
19 my @files = ('simple.tt');
20 $installer->extract_messages_from_templates($tempdir, @files);
22 ok(-e "$tempdir/simple.tt", 'it has created a temporary file simple.tt');
24 skip "simple.tt does not exist", 37 unless -e "$tempdir/simple.tt";
26 my $output = read_file("$tempdir/simple.tt");
27 my $expected_output = <<'EOF';
31 __nx('{count} item', '{count} items');
32 __p('context', 'hello');
33 __px('context', 'hello {name}');
34 __np('context', 'item', 'items');
35 __npx('context', '{count} item', '{count} items');
36 __npx('context', '{count} item', '{count} items');
37 __x('status is {status}');
43 is($output, $expected_output, "Output of extract_messages_from_templates is as expected");
45 my $xgettext_cmd = "xgettext -L Perl --from-code=UTF-8 "
46 . "--package-name=Koha --package-version='' "
47 . "-k -k__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -k__p:1c,2 "
48 . "-k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 "
49 . "-o $tempdir/Koha.pot -D $tempdir simple.tt";
51 system($xgettext_cmd);
52 my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot");
59 msgid => '"hello {name}"',
63 msgid_plural => '"items"',
66 msgid => '"{count} item"',
67 msgid_plural => '"{count} items"',
71 msgctxt => '"context"',
74 msgid => '"hello {name}"',
75 msgctxt => '"context"',
79 msgid_plural => '"items"',
80 msgctxt => '"context"',
83 msgid => '"{count} item"',
84 msgid_plural => '"{count} items"',
85 msgctxt => '"context"',
88 msgid => '"status is {status}"',
94 msgid => '"inactive"',
97 msgid => '"Inside block"',
101 for (my $i = 0; $i < @expected; $i++) {
102 for my $key (qw(msgid msgid_plural msgctxt)) {
103 my $expected = $expected[$i]->{$key};
104 my $expected_str = defined $expected ? $expected : 'not defined';
105 is($pot->[$i + 1]->$key, $expected, "$i: $key is $expected_str");