From 814795da60318c70059fc1dfbe7be4da37109db0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Demians?= Date: Sun, 19 Dec 2010 10:57:51 +0100 Subject: [PATCH] Bug 5506 Improve translation script [1] Update all .po files in once with this command: translate update [2] For sysprefs, quoted text wasn't properly retrieved from .po file and so quoted strings wasn't translatable. [3] The install process (translate -p install de-DE) was rewriting syspref .po file which isn't required anymore. MUST be applied to [3.2] to get all syspref proper translation. Signed-off-by: Chris Cormack --- misc/translator/LangInstaller.pm | 44 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index a1fef0f40d..010b4a7348 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -21,6 +21,8 @@ use strict; use warnings; use C4::Context; +# WARNING: Any other tested YAML library fails to work properly in this +# script content use YAML::Syck qw( Dump LoadFile ); use Locale::PO; use FindBin qw( $Bin ); @@ -172,7 +174,8 @@ sub update_tab_prefs { } } elsif ( $element ) { - my $text = $self->get_trans_text( $self->{file} . "#$pref_name# $element" ); + my $id = $self->{file} . "#$pref_name# $element"; + my $text = $self->get_trans_text( $id ); $p->[$i] = $text if $text; } } @@ -186,7 +189,6 @@ sub get_po_from_prefs { for my $file ( @{$self->{pref_files}} ) { my $pref = LoadFile( $self->{path_pref_en} . "/$file" ); $self->{file} = $file; - #print Dump($pref), "\n"; while ( my ($tab, $tab_content) = each %$pref ) { if ( ref($tab_content) eq 'ARRAY' ) { $self->add_prefs( $tab, $tab_content ); @@ -210,10 +212,9 @@ sub save_po { } -sub update_prefs { +sub get_po_merged_with_en { my $self = shift; - print "Update '", $self->{lang}, "' preferences .po file from 'en' .pref files\n"; # Get po from current 'en' .pref files $self->get_po_from_prefs(); my $po_current = $self->{po}; @@ -222,12 +223,19 @@ sub update_prefs { my $po_previous = Locale::PO->load_file_ashash( $self->po_filename ); for my $id ( keys %$po_current ) { - my $po = $po_previous->{'"'.$id.'"'}; + my $po = $po_previous->{Locale::PO->quote($id)}; next unless $po; my $text = Locale::PO->dequote( $po->msgstr ); $po_current->{$id}->msgstr( $text ); } +} + +sub update_prefs { + my $self = shift; + print "Update '", $self->{lang}, + "' preferences .po file from 'en' .pref files\n"; + $self->get_po_merged_with_en(); $self->save_po(); } @@ -240,9 +248,8 @@ sub install_prefs { exit; } - # Update the language .po file with last modified 'en' preferences - # and load it. - $self->update_prefs(); + # Get the language .po file merged with last modified 'en' preferences + $self->get_po_merged_with_en(); for my $file ( @{$self->{pref_files}} ) { my $pref = LoadFile( $self->{path_pref_en} . "/$file" ); @@ -257,7 +264,8 @@ sub install_prefs { } my $ntab = {}; for my $section ( keys %$tab_content ) { - my $text = $self->get_trans_text($self->{file} . " $section"); + my $id = $self->{file} . " $section"; + my $text = $self->get_trans_text($id); my $nsection = $text ? $text : $section; $ntab->{$nsection} = $tab_content->{$section}; } @@ -347,11 +355,23 @@ sub install { } +sub get_all_langs { + my $self = shift; + opendir( my $dh, $self->{path_po} ); + my @files = grep { $_ =~ /-i-opac-t-prog-v-3002000.po$/ } + readdir $dh; + @files = map { $_ =~ s/-i-opac-t-prog-v-3002000.po$//; $_ } @files; +} + + sub update { my $self = shift; - return unless $self->{lang}; - $self->update_tmpl() unless $self->{pref_only}; - $self->update_prefs(); + 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(); + } } -- 2.39.5