|
Lines 1-94
Link Here
|
| 1 |
#!/usr/bin/perl |
|
|
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
=head2 translate-templates.t |
| 20 |
|
| 21 |
This test verifies that all staff and OPAC template |
| 22 |
files can be processed by the string extractor |
| 23 |
without error; such errors usually indicate a |
| 24 |
construct that the extractor cannot parse. |
| 25 |
|
| 26 |
=cut |
| 27 |
|
| 28 |
use Test::More; |
| 29 |
use File::Temp qw/tempdir/; |
| 30 |
use IPC::Open3; |
| 31 |
use File::Spec; |
| 32 |
use Symbol qw(gensym); |
| 33 |
use FindBin qw($Bin); |
| 34 |
use Cwd qw(abs_path); |
| 35 |
use utf8; |
| 36 |
|
| 37 |
my $po_dir = tempdir(CLEANUP => 1); |
| 38 |
|
| 39 |
# Find OPAC themes |
| 40 |
my $opac_dir = 'koha-tmpl/opac-tmpl'; |
| 41 |
opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; |
| 42 |
my @opac_themes = grep { not /^\.|lib|js|xslt/ } readdir($dh); |
| 43 |
close $dh; |
| 44 |
|
| 45 |
# Find STAFF themes |
| 46 |
my $staff_dir = 'koha-tmpl/intranet-tmpl'; |
| 47 |
opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; |
| 48 |
my @staff_themes = grep { not /^\.|lib|js/ } readdir($dh); |
| 49 |
close $dh; |
| 50 |
|
| 51 |
my $misc_translator_dir = abs_path("$Bin/../../misc/translator"); |
| 52 |
|
| 53 |
chdir $misc_translator_dir; # for now, tmpl_process3.pl works only if run from its directory |
| 54 |
|
| 55 |
# Check translatable of OPAC themes |
| 56 |
for my $theme ( @opac_themes ) { |
| 57 |
test_string_extraction("opac_$theme", "../../koha-tmpl/opac-tmpl/$theme/en", $po_dir); |
| 58 |
} |
| 59 |
|
| 60 |
# Check translatable of STAFF themes |
| 61 |
for my $theme ( @staff_themes ) { |
| 62 |
test_string_extraction("staff_$theme", "../../koha-tmpl/intranet-tmpl/$theme/en", $po_dir); |
| 63 |
} |
| 64 |
|
| 65 |
sub test_string_extraction { |
| 66 |
my $module = shift; |
| 67 |
my $template_dir = shift; |
| 68 |
my $po_dir = shift; |
| 69 |
|
| 70 |
my $command = "PERL5LIB=\$PERL5LIB:$misc_translator_dir ./tmpl_process3.pl create -i $template_dir -s $po_dir/$module.po -r --pedantic-warnings"; |
| 71 |
|
| 72 |
open (NULL, ">", File::Spec->devnull); ## no critic (BarewordFileHandles) |
| 73 |
print NULL "foo"; # avoid warning; |
| 74 |
my $pid = open3(gensym, ">&NULL", \*PH, $command); |
| 75 |
my @warnings; |
| 76 |
while (<PH>) { |
| 77 |
# ignore some noise on STDERR |
| 78 |
# the output of msmerge, that consist in .... followed by a "done" (localized), followed by a . |
| 79 |
# The "done" localized can include diacritics, so ignoring the whole word |
| 80 |
# FIXME PP: the flow is not correct UTF8, testing \p{IsLetter} does not work, but I think this regexp will do the job |
| 81 |
next if (/^\.+ .*\.$/); |
| 82 |
# other Koha-specific catses that should not worry us |
| 83 |
next if /^Warning: Can't determine original templates' charset/; |
| 84 |
next if /^Warning: Charset Out defaulting to/; |
| 85 |
next if /^Removing empty file /; |
| 86 |
next if /^I UTF-8 O UTF-8 at /; |
| 87 |
push @warnings, $_; |
| 88 |
} |
| 89 |
waitpid($pid, 0); |
| 90 |
|
| 91 |
ok($#warnings == -1, "$module templates are translatable") or diag join("\n", @warnings, ''); |
| 92 |
} |
| 93 |
|
| 94 |
done_testing(); |
| 95 |
- |