@@ -, +, @@ cd misc/translation ./translate create xx-YY check new file po/xx-YY-locale-prefs.po translate some strings on previous file, remember that those values sets the preference ./translate update xx-YY check translations are preserved ./translate install xx-YY check new locale-sysprefs.yml file in installer/data/mysql/xx-YY/ check 'translated' options Check correct value on sysprefs --- misc/translator/LangInstaller.pm | 77 ++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 4 deletions(-) --- a/misc/translator/LangInstaller.pm +++ a/misc/translator/LangInstaller.pm @@ -165,6 +165,13 @@ sub new { suffix => "-installer-MARC21.po", }; + # EN locales sysprefs + push @{$self->{installer}}, { + name => "Localized sysprefs", + dirs => [ 'installer/data/mysql/en/', ], + suffix => "-locale-prefs.po", + }; + # EN UNIMARC YAML installer files push @{$self->{installer}}, { name => "UNIMARC YAML installer files", @@ -551,6 +558,64 @@ sub get_po_from_target { return $po; } +sub get_po_from_locale_pref { + my $self = shift; + my $target = shift; + + my $po; + my $po_head = new Locale::PO; + $po_head->{msgid} = "\"\""; + $po_head->{msgstr} = "". + "Project-Id-Version: Koha Project - Installation files\\n" . + "PO-Revision-Date: YEAR-MO-DA HO:MI +ZONE\\n" . + "Last-Translator: FULL NAME \\n" . + "Language-Team: Koha Translation Team\\n" . + "Language: ".$self->{lang}."\\n" . + "MIME-Version: 1.0\\n" . + "Content-Type: text/plain; charset=UTF-8\\n" . + "Content-Transfer-Encoding: 8bit\\n"; + + my @dirs = @{ $target->{dirs} }; + my $intradir = $self->{context}->config('intranetdir'); + for my $dir ( @dirs ) { # each dir + opendir( my $dh, "$intradir/$dir" ) or die ("Can't open $intradir/$dir"); + my @filelist = grep { $_ =~ m/\.yml/ } readdir($dh); # Just yaml files + close($dh); + for my $file ( @filelist ) { # each file + my $yaml = LoadFile( "$intradir/$dir/$file" ); + my @tables = @{ $yaml->{'tables'} }; + my $tablec; + for my $table ( @tables ) { # each table + $tablec++; + my $table_name = ( keys %$table )[0]; + my @translatable = @{ $table->{$table_name}->{translatable} }; + my @rows = @{ $table->{$table_name}->{rows} }; + my @comments; + @comments = @{ $table->{$table_name}->{'comments'} } if ( $table->{$table_name}->{'comments'} ); + my $rowc; + for my $row ( @rows ) { # each row + $rowc++; + for my $field ( @translatable ) { # each field + my $automatic; + $automatic = "Use this to SET sysprefs\n" . join "\n", map { "$_: $row->{$_}" } @comments if ( @comments ); + if ( defined $row->{$field} and not $po->{ "$row->{variable}# ".$row->{$field} } ) { + my $msg = new Locale::PO( + -msgid => "$row->{variable}# ".$row->{$field}, -msgstr => "$row->{$field}", + -reference => "$dir/$file:$table_name:$tablec:row:$rowc" ); + $msg->automatic($automatic) if ( $automatic ); + $msg->fuzzy(1); + $po->{ "$row->{variable}# ".$row->{$field} } = $msg; + } + } + } + } + } + } + $po->{''} = $po_head if ( $po ); + + return $po; +} + sub create_installer { my $self = shift; return unless ( $self->{installer} ); @@ -567,7 +632,7 @@ sub create_installer { } for my $target ( @targets ) { - my $po = get_po_from_target( $self, $target ); + my $po = ( $target->{suffix} =~ /locale-prefs/ ) ? get_po_from_locale_pref( $self, $target ) : get_po_from_target( $self, $target ); # create output file only if there is something to write if ( $po ) { my $po_file = $self->po_filename( $target->{suffix} ); @@ -587,7 +652,7 @@ sub update_installer { for my $target ( @targets ) { return unless ( -e $self->po_filename( $target->{suffix} ) ); - my $po = get_po_from_target( $self, $target ); + my $po = ( $target->{suffix} =~ /locale-pref/ ) ? get_po_from_locale_pref( $self, $target ) : get_po_from_target( $self, $target ); # update file only if there is something to update if ( $po ) { my ( $fh, $po_temp ) = tempfile(); @@ -608,6 +673,8 @@ sub translate_yaml { my $target = shift; my $srcyml = shift; + my $pref = ( $target->{suffix} =~ /locale-pref/ ) ? 1 : 0; + my $po_file = $self->po_filename( $target->{suffix} ); return $srcyml unless ( -e $po_file ); @@ -654,7 +721,9 @@ sub translate_yaml { } } else { next unless defined $row->{$field}; # next if null value - my $po = $po_ref->{"\"$row->{$field}\""}; # quoted key + my $key = ( $pref ) ? $row->{variable}."# ".$row->{$field} : $row->{$field}; + $key =~ s/"/\\"/g; + my $po = $po_ref->{"\"$key\""}; if ( $po and not defined( $po->fuzzy() ) # not fuzzy and length( $po->msgid() ) > 2 # not empty msgid and length( $po->msgstr() ) > 2 ) { # not empty msgstr @@ -699,7 +768,7 @@ sub install_installer { make_path("$intradir/$tdir"); opendir( my $dh, "$intradir/$dir" ) or die ("Can't open $intradir/$dir"); - my @files = grep { ! /^\.+$/ } readdir($dh); + my @files = grep { $_ =~ m/\.yml/ } readdir($dh); close($dh); for my $file ( @files ) { --