From c5ba385e4397c8c162e9d7d49ec90011b4474ebb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 20 Mar 2020 11:54:15 +0100 Subject: [PATCH] Bug 20307: Replace separator with # To avoid colision we replace the separator with something that is supposed to be less used than underscore The problematic case was explaing by Julian on comment 96: """ The value stored in localization.code is a concatenation of the AV category code, a '_', and the AV code. Which means that if we have a category A with a value B_C, and a category A_B with a value C, they will share their translations. """ --- Koha/AuthorisedValue.pm | 22 +++++++++++++++++++--- Koha/Schema/Result/AuthorisedValue.pm | 2 +- t/db_dependent/AuthorisedValues.t | 10 +++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index a16e58f90c..671e26b9a2 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -71,7 +71,7 @@ sub opac_translated_description { return $self->translated_description unless $self->lib_opac; my $translated_description = Koha::Localizations->search({ - code => sprintf( "%s_%s", $self->category, $self->authorised_value ), + code => $self->build_code, entity => 'authorised_values', lang => $lang, interface => 'opac', @@ -97,7 +97,7 @@ sub translated_description { } $lang ||= C4::Languages::getlanguage; my $translated_description = Koha::Localizations->search({ - code => sprintf( "%s_%s", $self->category, $self->authorised_value ), + code => $self->build_code, entity => 'authorised_values', lang => $lang, })->next; @@ -114,7 +114,7 @@ sub translated_descriptions { my ( $self ) = @_; my @translated_descriptions = Koha::Localizations->search( { entity => 'authorised_values', - code => sprintf( "%s_%s", $self->category, $self->authorised_value ), + code => $self->build_code, } ); return [ map { @@ -134,6 +134,22 @@ sub image_location { return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl ); } +=head3 build_code + +my $code = $av->build_code; + +Return the "code" used by the translation mecanism to identify a row. +It is a concatenation of category and authorised_value. + +Note that is is also used in Koha/Schema/Result/AuthorisedValue.pm + +=cut + +sub build_code { + my ( $self ) = @_; + return sprintf "%s#%s", $self->category, $self->authorised_value; +} + =head3 _type =cut diff --git a/Koha/Schema/Result/AuthorisedValue.pm b/Koha/Schema/Result/AuthorisedValue.pm index e6a9b1bfa0..e42d388cf6 100644 --- a/Koha/Schema/Result/AuthorisedValue.pm +++ b/Koha/Schema/Result/AuthorisedValue.pm @@ -159,7 +159,7 @@ __PACKAGE__->has_many( die "no interface specified!" unless $INTERFACE; return ({ - "$args->{foreign_alias}.code" => \["= CONCAT(me.category, '_', me.authorised_value)"], + "$args->{foreign_alias}.code" => \["= CONCAT(me.category, '#', me.authorised_value)"], "$args->{foreign_alias}.lang" => $LANGUAGE, "$args->{foreign_alias}.interface" => $INTERFACE, }); diff --git a/t/db_dependent/AuthorisedValues.t b/t/db_dependent/AuthorisedValues.t index a8c29341f7..6702267d5e 100644 --- a/t/db_dependent/AuthorisedValues.t +++ b/t/db_dependent/AuthorisedValues.t @@ -259,7 +259,7 @@ subtest "localization" => sub { Koha::Localization->new( { entity => 'authorised_values', - code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), + code => $av1->build_code, lang => 'es-ES', interface => 'intranet', translation => 'traducción 1' @@ -268,7 +268,7 @@ subtest "localization" => sub { Koha::Localization->new( { entity => 'authorised_values', - code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), + code => $av1->build_code, lang => 'es-ES', interface => 'opac', translation => 'opac traducción 1' @@ -277,7 +277,7 @@ subtest "localization" => sub { Koha::Localization->new( { entity => 'authorised_values', - code => sprintf( "%s_%s", $av1->category, $av2->authorised_value ), + code => $av2->build_code, lang => 'es-ES', interface => 'intranet', translation => 'traducción 2' @@ -287,7 +287,7 @@ subtest "localization" => sub { Koha::Localization->new( { entity => 'authorised_values', - code => sprintf( "%s_%s", $av1->category, $av1->authorised_value ), + code => $av1->build_code, lang => 'fr-FR', interface => 'intranet', translation => 'traduction 1' @@ -296,7 +296,7 @@ subtest "localization" => sub { Koha::Localization->new( { entity => 'authorised_values', - code => sprintf( "%s_%s", $av2->category, $av2->authorised_value ), + code => $av2->build_code, lang => 'de-DE', interface => 'intranet', translation => 'Übersetzung 2' -- 2.20.1