From 348caef43d21e78d19e7c168cf4d964c4a67b91f Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Sat, 29 Aug 2020 20:15:38 +0400 Subject: [PATCH] Bug 25067: Fix translation of system preferences files A previous patch reverted the string extraction mechanism for .pref files but did not update the 'install' part. This patch does just that. --- misc/translator/LangInstaller.pm | 44 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index be51394452..5baddeeccc 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -148,34 +148,33 @@ sub po_filename { } sub get_trans_text { - my ($self, $msgctxt, $msgid) = @_; + my ($self, $msgid, $default) = @_; - my $key = ($msgctxt // '') . ";$msgid"; - - my $po = $self->{po}->{$key}; + my $po = $self->{po}->{Locale::PO->quote($msgid)}; if ($po) { my $msgstr = Locale::PO->dequote($po->msgstr); - - return $msgstr || $msgid; + if ($msgstr and length($msgstr) > 0) { + return $msgstr; + } } - return $msgid; + return $default; } sub get_translated_tab_content { - my ($self, $tab, $tab_content) = @_; + my ($self, $file, $tab_content) = @_; if ( ref($tab_content) eq 'ARRAY' ) { - return $self->get_translated_prefs($tab, $tab_content); + return $self->get_translated_prefs($file, $tab_content); } my $translated_tab_content = { map { my $section = $_; my $sysprefs = $tab_content->{$section}; - my $context = "$tab > $section"; + my $msgid = sprintf('%s %s', $file, $section); - $self->get_trans_text($tab, $section) => $self->get_translated_prefs($context, $sysprefs); + $self->get_trans_text($msgid, $section) => $self->get_translated_prefs($file, $sysprefs); } keys %$tab_content }; @@ -183,7 +182,7 @@ sub get_translated_tab_content { } sub get_translated_prefs { - my ($self, $context, $sysprefs) = @_; + my ($self, $file, $sysprefs) = @_; my $translated_prefs = [ map { @@ -192,7 +191,7 @@ sub get_translated_prefs { my $translated_syspref = [ map { - $self->get_translated_pref("$context > $pref_name", $_ ); + $self->get_translated_pref($file, $pref_name, $_); } @$_ ]; @@ -204,10 +203,12 @@ sub get_translated_prefs { } sub get_translated_pref { - my ($self, $context, $syspref) = @_; + my ($self, $file, $pref_name, $syspref) = @_; unless (ref($syspref)) { - return $self->get_trans_text($context, $syspref // ''); + $syspref //= ''; + my $msgid = sprintf('%s#%s# %s', $file, $pref_name, $syspref); + return $self->get_trans_text($msgid, $syspref); } my $translated_pref = { @@ -219,7 +220,8 @@ sub get_translated_pref { if (($key eq 'choices' || $key eq 'multiple') && ref($value) eq 'HASH') { $translated_value = { map { - $_ => $self->get_trans_text($context, $value->{$_}) + my $msgid = sprintf('%s#%s# %s', $file, $pref_name, $value->{$_}); + $_ => $self->get_trans_text($msgid, $value->{$_}) } keys %$value } } @@ -239,13 +241,7 @@ sub install_prefs { exit; } - my @po_entries = @{ Locale::PO->load_file_asarray($self->po_filename("-pref.po"), 'utf8') }; - $self->{po} = { map { - my $msgctxt = $_->msgctxt ? Locale::PO->dequote($_->msgctxt) : ''; - my $msgid = Locale::PO->dequote($_->msgid); - - "$msgctxt;$msgid" => $_; - } @po_entries }; + $self->{po} = Locale::PO->load_file_ashash($self->po_filename("-pref.po"), 'utf8'); for my $file ( @{$self->{pref_files}} ) { my $pref = LoadFile( $self->{path_pref_en} . "/$file" ); @@ -255,7 +251,7 @@ sub install_prefs { my $tab = $_; my $tab_content = $pref->{$tab}; - $self->get_trans_text(undef, $tab) => $self->get_translated_tab_content($tab, $tab_content); + $self->get_trans_text($file, $tab) => $self->get_translated_tab_content($file, $tab_content); } keys %$pref }; -- 2.20.1