Bugzilla – Attachment 174597 Details for
Bug 38460
Enable translations for authorised values (alternative)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 38460: [WIP] Enable translations for authorised values (alternative)
Bug-38460-WIP-Enable-translations-for-authorised-v.patch (text/plain), 9.07 KB, created by
Julian Maurice
on 2024-11-15 15:23:27 UTC
(
hide
)
Description:
Bug 38460: [WIP] Enable translations for authorised values (alternative)
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2024-11-15 15:23:27 UTC
Size:
9.07 KB
patch
obsolete
>From cc72655f4d215dd348ae8e53e77496c3cf056eaa Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Fri, 15 Nov 2024 16:12:33 +0100 >Subject: [PATCH] Bug 38460: [WIP] Enable translations for authorised values > (alternative) > >As it's a WIP, not every place shows the translated description. One >place where it works is the items table in the "edit item" page > >Test plan: >1. Edit one of LOC authorised values, you should see links to translate > descriptions (for both staff and opac) > Add translations for a language >2. Switch to this language, if not already done >3. Find a biblio record, edit one of its items and change the > loc field to the value you translated. Save. >4. Now in the table at the top of the page you should see the translated > description >--- > C4/Biblio.pm | 29 +++++++------------ > Koha/AuthorisedValue.pm | 12 ++++++++ > Koha/Schema/Result/AuthorisedValue.pm | 26 +++++++++++++++-- > Koha/Template/Plugin/AuthorisedValues.pm | 6 ++-- > .../data/mysql/atomicupdate/bug-38460.pl | 28 ++++++++++++++++++ > .../en/modules/admin/authorised_values.tt | 3 ++ > 6 files changed, 82 insertions(+), 22 deletions(-) > create mode 100755 installer/data/mysql/atomicupdate/bug-38460.pl > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 6f162e2119..991429a849 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -1502,25 +1502,18 @@ sub GetAuthorisedValueDesc { > > my $dbh = C4::Context->dbh; > if ( $category ne "" ) { >- $cache_key = "AV_descriptions:" . $category; >- my $av_descriptions = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); >- if ( !$av_descriptions ) { >- $av_descriptions = { >- map { >- $_->authorised_value => >- { lib => $_->lib, lib_opac => $_->lib_opac } >- } Koha::AuthorisedValues->search( >- { category => $category }, >- { >- columns => [ 'authorised_value', 'lib_opac', 'lib' ] >- } >- )->as_list >- }; >- $cache->set_in_cache($cache_key, $av_descriptions); >+ my $memory_cache = Koha::Cache::Memory::Lite->get_instance(); >+ my $cache_key = 'GetAuthorisedValueDesc:authorised_values'; >+ my $authorised_values = $memory_cache->get_from_cache($cache_key); >+ unless ($authorised_values) { >+ $authorised_values = { map { $_->authorised_value => $_ } Koha::AuthorisedValues->as_list }; >+ $memory_cache->set_in_cache($cache_key, $authorised_values); > } >- return ( $opac && $av_descriptions->{$value}->{'lib_opac'} ) >- ? $av_descriptions->{$value}->{'lib_opac'} >- : $av_descriptions->{$value}->{'lib'}; >+ my $av = $authorised_values->{$value}; >+ return unless $av; >+ >+ my $lang = C4::Languages::getlanguage(); >+ return $opac ? $av->opac_translated_description : $av->localization('lib', $lang); > } else { > return $value; # if nothing is found return the original value > } >diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm >index 5669ab6086..999f0c45f1 100644 >--- a/Koha/AuthorisedValue.pm >+++ b/Koha/AuthorisedValue.pm >@@ -103,6 +103,18 @@ sub opac_description { > return $self->lib_opac() || $self->lib(); > } > >+=head3 opac_translated_description >+ >+my $description = $av->opac_translated_description($lang); >+ >+=cut >+ >+sub opac_translated_description { >+ my ($self, $lang) = @_; >+ >+ return $self->localization('lib_opac', $lang) || $self->localization('lib', $lang); >+} >+ > =head3 to_api_mapping > > This method returns the mapping for representing a Koha::AuthorisedValue object >diff --git a/Koha/Schema/Result/AuthorisedValue.pm b/Koha/Schema/Result/AuthorisedValue.pm >index 874c166b02..25ce3ae907 100644 >--- a/Koha/Schema/Result/AuthorisedValue.pm >+++ b/Koha/Schema/Result/AuthorisedValue.pm >@@ -142,6 +142,21 @@ __PACKAGE__->has_many( > { cascade_copy => 0, cascade_delete => 0 }, > ); > >+=head2 authorised_values_localizations >+ >+Type: has_many >+ >+Related object: L<Koha::Schema::Result::AuthorisedValuesLocalization> >+ >+=cut >+ >+__PACKAGE__->has_many( >+ "authorised_values_localizations", >+ "Koha::Schema::Result::AuthorisedValuesLocalization", >+ { "foreign.authorised_value_id" => "self.id" }, >+ { cascade_copy => 0, cascade_delete => 0 }, >+); >+ > =head2 category > > Type: belongs_to >@@ -173,9 +188,16 @@ __PACKAGE__->has_many( > ); > > >-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 >-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LH9dpEEzlVVsjNVv/jnONg >+# Created by DBIx::Class::Schema::Loader v0.07052 @ 2024-11-15 16:11:15 >+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mlwkraQyS4N5mlE7J5g7qQ > >+__PACKAGE__->load_components('+Koha::Schema::Component::Localization'); >+__PACKAGE__->localization_add_relationships( >+ 'authorised_values_localizations', >+ 'authorised_value_id' => 'id', >+ 'lib', >+ 'lib_opac', >+); > > # You can replace this text with custom code or comments, and it will be preserved on regeneration > 1; >diff --git a/Koha/Template/Plugin/AuthorisedValues.pm b/Koha/Template/Plugin/AuthorisedValues.pm >index 4e74c1bbad..7f9fe53189 100644 >--- a/Koha/Template/Plugin/AuthorisedValues.pm >+++ b/Koha/Template/Plugin/AuthorisedValues.pm >@@ -22,15 +22,17 @@ use Template::Plugin; > use base qw( Template::Plugin ); > > use C4::Koha qw( GetAuthorisedValues ); >+use C4::Languages; > use Koha::AuthorisedValues; > > sub GetByCode { > my ( $self, $category, $code, $opac ) = @_; > my $av = Koha::AuthorisedValues->search({ category => $category, authorised_value => $code }); >+ my $lang = C4::Languages::getlanguage(); > return $av->count > ? $opac >- ? $av->next->opac_description >- : $av->next->lib >+ ? $av->next->opac_translated_description($lang) >+ : $av->next->localization('lib', $lang) > : $code; > } > >diff --git a/installer/data/mysql/atomicupdate/bug-38460.pl b/installer/data/mysql/atomicupdate/bug-38460.pl >new file mode 100755 >index 0000000000..6e9ab64860 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug-38460.pl >@@ -0,0 +1,28 @@ >+use Modern::Perl; >+use Koha::Installer::Output qw(say_warning say_failure say_success say_info); >+ >+return { >+ bug_number => '38460', >+ description => 'Add authorised_values_localizations table', >+ up => sub { >+ my ($args) = @_; >+ my ( $dbh, $out ) = @$args{qw(dbh out)}; >+ >+ unless ( TableExists('authorised_values_localizations') ) { >+ $dbh->do( " >+ CREATE TABLE `authorised_values_localizations` ( >+ `authorised_values_localizations_id` int(11) NOT NULL AUTO_INCREMENT, >+ `authorised_value_id` int(11) NOT NULL, >+ `property` varchar(100) NOT NULL, >+ `lang` varchar(25) NOT NULL, >+ `translation` mediumtext DEFAULT NULL, >+ PRIMARY KEY (`authorised_values_localizations_id`), >+ UNIQUE KEY `authorised_value_id_property_lang` (`authorised_value_id`, `property`, `lang`), >+ CONSTRAINT `authorised_values_localizations_authorised_value_id_fk` >+ FOREIGN KEY (`authorised_value_id`) REFERENCES `authorised_values` (`id`) >+ ON DELETE CASCADE ON UPDATE CASCADE >+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+ " ); >+ } >+ }, >+}; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >index 2bfb4f3f7f..06c8b71590 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/authorised_values.tt >@@ -180,10 +180,12 @@ > <li> > <label for="lib">Description: </label> > <input type="text" name="lib" id="lib" value="[% av.lib | html %]" maxlength="200" /> >+ [% INCLUDE 'localization-link.inc' source='AuthorisedValue' object_id=av.id property='lib' %] > </li> > <li> > <label for="lib_opac">Description (OPAC): </label> > <input type="text" name="lib_opac" id="lib_opac" value="[% av.lib_opac | html %]" maxlength="200" /> >+ [% INCLUDE 'localization-link.inc' source='AuthorisedValue' object_id=av.id property='lib_opac' %] > </li> > <li><label for="branches">Library limitations: </label> > <select id="branches" name="branches" multiple size="10"> >@@ -403,6 +405,7 @@ > [% Asset.js("js/admin-menu.js") | $raw %] > [% INCLUDE 'datatables.inc' %] > [% INCLUDE 'columns_settings.inc' %] >+ [% INCLUDE 'greybox.inc' %] > <script> > $(document).ready(function() { > >-- >2.39.2
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 38460
:
174597
|
174600
|
174601