Bug 7780: make silent/verbose flag for translation installing
authorPaul Poulain <paul.poulain@biblibre.com>
Wed, 21 Mar 2012 15:18:29 +0000 (16:18 +0100)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 26 Mar 2012 09:01:40 +0000 (11:01 +0200)
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 <f.demians@tamil.fr>
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 <paul.poulain@biblibre.com>
misc/translator/LangInstaller.pm
misc/translator/tmpl_process3.pl
misc/translator/translate

index c8a204a..f9abda6 100644 (file)
@@ -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"
     }
index cb69117..89c993f 100755 (executable)
@@ -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;
index 90f2950..f0c12c9 100755 (executable)
@@ -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;