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>.
21 =head2 translate-templates.t
23 This test verifies that all staff and OPAC template
24 files can be processed by the string extractor
25 without error; such errors usually indicate a
26 construct that the extractor cannot parse.
31 use File
::Temp qw
/tempdir/;
34 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/ } 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 chdir "misc/translator"; # for now, tmpl_process3.pl works only if run from its directory
53 # Check translatable of OPAC themes
54 for my $theme ( @opac_themes ) {
55 test_string_extraction
("opac_$theme", "../../koha-tmpl/opac-tmpl/$theme/en", $po_dir);
58 # Check translatable of STAFF themes
59 for my $theme ( @staff_themes ) {
60 test_string_extraction
("staff_$theme", "../../koha-tmpl/intranet-tmpl/$theme/en", $po_dir);
63 sub test_string_extraction
{
65 my $template_dir = shift;
68 my $command = "./tmpl_process3.pl create -i $template_dir -s $po_dir/$module.po -r --pedantic-warnings";
70 open (NULL
, ">", File
::Spec
->devnull);
71 print NULL
"foo"; # avoid warning;
72 my $pid = open3
(gensym
, ">&NULL", \
*PH
, $command);
75 # ignore some noise on STDERR
76 # the output of msmerge, that consist in .... followed by a "done" (localized), followed by a .
77 # The "done" localized can include diacritics, so ignoring the whole word
78 # FIXME PP: the flow is not correct UTF8, testing \p{IsLetter} does not work, but I think this regexp will do the job
79 next if (/^\.+ .*\.$/);
80 # other Koha-specific catses that should not worry us
81 next if /^Warning: Can't determine original templates' charset/;
82 next if /^Warning: Charset Out defaulting to/;
83 next if /^Removing empty file /;
84 next if /^I UTF-8 O UTF-8 at /;
89 ok
($#warnings == -1, "$module templates are translatable") or diag
join("\n", @warnings, '');