Bugzilla – Attachment 99375 Details for
Bug 24211
Compress/uncompress translation files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24211: Compress/uncompress translation files
Bug-24211-Compressuncompress-translation-files.patch (text/plain), 5.53 KB, created by
Jonathan Druart
on 2020-02-21 13:17:47 UTC
(
hide
)
Description:
Bug 24211: Compress/uncompress translation files
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-02-21 13:17:47 UTC
Size:
5.53 KB
patch
obsolete
>From d060378b636808c09a91405061c66b0afe54ac60 Mon Sep 17 00:00:00 2001 >From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Date: Tue, 10 Dec 2019 21:02:41 -0300 >Subject: [PATCH] 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> >--- > misc/translator/LangInstaller.pm | 38 ++++++++++++++++++++++++++++++++++++-- > misc/translator/translate | 15 ++++++++++++++- > 2 files changed, 50 insertions(+), 3 deletions(-) > >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index 8a7c5abcfa..13367b5c54 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -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(); >diff --git a/misc/translator/translate b/misc/translator/translate >index 8683afd7db..bab716de43 100755 >--- a/misc/translator/translate >+++ b/misc/translator/translate >@@ -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 >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24211
:
96174
|
96814
|
98584
| 99375