Bugzilla – Attachment 98584 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.44 KB, created by
Bouzid Fergani
on 2020-02-07 19:03:41 UTC
(
hide
)
Description:
Bug 24211: Compress/uncompress translation files
Filename:
MIME Type:
Creator:
Bouzid Fergani
Created:
2020-02-07 19:03:41 UTC
Size:
5.44 KB
patch
obsolete
>From 3c24e07245457209a168b930a6b164fc0e18435a 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> >--- > 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 3da23a8..6c684b7 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/misc/translator/LangInstaller.pm >@@ -81,12 +81,16 @@ sub new { > $self->{msginit} = `which msginit`; > $self->{xgettext} = `which xgettext`; > $self->{sed} = `which sed`; >+ $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"; >@@ -716,9 +720,38 @@ sub remove_pot { > unlink "$Bin/$self->{domain}.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(); >@@ -729,9 +762,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; > } > > >@@ -740,6 +773,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 59a0c12..1f254a2 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( /^$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.7.4
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