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 );
}
}
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;
}
}
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 );
}
-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};
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();
}
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" );
}
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};
}
}
+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();
+ }
}