@@ -, +, @@ --- Koha/AuthorisedValue.pm | 22 +++++++++++++++++++--- Koha/Schema/Result/AuthorisedValue.pm | 2 +- t/db_dependent/AuthorisedValues.t | 10 +++++----- 3 files changed, 25 insertions(+), 9 deletions(-) --- a/Koha/AuthorisedValue.pm +++ a/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 --- a/Koha/Schema/Result/AuthorisedValue.pm +++ a/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, }); --- a/t/db_dependent/AuthorisedValues.t +++ a/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' --