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: 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>
This commit is contained in:
parent
5531904dcc
commit
d029ec835d
3 changed files with 22 additions and 23 deletions
|
@ -39,7 +39,7 @@ sub set_lang {
|
||||||
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, $lang, $pref_only) = @_;
|
my ($class, $lang, $pref_only, $verbose) = @_;
|
||||||
|
|
||||||
my $self = { };
|
my $self = { };
|
||||||
|
|
||||||
|
@ -49,8 +49,9 @@ sub new {
|
||||||
'/prog/en/modules/admin/preferences';
|
'/prog/en/modules/admin/preferences';
|
||||||
set_lang( $self, $lang ) if $lang;
|
set_lang( $self, $lang ) if $lang;
|
||||||
$self->{pref_only} = $pref_only;
|
$self->{pref_only} = $pref_only;
|
||||||
$self->{translator_path} = $Bin;
|
$self->{verbose} = $verbose;
|
||||||
$self->{path_po} = $self->{translator_path} . "/po";
|
$self->{process} = "$Bin/tmpl_process3.pl " . ($verbose ? '' : '-q');
|
||||||
|
$self->{path_po} = "$Bin/po";
|
||||||
$self->{po} = {};
|
$self->{po} = {};
|
||||||
|
|
||||||
# Get all .pref file names
|
# Get all .pref file names
|
||||||
|
@ -210,7 +211,7 @@ sub save_po {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
# Write .po entries into a file put in Koha standard po directory
|
# Write .po entries into a file put in Koha standard po directory
|
||||||
Locale::PO->save_file_fromhash( $self->po_filename, $self->{po} );
|
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 {
|
sub update_prefs {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
print "Update '", $self->{lang},
|
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->get_po_merged_with_en();
|
||||||
$self->save_po();
|
$self->save_po();
|
||||||
}
|
}
|
||||||
|
@ -281,7 +282,7 @@ sub install_prefs {
|
||||||
$pref->{$tab} = $ntab;
|
$pref->{$tab} = $ntab;
|
||||||
}
|
}
|
||||||
my $file_trans = $self->{po_path_lang} . "/$file";
|
my $file_trans = $self->{po_path_lang} . "/$file";
|
||||||
print "Write $file\n";
|
print "Write $file\n" if $self->{verbose};
|
||||||
open my $fh, ">", $file_trans;
|
open my $fh, ">", $file_trans;
|
||||||
print $fh Dump($pref);
|
print $fh Dump($pref);
|
||||||
}
|
}
|
||||||
|
@ -290,19 +291,18 @@ sub install_prefs {
|
||||||
|
|
||||||
sub install_tmpl {
|
sub install_tmpl {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
print "Install templates\n" if $self->{verbose};
|
||||||
print
|
|
||||||
"Install templates\n";
|
|
||||||
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
||||||
print
|
print
|
||||||
" Install templates '$interface\n",
|
" Install templates '$interface\n",
|
||||||
" From: $tmpl->{dir}/en/\n",
|
" From: $tmpl->{dir}/en/\n",
|
||||||
" To : $tmpl->{dir}/$self->{lang}\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}";
|
my $lang_dir = "$tmpl->{dir}/$self->{lang}";
|
||||||
mkdir $lang_dir unless -d $lang_dir;
|
mkdir $lang_dir unless -d $lang_dir;
|
||||||
system
|
system
|
||||||
"$self->{translator_path}/tmpl_process3.pl install " .
|
"$self->{process} install " .
|
||||||
"-i $tmpl->{dir}/en/ " .
|
"-i $tmpl->{dir}/en/ " .
|
||||||
"-o $tmpl->{dir}/$self->{lang} ".
|
"-o $tmpl->{dir}/$self->{lang} ".
|
||||||
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
||||||
|
@ -313,17 +313,17 @@ sub install_tmpl {
|
||||||
sub update_tmpl {
|
sub update_tmpl {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
print
|
print "Update templates\n" if $self->{verbose};
|
||||||
"Update templates\n";
|
|
||||||
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
||||||
print
|
print
|
||||||
" Update templates '$interface'\n",
|
" Update templates '$interface'\n",
|
||||||
" From: $tmpl->{dir}/en/\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}";
|
my $lang_dir = "$tmpl->{dir}/$self->{lang}";
|
||||||
mkdir $lang_dir unless -d $lang_dir;
|
mkdir $lang_dir unless -d $lang_dir;
|
||||||
system
|
system
|
||||||
"$self->{translator_path}/tmpl_process3.pl update " .
|
"$self->{process} update " .
|
||||||
"-i $tmpl->{dir}/en/ " .
|
"-i $tmpl->{dir}/en/ " .
|
||||||
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
||||||
}
|
}
|
||||||
|
@ -341,15 +341,15 @@ sub create_prefs {
|
||||||
sub create_tmpl {
|
sub create_tmpl {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
print
|
print "Create templates\n" if $self->{verbose};
|
||||||
"Create templates\n";
|
|
||||||
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
while ( my ($interface, $tmpl) = each %{$self->{interface}} ) {
|
||||||
print
|
print
|
||||||
" Create templates .po files for '$interface'\n",
|
" Create templates .po files for '$interface'\n",
|
||||||
" From: $tmpl->{dir}/en/\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
|
system
|
||||||
"$self->{translator_path}/tmpl_process3.pl create " .
|
"$self->{process} create " .
|
||||||
"-i $tmpl->{dir}/en/ " .
|
"-i $tmpl->{dir}/en/ " .
|
||||||
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
"-s $self->{path_po}/$self->{lang}$tmpl->{suffix} -r"
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,7 +272,6 @@ if (defined $href) {
|
||||||
die "$str_file: PO file is corrupted, or not a PO file\n" unless 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_out = TmplTokenizer::charset_canon $2 if $href->{'""'}->msgstr =~ /\bcharset=(["']?)([^;\s"'\\]+)\1/;
|
||||||
$charset_in = $charset_out;
|
$charset_in = $charset_out;
|
||||||
warn "Charset in/out: ".$charset_out;
|
|
||||||
# for my $msgid (keys %$href) {
|
# for my $msgid (keys %$href) {
|
||||||
# if ($msgid =~ /\bcharset=(["']?)([^;\s"'\\]+)\1/) {
|
# if ($msgid =~ /\bcharset=(["']?)([^;\s"'\\]+)\1/) {
|
||||||
# my $candidate = TmplTokenizer::charset_canon $2;
|
# my $candidate = TmplTokenizer::charset_canon $2;
|
||||||
|
@ -350,7 +349,7 @@ if ($action eq 'create') {
|
||||||
close INPUT;
|
close INPUT;
|
||||||
close OUTPUT;
|
close OUTPUT;
|
||||||
}
|
}
|
||||||
$st = system('msgmerge', '-U', '-s', $str_file, $tmpfile2);
|
$st = system("msgmerge -U ".($quiet?'-q':'')." -s $str_file $tmpfile2");
|
||||||
} else {
|
} else {
|
||||||
error_normal "Text extraction failed: $xgettext: $!\n", undef;
|
error_normal "Text extraction failed: $xgettext: $!\n", undef;
|
||||||
error_additional "Will not run msgmerge\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)
|
# Merge the temporary "pot file" with the specified po file ($str_file)
|
||||||
# FIXME: msgmerge(1) is a Unix dependency
|
# FIXME: msgmerge(1) is a Unix dependency
|
||||||
# FIXME: need to check the return value
|
# 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 {
|
} else {
|
||||||
error_normal "Text extraction failed: $xgettext: $!\n", undef;
|
error_normal "Text extraction failed: $xgettext: $!\n", undef;
|
||||||
error_additional "Will not run msgmerge\n", undef;
|
error_additional "Will not run msgmerge\n", undef;
|
||||||
|
|
|
@ -48,7 +48,7 @@ usage() if $#ARGV != 1 && $#ARGV != 0;
|
||||||
my ($cmd, $lang) = @ARGV;
|
my ($cmd, $lang) = @ARGV;
|
||||||
$cmd = lc $cmd;
|
$cmd = lc $cmd;
|
||||||
if ( $cmd =~ /create|install|update/ ) {
|
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} ) {
|
if ( $cmd !~ /create/ && $lang && not $lang ~~ $installer->{langs} ) {
|
||||||
print "Unsupported language: $lang\n";
|
print "Unsupported language: $lang\n";
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in a new issue