Bugzilla – Attachment 103074 Details for
Bug 24973
Allow to localize and translate system preferences with new yaml based installer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24973: Translate locale-syspref.yml
Bug-24973-Translate-locale-sysprefyml.patch (text/plain), 7.32 KB, created by
Bernardo Gonzalez Kriegel
on 2020-04-16 11:16:09 UTC
(
hide
)
Description:
Bug 24973: Translate locale-syspref.yml
Filename:
MIME Type:
Creator:
Bernardo Gonzalez Kriegel
Created:
2020-04-16 11:16:09 UTC
Size:
7.32 KB
patch
obsolete
>From 91c422401bce8236da500fea0eec58cbb453340b Mon Sep 17 00:00:00 2001 >From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> >Date: Wed, 15 Apr 2020 20:15:51 -0300 >Subject: [PATCH] Bug 24973: Translate locale-syspref.yml > >This patch modifies LangInstaller.pm to >enable translation of the new localized >system preference file. > >This 'translation' is special because it's >used to SET some system preferences, not >just translate some strings. > >The translation .po file is special, with a >structure similar to the syspref translation file. >It adds some comments to guide the translator >in order to put correct values in the translation, >perhaps an explanation will be needed in release notes. > >All new entries are set as 'fuzzy' and have a copy of >the 'en' values as a reference. > >To test: >1) Apply the patch >2) Create translations file for a 'new' language > cd misc/translation > ./translate create xx-YY > > check new file po/xx-YY-locale-prefs.po >3) Update translations > translate some strings on previous file, > remember that those values sets the preference > ./translate update xx-YY > check translations are preserved > >3) Install translations > ./translate install xx-YY > > check new locale-sysprefs.yml file in > installer/data/mysql/xx-YY/ > check 'translated' options > >4) Do a clean install with the new language > Check correct value on sysprefs >--- > misc/translator/LangInstaller.pm | 77 ++++++++++++++++++++++++++++++-- > 1 file changed, 73 insertions(+), 4 deletions(-) > >diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm >index 7b5e23648b..31c90c3059 100644 >--- a/misc/translator/LangInstaller.pm >+++ b/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 <EMAIL\@ADDRESS>\\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 ) { >-- >2.17.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 24973
:
103071
|
103072
|
103073
|
103074
|
103075
|
104971
|
105032
|
108130
|
108166
|
108946