3 # This file is part of Koha.
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.
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.
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>.
19 =head2 translate-templates.t
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.
29 use File
::Temp qw
/tempdir/;
32 use Symbol
qw(gensym);
37 my $po_dir = tempdir
(CLEANUP
=> 1);
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);
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);
51 my $misc_translator_dir = abs_path
("$Bin/../../misc/translator");
53 chdir $misc_translator_dir; # for now, tmpl_process3.pl works only if run from its directory
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);
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);
65 sub test_string_extraction
{
67 my $template_dir = shift;
70 my $command = "PERL5LIB=\$PERL5LIB:$misc_translator_dir ./tmpl_process3.pl create -i $template_dir -s $po_dir/$module.po -r --pedantic-warnings";
72 open (NULL
, ">", File
::Spec
->devnull); ## no critic (BarewordFileHandles)
73 print NULL
"foo"; # avoid warning;
74 my $pid = open3
(gensym
, ">&NULL", \
*PH
, $command);
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 /;
91 ok
($#warnings == -1, "$module templates are translatable") or diag
join("\n", @warnings, '');