3cfc2ec7bd
misc/translator/translate was doing three different things: - extract translatable strings - create or update PO files - install translated templates This patch separates responsibilities by moving the string extraction code into several 'xgettext-like' scripts and adds gulp tasks to automate string extraction and PO files update This has several benefits: - gulp runs tasks in parallel, so it's a lot faster (updating all PO files is at least 10 times faster with my 4-cores CPU) - there is no need for $KOHA_CONF to be defined LangInstaller.pm relied on $KOHA_CONF to get the different paths needed. I'm not sure why, since string extraction and PO update should work on source files, not installed files - string extraction code can be more easily tested This patch also brings a couple of fixes and improvements: - TT string extraction (strings wrapped in [% t(...) %]) was done with Template::Parser and PPI, which was extremely slow, and had some problems (see bug 24797). This is now done with Locale::XGettext::TT2 (new dependency) which is a lot faster, and fixes bug 24797 - Fix header in 4 PO files For backward compatibility, 'create' and 'update' commands of misc/translator/translate can still be used and will execute the corresponding gulp task Test plan: 1. Run `yarn install` and install Locale::XGettext::TT2 2. Run `gulp po:update` 3. Verify the contents of updated PO files 4. Run `cd misc/translator && ./translate install <lang>` 5. Verify that all (templates, sysprefs, xslt, installer files) is correctly translated 6. Run `gulp po:create --lang <lang>` and verify that it created all PO files for that language 7. Run `prove t/misc/translator` Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> Need to install yarn & gulp, no errors Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
140 lines
3.5 KiB
Perl
Executable file
140 lines
3.5 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
# Copyright (C) 2010 Tamil s.a.r.l.
|
|
#
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
package Main;
|
|
|
|
use FindBin;
|
|
use lib $FindBin::Bin;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use LangInstaller;
|
|
use Getopt::Long;
|
|
use Pod::Usage;
|
|
|
|
use Koha::Caches;
|
|
|
|
|
|
my $verbose = 0;
|
|
my $pref = 0;
|
|
my $all = 0;
|
|
my @files;
|
|
GetOptions(
|
|
'v|verbose' => \$verbose,
|
|
'p' => \$pref,
|
|
'f:s' => \@files,
|
|
'a|all' => \$all,
|
|
);
|
|
|
|
|
|
sub usage {
|
|
pod2usage( -verbose => 2 );
|
|
exit;
|
|
}
|
|
|
|
|
|
usage() if $#ARGV != 1 && $#ARGV != 0;
|
|
|
|
my ($cmd, $lang) = @ARGV;
|
|
$cmd = lc $cmd;
|
|
if ( $cmd =~ /^(install|compress|uncompress)$/ ) {
|
|
my $installer = LangInstaller->new( $lang, $pref, $verbose );
|
|
if ( $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
|
|
print "Unsupported language: $lang\n";
|
|
exit;
|
|
}
|
|
if ( $all ) {
|
|
for my $lang ( @{$installer->{langs}} ) {
|
|
$installer->set_lang( $lang );
|
|
$installer->$cmd(\@files);
|
|
}
|
|
}
|
|
else {
|
|
$installer->$cmd(\@files);
|
|
}
|
|
|
|
Koha::Caches->get_instance()->flush_all;
|
|
} elsif ($cmd eq 'create' or $cmd eq 'update') {
|
|
my $command = "gulp po:$cmd";
|
|
$command .= " --silent" if (!$verbose);
|
|
$command .= " --lang $lang" if ($lang);
|
|
|
|
if ($verbose) {
|
|
print STDERR "Deprecation notice: PO creation and update are now gulp tasks. See docs/development/internationalization.md\n";
|
|
print STDERR "Running `$command`\n";
|
|
}
|
|
|
|
system($command);
|
|
} else {
|
|
usage();
|
|
}
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
translate - Handle templates and preferences translation
|
|
|
|
=head1 SYNOPSYS
|
|
|
|
translate install fr-FR
|
|
translate install fr-FR -f search -f memberentry
|
|
translate -p install fr-FR
|
|
translate compress [fr-FR]
|
|
translate uncompress [fr-FR]
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
In Koha, three categories of information are translated based on standard GNU
|
|
.po files: opac templates pages, intranet templates and system preferences. The
|
|
script is a wrapper. It allows to quickly install .po files for a
|
|
given language or for all available languages.
|
|
|
|
=head1 USAGE
|
|
|
|
Use the -v or --verbose parameter to make translator more verbose.
|
|
|
|
=over
|
|
|
|
=item translate [-p|-f] install F<lang>
|
|
|
|
Use .po files to translate the english version of templates and preferences files
|
|
and copy those files in the appropriate directory. Without F<lang>, all
|
|
available languages are installed. With -p option, only preferences .po file is
|
|
updated.
|
|
|
|
With -f parameter (repeatable) you can specify specific files to translate. For
|
|
example, -f search will translate all templates containing 'search'.
|
|
|
|
=item translate compress F<lang>
|
|
|
|
Compress .po files in F<po> directory, named F<lang>-*.po. Without F<lang>, files
|
|
from all available languages are compressed.
|
|
|
|
=item translate uncompress F<lang>
|
|
|
|
Uncompress .po.gz files in F<po> directory, named F<lang>-*.po.gz. Without F<lang>,
|
|
files from all available languages are uncompressed.
|
|
|
|
|
|
=back
|
|
|
|
=cut
|
|
|