Bug 31640: Fuzzy translations of preferences can cause missing sections and inaccurate translations

This patch ignores fuzzy translations for preferences and warns if there are multiple sections with the same translated name.

Test Plan:
1)  Install English United Kingdom translations (./misc/translator/translate install en-GB)
2)  Go to Koha administration in the staff interface
3)  Click Global system preferences
4)  Select I18N/L10N preferences
5)  Enable English United Kingdom in the language preference for staff interface
6)  Save all I18N/L10N preferences
7)  Return to Koha administration
8)  Select English United Kingdom as the language at the bottom of the screen
9)  Click on Global system preferences
10) Select Circulation
11) Observe that there is only SelfCheckInMainUserBlock or StockRotation, but not both
12) Apply the patch
13) Install English United Kingdom translations (./misc/translator/translate install en-GB)
14) Go to Koha administration
15) Select English United Kingdom as the language at the bottom of the screen
16) Click on Global system preferences
17) Select Circulation
18) Observe that SelfCheckInMainUserBlock and StockRotation are both present

Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 5fdc436119)
Signed-off-by: Jacob O'Mara <jacobomara901@gmail.com>
This commit is contained in:
Kevin Carnes 2022-09-28 10:39:30 +02:00 committed by Jacob O'Mara
parent d88a947cd2
commit b37b855638

View file

@ -147,7 +147,7 @@ sub get_trans_text {
my ($self, $msgid, $default) = @_;
my $po = $self->{po}->{Locale::PO->quote($msgid)};
if ($po) {
if ( $po and not defined( $po->fuzzy() ) ) {
my $msgstr = Locale::PO->dequote($po->msgstr);
if ($msgstr and length($msgstr) > 0) {
return $msgstr;
@ -174,6 +174,18 @@ sub get_translated_tab_content {
} keys %$tab_content
};
if ( keys %$translated_tab_content != keys %$tab_content ) {
my %duplicates;
for my $section (keys %$tab_content) {
push @{$duplicates{$self->get_trans_text("$file $section", $section)}}, $section;
}
for my $translation (keys %duplicates) {
if (@{$duplicates{$translation}} > 1) {
warn qq(In file "$file", "$translation" is a translation for sections ") . join('", "', @{$duplicates{$translation}}) . '"';
}
}
}
return $translated_tab_content;
}
@ -251,6 +263,17 @@ sub install_prefs {
} keys %$pref
};
if ( keys %$translated_pref != keys %$pref ) {
my %duplicates;
for my $tab (keys %$pref) {
push @{$duplicates{$self->get_trans_text($file, $tab)}}, $tab;
}
for my $translation (keys %duplicates) {
if (@{$duplicates{$translation}} > 1) {
warn qq(In file "$file", "$translation" is a translation for tabs ") . join('", "', @{$duplicates{$translation}}) . '"';
}
}
}
my $file_trans = $self->{po_path_lang} . "/$file";
print "Write $file\n" if $self->{verbose};