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);
35 my $po_dir = tempdir
(CLEANUP
=> 1);
38 my $opac_dir = 'koha-tmpl/opac-tmpl';
39 opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
40 my @opac_themes = grep { not /^\.|lib|js|xslt/ } readdir($dh);
44 my $staff_dir = 'koha-tmpl/intranet-tmpl';
45 opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
46 my @staff_themes = grep { not /^\.|lib|js/ } readdir($dh);
49 chdir "misc/translator"; # for now, tmpl_process3.pl works only if run from its directory
51 # Check translatable of OPAC themes
52 for my $theme ( @opac_themes ) {
53 test_string_extraction
("opac_$theme", "../../koha-tmpl/opac-tmpl/$theme/en", $po_dir);
56 # Check translatable of STAFF themes
57 for my $theme ( @staff_themes ) {
58 test_string_extraction
("staff_$theme", "../../koha-tmpl/intranet-tmpl/$theme/en", $po_dir);
61 sub test_string_extraction
{
63 my $template_dir = shift;
66 my $command = "./tmpl_process3.pl create -i $template_dir -s $po_dir/$module.po -r --pedantic-warnings";
68 open (NULL
, ">", File
::Spec
->devnull);
69 print NULL
"foo"; # avoid warning;
70 my $pid = open3
(gensym
, ">&NULL", \
*PH
, $command);
73 # ignore some noise on STDERR
74 # the output of msmerge, that consist in .... followed by a "done" (localized), followed by a .
75 # The "done" localized can include diacritics, so ignoring the whole word
76 # FIXME PP: the flow is not correct UTF8, testing \p{IsLetter} does not work, but I think this regexp will do the job
77 next if (/^\.+ .*\.$/);
78 # other Koha-specific catses that should not worry us
79 next if /^Warning: Can't determine original templates' charset/;
80 next if /^Warning: Charset Out defaulting to/;
81 next if /^Removing empty file /;
82 next if /^I UTF-8 O UTF-8 at /;
87 ok
($#warnings == -1, "$module templates are translatable") or diag
join("\n", @warnings, '');