From a2e381ad30da451ef6401d3b86a235b30d531de5 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 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: Katrin Fischer Works as described. --- misc/translator/LangInstaller.pm | 83 ++++++++++++++++++++++++-------------- misc/translator/tmpl_process3.pl | 5 +- misc/translator/translate | 9 ++++- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index c8a204a..95f2b15 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -208,9 +208,12 @@ sub get_po_from_prefs { sub save_po { my $self = shift; + my $silent = 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"; + if ($silent) { + print "Saved in file: ", $self->po_filename, "\n"; + } } @@ -235,15 +238,19 @@ sub get_po_merged_with_en { sub update_prefs { my $self = shift; - print "Update '", $self->{lang}, - "' preferences .po file from 'en' .pref files\n"; + my $silent = shift; + unless ($silent) { + print "Update '", $self->{lang}, + "' preferences .po file from 'en' .pref files\n"; + } $self->get_po_merged_with_en(); - $self->save_po(); + $self->save_po($silent); } sub install_prefs { my $self = shift; + my $silent = shift; unless ( -r $self->{po_path_lang} ) { print "Koha directories hierarchy for ", $self->{lang}, " must be created first\n"; @@ -281,7 +288,9 @@ sub install_prefs { $pref->{$tab} = $ntab; } my $file_trans = $self->{po_path_lang} . "/$file"; - print "Write $file\n"; + unless ($silent) { + print "Write $file\n"; + } open my $fh, ">", $file_trans; print $fh Dump($pref); } @@ -290,19 +299,22 @@ sub install_prefs { sub install_tmpl { my $self = shift; - - print - "Install templates\n"; + my $silent = shift; + unless ($silent) { + print "Install templates\n"; + } 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"; + unless ($silent) { + 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"; + } my $lang_dir = "$tmpl->{dir}/$self->{lang}"; mkdir $lang_dir unless -d $lang_dir; system - "$self->{translator_path}/tmpl_process3.pl install " . + "$self->{translator_path}/tmpl_process3.pl $silent install " . "-i $tmpl->{dir}/en/ " . "-o $tmpl->{dir}/$self->{lang} ". "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" @@ -312,18 +324,22 @@ sub install_tmpl { sub update_tmpl { my $self = shift; + my $silent = shift; - print - "Update templates\n"; + unless ($silent) { + print "Update templates\n"; + } 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"; + unless ($silent) { + print + " Update templates '$interface'\n", + " From: $tmpl->{dir}/en/\n", + " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"; + } my $lang_dir = "$tmpl->{dir}/$self->{lang}"; mkdir $lang_dir unless -d $lang_dir; system - "$self->{translator_path}/tmpl_process3.pl update " . + "$self->{translator_path}/tmpl_process3.pl update $silent " . "-i $tmpl->{dir}/en/ " . "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" } @@ -340,16 +356,20 @@ sub create_prefs { sub create_tmpl { my $self = shift; + my $silent = shift; - print - "Create templates\n"; + unless ($silent) { + print "Create templates\n"; + } while ( my ($interface, $tmpl) = each %{$self->{interface}} ) { + unless ($silent) { print " Create templates .po files for '$interface'\n", " From: $tmpl->{dir}/en/\n", " To : $self->{path_po}/$self->{lang}$tmpl->{suffix}\n"; + } system - "$self->{translator_path}/tmpl_process3.pl create " . + "$self->{translator_path}/tmpl_process3.pl $silent create " . "-i $tmpl->{dir}/en/ " . "-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r" } @@ -358,9 +378,10 @@ sub create_tmpl { sub install { my $self = shift; + my $silent = shift; return unless $self->{lang}; - $self->install_tmpl() unless $self->{pref_only}; - $self->install_prefs(); + $self->install_tmpl($silent) unless $self->{pref_only}; + $self->install_prefs($silent); } @@ -375,20 +396,22 @@ sub get_all_langs { sub update { my $self = shift; + my $silent = shift; my @langs = $self->{lang} ? ($self->{lang}) : $self->get_all_langs(); for my $lang ( @langs ) { $self->set_lang( $lang ); - $self->update_tmpl() unless $self->{pref_only}; - $self->update_prefs(); + $self->update_tmpl($silent) unless $self->{pref_only}; + $self->update_prefs($silent); } } sub create { my $self = shift; + my $silent = shift; return unless $self->{lang}; - $self->create_tmpl() unless $self->{pref_only}; - $self->create_prefs(); + $self->create_tmpl($silent) unless $self->{pref_only}; + $self->create_prefs($silent); } diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index cb69117..89c993f 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 90f2950..57d0454 100755 --- a/misc/translator/translate +++ b/misc/translator/translate @@ -36,6 +36,13 @@ GetOptions( 'a|all' => \$all, ); +# crapy API = tmpl_process3.pl has a -q flag to silent the process +# this script has a -v (verbose) flag. +# so, here we're setting $silent depending on $verbose... +my $silent='-q'; +if ($verbose) { + $silent = ''; +} sub usage { pod2usage( -verbose => 2 ); @@ -61,7 +68,7 @@ if ( $cmd =~ /create|install|update/ ) { } } else { - $installer->$cmd(); + $installer->$cmd($silent); } } else { -- 1.7.5.4