Bug 24211: Compress/uncompress translation files

This patch adds the ability to compress/uncompress
translations files.

On update/install the files are uncompressed first

The only gain is to use less space.

To test:
1) Apply the patch
2) Go to misc/translator
3) Try it
   $ ./translate compress fr-FR (check po/*.gz)
   $ ./translate uncompress fr-FR ( check normal files)
4) Try again with verbose mode
   $ ./translate compress fr-FR -v (list compressed files)
   $ ./translate uncompress fr-FR -v (list uncompressed files)
5) Try update compressed files
   $ ./translate compress fr-FR
   $ ./translate update fr-FR (result is uncompressed)
6) Try install compressed files
   $ ./translate compress fr-FR
   $ ./translate install fr-FR
7) Try compress all
   $ ./translate compress  (add '-v' for verbose output)
8) Try uncompress all
   $ ./translate uncompress  (add '-v' for verbose output)

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Bouzid Fergani <bouzid.fergani@inlibro.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Bernardo Gonzalez Kriegel 2019-12-10 21:02:41 -03:00 committed by Martin Renvoize
parent 612887d46f
commit e875e39806
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
2 changed files with 50 additions and 3 deletions

View File

@ -82,12 +82,16 @@ sub new {
$self->{xgettext} = `which xgettext`;
$self->{sed} = `which sed`;
$self->{po2json} = "$Bin/po2json";
$self->{gzip} = `which gzip`;
$self->{gunzip} = `which gunzip`;
chomp $self->{cp};
chomp $self->{msgmerge};
chomp $self->{msgfmt};
chomp $self->{msginit};
chomp $self->{xgettext};
chomp $self->{sed};
chomp $self->{gzip};
chomp $self->{gunzip};
unless ($self->{xgettext}) {
die "Missing 'xgettext' executable. Have you installed the gettext package?\n";
@ -766,9 +770,38 @@ sub remove_pot {
unlink "$Bin/$self->{domain}-js.pot";
}
sub compress {
my ($self, $files) = @_;
my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
for my $lang ( @langs ) {
$self->set_lang( $lang );
opendir( my $dh, $self->{path_po} );
my @files = grep { $_ =~ /^$self->{lang}.*po$/ } readdir $dh;
foreach my $file ( @files ) {
say "Compress file $file" if $self->{verbose};
system "$self->{gzip} -9 $self->{path_po}/$file";
}
}
}
sub uncompress {
my ($self, $files) = @_;
my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
for my $lang ( @langs ) {
opendir( my $dh, $self->{path_po} );
$self->set_lang( $lang );
my @files = grep { $_ =~ /^$self->{lang}.*po.gz$/ } readdir $dh;
foreach my $file ( @files ) {
say "Uncompress file $file" if $self->{verbose};
system "$self->{gunzip} $self->{path_po}/$file";
}
}
}
sub install {
my ($self, $files) = @_;
return unless $self->{lang};
$self->uncompress();
$self->install_tmpl($files) unless $self->{pref_only};
$self->install_prefs();
$self->install_messages();
@ -779,9 +812,9 @@ sub install {
sub get_all_langs {
my $self = shift;
opendir( my $dh, $self->{path_po} );
my @files = grep { $_ =~ /-pref.po$/ }
my @files = grep { $_ =~ /-pref.(po|po.gz)$/ }
readdir $dh;
@files = map { $_ =~ s/-pref.po$//; $_ } @files;
@files = map { $_ =~ s/-pref.(po|po.gz)$//; $_ } @files;
}
@ -790,6 +823,7 @@ sub update {
my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs();
for my $lang ( @langs ) {
$self->set_lang( $lang );
$self->uncompress();
$self->update_tmpl($files) unless $self->{pref_only};
$self->update_prefs();
$self->update_messages();

View File

@ -52,7 +52,7 @@ usage() if $#ARGV != 1 && $#ARGV != 0;
my ($cmd, $lang) = @ARGV;
$cmd = lc $cmd;
if ( $cmd =~ /create|install|update/ ) {
if ( $cmd =~ /^(create|install|update|compress|uncompress)$/ ) {
my $installer = LangInstaller->new( $lang, $pref, $verbose );
if ( $cmd ne 'create' and $lang and not grep( {$_ eq $lang} @{ $installer->{langs} } ) ) {
print "Unsupported language: $lang\n";
@ -87,6 +87,8 @@ translate - Handle templates and preferences translation
translate install fr-FR -f search -f memberentry
translate -p install fr-FR
translate install
translate compress [fr-FR]
translate uncompress [fr-FR]
=head1 DESCRIPTION
@ -143,6 +145,17 @@ 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