Lines 29-34
use File::Basename;
Link Here
|
29 |
use File::Find; |
29 |
use File::Find; |
30 |
use File::Path qw( make_path ); |
30 |
use File::Path qw( make_path ); |
31 |
use File::Slurp; |
31 |
use File::Slurp; |
|
|
32 |
use File::Spec; |
32 |
use File::Temp qw( tempdir ); |
33 |
use File::Temp qw( tempdir ); |
33 |
use Template::Parser; |
34 |
use Template::Parser; |
34 |
use PPI; |
35 |
use PPI; |
Lines 518-532
sub update_messages {
Link Here
|
518 |
} |
519 |
} |
519 |
|
520 |
|
520 |
sub extract_messages_from_templates { |
521 |
sub extract_messages_from_templates { |
521 |
my ($self, $tempdir, @files) = @_; |
522 |
my ($self, $tempdir, $type, @files) = @_; |
522 |
|
523 |
|
523 |
my $intranetdir = $self->{context}->config('intranetdir'); |
524 |
my $htdocs = $type eq 'intranet' ? 'intrahtdocs' : 'opachtdocs'; |
|
|
525 |
my $dir = $self->{context}->config($htdocs); |
524 |
my @keywords = qw(t tx tn txn tnx tp tpx tnp tnpx); |
526 |
my @keywords = qw(t tx tn txn tnx tp tpx tnp tnpx); |
525 |
my $parser = Template::Parser->new(); |
527 |
my $parser = Template::Parser->new(); |
526 |
|
528 |
|
527 |
foreach my $file (@files) { |
529 |
foreach my $file (@files) { |
528 |
say "Extract messages from $file" if $self->{verbose}; |
530 |
say "Extract messages from $file" if $self->{verbose}; |
529 |
my $template = read_file("$intranetdir/$file"); |
531 |
my $template = read_file(File::Spec->catfile($dir, $file)); |
530 |
|
532 |
|
531 |
# No need to process a file that doesn't use the i18n.inc file. |
533 |
# No need to process a file that doesn't use the i18n.inc file. |
532 |
next unless $template =~ /i18n\.inc/; |
534 |
next unless $template =~ /i18n\.inc/; |
Lines 537-544
sub extract_messages_from_templates {
Link Here
|
537 |
next; |
539 |
next; |
538 |
} |
540 |
} |
539 |
|
541 |
|
540 |
make_path(dirname("$tempdir/$file")); |
542 |
my $destfile = $type eq 'intranet' ? |
541 |
open my $fh, '>', "$tempdir/$file"; |
543 |
File::Spec->catfile($tempdir, 'koha-tmpl', 'intranet-tmpl', $file) : |
|
|
544 |
File::Spec->catfile($tempdir, 'koha-tmpl', 'opac-tmpl', $file); |
545 |
|
546 |
make_path(dirname($destfile)); |
547 |
open my $fh, '>', $destfile; |
542 |
|
548 |
|
543 |
my @blocks = ($data->{BLOCK}, values %{ $data->{DEFBLOCKS} }); |
549 |
my @blocks = ($data->{BLOCK}, values %{ $data->{DEFBLOCKS} }); |
544 |
foreach my $block (@blocks) { |
550 |
foreach my $block (@blocks) { |
Lines 605-639
sub extract_messages {
Link Here
|
605 |
say "Extract messages into POT file" if $self->{verbose}; |
611 |
say "Extract messages into POT file" if $self->{verbose}; |
606 |
|
612 |
|
607 |
my $intranetdir = $self->{context}->config('intranetdir'); |
613 |
my $intranetdir = $self->{context}->config('intranetdir'); |
|
|
614 |
my $opacdir = $self->{context}->config('opacdir'); |
615 |
|
616 |
# Find common ancestor directory |
617 |
my @intranetdirs = File::Spec->splitdir($intranetdir); |
618 |
my @opacdirs = File::Spec->splitdir($opacdir); |
619 |
my @basedirs; |
620 |
while (@intranetdirs and @opacdirs) { |
621 |
my ($dir1, $dir2) = (shift @intranetdirs, shift @opacdirs); |
622 |
last if $dir1 ne $dir2; |
623 |
push @basedirs, $dir1; |
624 |
} |
625 |
my $basedir = File::Spec->catdir(@basedirs); |
626 |
|
608 |
my @files_to_scan; |
627 |
my @files_to_scan; |
609 |
my @directories_to_scan = ('.'); |
628 |
my @directories_to_scan = ('.'); |
610 |
my @blacklist = qw(blib koha-tmpl skel tmp t); |
629 |
my @blacklist = map { File::Spec->catdir(@intranetdirs, $_) } qw(blib koha-tmpl skel tmp t); |
611 |
while (@directories_to_scan) { |
630 |
while (@directories_to_scan) { |
612 |
my $dir = shift @directories_to_scan; |
631 |
my $dir = shift @directories_to_scan; |
613 |
opendir DIR, "$intranetdir/$dir" or die "Unable to open $dir: $!"; |
632 |
opendir DIR, File::Spec->catdir($basedir, $dir) or die "Unable to open $dir: $!"; |
614 |
foreach my $entry (readdir DIR) { |
633 |
foreach my $entry (readdir DIR) { |
615 |
next if $entry =~ /^\./; |
634 |
next if $entry =~ /^\./; |
616 |
my $relentry = "$dir/$entry"; |
635 |
my $relentry = File::Spec->catfile($dir, $entry); |
617 |
$relentry =~ s|^\./||; |
636 |
my $abspath = File::Spec->catfile($basedir, $relentry); |
618 |
if (-d "$intranetdir/$relentry" and not grep /^$relentry$/, @blacklist) { |
637 |
if (-d $abspath and not grep /^$relentry$/, @blacklist) { |
619 |
push @directories_to_scan, "$relentry"; |
638 |
push @directories_to_scan, $relentry; |
620 |
} elsif (-f "$intranetdir/$relentry" and $relentry =~ /(pl|pm)$/) { |
639 |
} elsif (-f $abspath and $relentry =~ /\.(pl|pm)$/) { |
621 |
push @files_to_scan, "$relentry"; |
640 |
push @files_to_scan, $relentry; |
622 |
} |
641 |
} |
623 |
} |
642 |
} |
624 |
} |
643 |
} |
625 |
|
644 |
|
626 |
my @tt_files; |
645 |
my $intrahtdocs = $self->{context}->config('intrahtdocs'); |
|
|
646 |
my $opachtdocs = $self->{context}->config('opachtdocs'); |
647 |
|
648 |
my @intranet_tt_files; |
649 |
find(sub { |
650 |
if ($File::Find::dir =~ m|/en/| && $_ =~ m/\.(tt|inc)$/) { |
651 |
my $filename = $File::Find::name; |
652 |
$filename =~ s|^$intrahtdocs/||; |
653 |
push @intranet_tt_files, $filename; |
654 |
} |
655 |
}, $intrahtdocs); |
656 |
|
657 |
my @opac_tt_files; |
627 |
find(sub { |
658 |
find(sub { |
628 |
if ($File::Find::dir =~ m|/en/| && $_ =~ m/\.(tt|inc)$/) { |
659 |
if ($File::Find::dir =~ m|/en/| && $_ =~ m/\.(tt|inc)$/) { |
629 |
my $filename = $File::Find::name; |
660 |
my $filename = $File::Find::name; |
630 |
$filename =~ s|^$intranetdir/||; |
661 |
$filename =~ s|^$opachtdocs/||; |
631 |
push @tt_files, $filename; |
662 |
push @opac_tt_files, $filename; |
632 |
} |
663 |
} |
633 |
}, "$intranetdir/koha-tmpl"); |
664 |
}, $opachtdocs); |
634 |
|
665 |
|
635 |
my $tempdir = tempdir('Koha-translate-XXXX', TMPDIR => 1, CLEANUP => 1); |
666 |
my $tempdir = tempdir('Koha-translate-XXXX', TMPDIR => 1, CLEANUP => 1); |
636 |
$self->extract_messages_from_templates($tempdir, @tt_files); |
667 |
$self->extract_messages_from_templates($tempdir, 'intranet', @intranet_tt_files); |
|
|
668 |
$self->extract_messages_from_templates($tempdir, 'opac', @opac_tt_files); |
669 |
|
670 |
@intranet_tt_files = map { File::Spec->catfile('koha-tmpl', 'intranet-tmpl', $_) } @intranet_tt_files; |
671 |
@opac_tt_files = map { File::Spec->catfile('koha-tmpl', 'opac-tmpl', $_) } @opac_tt_files; |
672 |
my @tt_files = grep { -e File::Spec->catfile($tempdir, $_) } @intranet_tt_files, @opac_tt_files; |
673 |
|
637 |
push @files_to_scan, @tt_files; |
674 |
push @files_to_scan, @tt_files; |
638 |
|
675 |
|
639 |
my $xgettext_cmd = "$self->{xgettext} --force-po -L Perl --from-code=UTF-8 " |
676 |
my $xgettext_cmd = "$self->{xgettext} --force-po -L Perl --from-code=UTF-8 " |
Lines 641-647
sub extract_messages {
Link Here
|
641 |
. "-k -k__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -k__p:1c,2 " |
678 |
. "-k -k__ -k__x -k__n:1,2 -k__nx:1,2 -k__xn:1,2 -k__p:1c,2 " |
642 |
. "-k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 -kN__ -kN__n:1,2 " |
679 |
. "-k__px:1c,2 -k__np:1c,2,3 -k__npx:1c,2,3 -kN__ -kN__n:1,2 " |
643 |
. "-kN__p:1c,2 -kN__np:1c,2,3 " |
680 |
. "-kN__p:1c,2 -kN__np:1c,2,3 " |
644 |
. "-o $Bin/$self->{domain}.pot -D $tempdir -D $intranetdir"; |
681 |
. "-o $Bin/$self->{domain}.pot -D $tempdir -D $basedir"; |
645 |
$xgettext_cmd .= " $_" foreach (@files_to_scan); |
682 |
$xgettext_cmd .= " $_" foreach (@files_to_scan); |
646 |
|
683 |
|
647 |
if (system($xgettext_cmd) != 0) { |
684 |
if (system($xgettext_cmd) != 0) { |