Koha/t/LangInstaller.t
Julian Maurice bd81f0418c Bug 21895: Fix translation for package install
The string extraction process was not taking into account the fact that
standard/package install have a completely different directory structure
than the dev install

This patch tries to keep the exact same behaviour for dev installs,
while making it work for standard install by using opachtdocs,
intrahtdocs, opacdir and intranetdir from $KOHA_CONF

Test plan:
1. Follow test plan in
d708255c7a
2. Do a standard install and repeat step 1 on this new install
3. If you know how to build the Debian package, build it, install it and
verify that koha-translate works as expected
4. prove t/LangInstaller.t

Signed-off-by: Mirko Tietgen <mirko@abunchofthings.net>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2018-11-29 17:57:54 +00:00

109 lines
2.9 KiB
Perl

use Modern::Perl;
use FindBin '$Bin';
use lib "$Bin/../misc/translator";
use Test::More tests => 39;
use File::Temp qw(tempdir);
use File::Slurp;
use Locale::PO;
use t::lib::Mocks;
use_ok('LangInstaller');
my $installer = LangInstaller->new();
my $tempdir = tempdir(CLEANUP => 0);
t::lib::Mocks::mock_config('intrahtdocs', "$Bin/LangInstaller/templates");
my @files = ('simple.tt');
$installer->extract_messages_from_templates($tempdir, 'intranet', @files);
my $tempfile = "$tempdir/koha-tmpl/intranet-tmpl/simple.tt";
ok(-e $tempfile, 'it has created a temporary file simple.tt');
SKIP: {
skip "simple.tt does not exist", 37 unless -e $tempfile;
my $output = read_file($tempfile);
my $expected_output = <<'EOF';
__('hello');
__x('hello {name}');
__n('item', 'items');
__nx('{count} item', '{count} items');
__p('context', 'hello');
__px('context', 'hello {name}');
__np('context', 'item', 'items');
__npx('context', '{count} item', '{count} items');
__npx('context', '{count} item', '{count} items');
__x('status is {status}');
__('active');
__('inactive');
__('Inside block');
EOF
is($output, $expected_output, "Output of extract_messages_from_templates is as expected");
my $xgettext_cmd = "xgettext -L Perl --from-code=UTF-8 "
. "--package-name=Koha --package-version='' "
. "-k -k__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -k__p:1c,2 "
. "-k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 "
. "-o $tempdir/Koha.pot -D $tempdir koha-tmpl/intranet-tmpl/simple.tt";
system($xgettext_cmd);
my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot");
my @expected = (
{
msgid => '"hello"',
},
{
msgid => '"hello {name}"',
},
{
msgid => '"item"',
msgid_plural => '"items"',
},
{
msgid => '"{count} item"',
msgid_plural => '"{count} items"',
},
{
msgid => '"hello"',
msgctxt => '"context"',
},
{
msgid => '"hello {name}"',
msgctxt => '"context"',
},
{
msgid => '"item"',
msgid_plural => '"items"',
msgctxt => '"context"',
},
{
msgid => '"{count} item"',
msgid_plural => '"{count} items"',
msgctxt => '"context"',
},
{
msgid => '"status is {status}"',
},
{
msgid => '"active"',
},
{
msgid => '"inactive"',
},
{
msgid => '"Inside block"',
},
);
for (my $i = 0; $i < @expected; $i++) {
for my $key (qw(msgid msgid_plural msgctxt)) {
my $expected = $expected[$i]->{$key};
my $expected_str = defined $expected ? $expected : 'not defined';
is($pot->[$i + 1]->$key, $expected, "$i: $key is $expected_str");
}
}
}