From d029ec835d31c83322ef2e4de31bc597c2deb496 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Wed, 21 Mar 2012 16:18:29 +0100 Subject: [PATCH] Bug 7780: make silent/verbose flag for translation installing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This patch deal with the -v flag that you can put on translate script. If you run without -v, the process should be silent if you run with -v, the process should be verbose Signed-off-by: Frédéric Demians I've refactored your patch to handle verbosity directly via a translator attribute, rather than with parameter which has to be send to each object call method. Signed-off-by: Paul Poulain --- misc/translator/LangInstaller.pm | 38 ++++++++++++++++---------------- misc/translator/tmpl_process3.pl | 5 ++--- misc/translator/translate | 2 +- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index c8a204a393..f9abda6d6a 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -39,7 +39,7 @@ sub set_lang { sub new { - my ($class, $lang, $pref_only) = @_; + my ($class, $lang, $pref_only, $verbose) = @_; my $self = { }; @@ -49,8 +49,9 @@ sub new { '/prog/en/modules/admin/preferences'; set_lang( $self, $lang ) if $lang; $self->{pref_only} = $pref_only; - $self->{translator_path} = $Bin; - $self->{path_po} = $self->{translator_path} . "/po"; + $self->{verbose} = $verbose; + $self->{process} = "$Bin/tmpl_process3.pl " . ($verbose ? '' : '-q'); + $self->{path_po} = "$Bin/po"; $self->{po} = {}; # Get all .pref file names @@ -210,7 +211,7 @@ sub save_po { my $self = shift; # Write .po entries into a file put in Koha standard po directory Locale::PO->save_file_fromhash( $self->po_filename, $self->{po} ); - print "Saved in file: ", $self->po_filename, "\n"; + print "Saved in file: ", $self->po_filename, "\n" if $self->{verbose}; } @@ -236,7 +237,7 @@ sub get_po_merged_with_en { sub update_prefs { my $self = shift; print "Update '", $self->{lang}, - "' preferences .po file from 'en' .pref files\n"; + "' preferences .po file from 'en' .pref files\n" if $self->{verbose}; $self->get_po_merged_with_en(); $self->save_po(); } @@ -281,7 +282,7 @@ sub install_prefs { $pref->{$tab} = $ntab; } my $file_trans = $self->{po_path_lang} . "/$file"; - print "Write $file\n"; + print "Write $file\n" if $self->{verbose}; open my $fh, ">", $file_trans; print $fh Dump($pref); } @@ -290,19 +291,18 @@ sub install_prefs { sub install_tmpl { my $self = shift; - - print - "Install templates\n"; + print "Install templates\n" if $self->{verbose}; while ( my ($interface, $tmpl) = each %{$self->{interface}} ) { print " Install templates '$interface\n", " From: $tmpl->{dir}/en/\n", " To : $tmpl->{dir}/$self->{lang}\n", - " With: $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"; + " With: $self->{path_po}/$self->{lang}$tmpl->{suffix}\n" + if $self->{verbose}; my $lang_dir = "$tmpl->{dir}/$self->{lang}"; mkdir $lang_dir unless -d $lang_dir; system - "$self->{translator_path}/tmpl_process3.pl install " . + "$self->{process} install " . "-i $tmpl->{dir}/en/ " . "-o $tmpl->{dir}/$self->{lang} ". "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" @@ -313,17 +313,17 @@ sub install_tmpl { sub update_tmpl { my $self = shift; - print - "Update templates\n"; + print "Update templates\n" if $self->{verbose}; while ( my ($interface, $tmpl) = each %{$self->{interface}} ) { print " Update templates '$interface'\n", " From: $tmpl->{dir}/en/\n", - " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"; + " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n" + if $self->{verbose}; my $lang_dir = "$tmpl->{dir}/$self->{lang}"; mkdir $lang_dir unless -d $lang_dir; system - "$self->{translator_path}/tmpl_process3.pl update " . + "$self->{process} update " . "-i $tmpl->{dir}/en/ " . "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" } @@ -341,15 +341,15 @@ sub create_prefs { sub create_tmpl { my $self = shift; - print - "Create templates\n"; + print "Create templates\n" if $self->{verbose}; while ( my ($interface, $tmpl) = each %{$self->{interface}} ) { print " Create templates .po files for '$interface'\n", " From: $tmpl->{dir}/en/\n", - " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"; + " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n" + if $self->{verbose}; system - "$self->{translator_path}/tmpl_process3.pl create " . + "$self->{process} create " . "-i $tmpl->{dir}/en/ " . "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" } diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index cb69117e7c..89c993f672 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -272,7 +272,6 @@ if (defined $href) { die "$str_file: PO file is corrupted, or not a PO file\n" unless defined $href->{'""'}; $charset_out = TmplTokenizer::charset_canon $2 if $href->{'""'}->msgstr =~ /\bcharset=(["']?)([^;\s"'\\]+)\1/; $charset_in = $charset_out; - warn "Charset in/out: ".$charset_out; # for my $msgid (keys %$href) { # if ($msgid =~ /\bcharset=(["']?)([^;\s"'\\]+)\1/) { # my $candidate = TmplTokenizer::charset_canon $2; @@ -350,7 +349,7 @@ if ($action eq 'create') { close INPUT; close OUTPUT; } - $st = system('msgmerge', '-U', '-s', $str_file, $tmpfile2); + $st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile2"); } else { error_normal "Text extraction failed: $xgettext: $!\n", undef; error_additional "Will not run msgmerge\n", undef; @@ -376,7 +375,7 @@ if ($action eq 'create') { # Merge the temporary "pot file" with the specified po file ($str_file) # FIXME: msgmerge(1) is a Unix dependency # FIXME: need to check the return value - $st = system('msgmerge', '-U', '-s', $str_file, $tmpfile2); + $st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile2"); } else { error_normal "Text extraction failed: $xgettext: $!\n", undef; error_additional "Will not run msgmerge\n", undef; diff --git a/misc/translator/translate b/misc/translator/translate index 90f2950b7a..f0c12c9f12 100755 --- a/misc/translator/translate +++ b/misc/translator/translate @@ -48,7 +48,7 @@ usage() if $#ARGV != 1 && $#ARGV != 0; my ($cmd, $lang) = @ARGV; $cmd = lc $cmd; if ( $cmd =~ /create|install|update/ ) { - my $installer = LangInstaller->new( $lang, $pref ); + my $installer = LangInstaller->new( $lang, $pref, $verbose ); if ( $cmd !~ /create/ && $lang && not $lang ~~ $installer->{langs} ) { print "Unsupported language: $lang\n"; exit; -- 2.39.5