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('intrahtdocs', "$Bin/LangInstaller/templates");
19 my @files = ('simple.tt');
20 $installer->extract_messages_from_templates($tempdir, 'intranet', @files);
22 my $tempfile = "$tempdir/koha-tmpl/intranet-tmpl/simple.tt";
23 ok(-e $tempfile, 'it has created a temporary file simple.tt');
25 skip "simple.tt does not exist", 37 unless -e $tempfile;
27 my $output = read_file($tempfile);
28 my $expected_output = <<'EOF';
32 __nx('{count} item', '{count} items');
33 __p('context', 'hello');
34 __px('context', 'hello {name}');
35 __np('context', 'item', 'items');
36 __npx('context', '{count} item', '{count} items');
37 __npx('context', '{count} item', '{count} items');
38 __x('status is {status}');
44 is($output, $expected_output, "Output of extract_messages_from_templates is as expected");
46 my $xgettext_cmd = "xgettext -L Perl --from-code=UTF-8 "
47 . "--package-name=Koha --package-version='' "
48 . "-k -k__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -k__p:1c,2 "
49 . "-k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 "
50 . "-o $tempdir/Koha.pot -D $tempdir koha-tmpl/intranet-tmpl/simple.tt";
52 system($xgettext_cmd);
53 my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot");
60 msgid => '"hello {name}"',
64 msgid_plural => '"items"',
67 msgid => '"{count} item"',
68 msgid_plural => '"{count} items"',
72 msgctxt => '"context"',
75 msgid => '"hello {name}"',
76 msgctxt => '"context"',
80 msgid_plural => '"items"',
81 msgctxt => '"context"',
84 msgid => '"{count} item"',
85 msgid_plural => '"{count} items"',
86 msgctxt => '"context"',
89 msgid => '"status is {status}"',
95 msgid => '"inactive"',
98 msgid => '"Inside block"',
102 for (my $i = 0; $i < @expected; $i++) {
103 for my $key (qw(msgid msgid_plural msgctxt)) {
104 my $expected = $expected[$i]->{$key};
105 my $expected_str = defined $expected ? $expected : 'not defined';
106 is($pot->[$i + 1]->$key, $expected, "$i: $key is $expected_str");