Bugzilla – Attachment 149955 Details for
Bug 24977
Enable translations for authorised values (POC)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24977: Enable translations for authorised values (POC)
Bug-24977-Enable-translations-for-authorised-value.patch (text/plain), 6.79 KB, created by
Jonathan Druart
on 2023-04-20 12:49:28 UTC
(
hide
)
Description:
Bug 24977: Enable translations for authorised values (POC)
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-04-20 12:49:28 UTC
Size:
6.79 KB
patch
obsolete
>From 9b95702e2916ab57ae737faa34d647daaf473500 Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Wed, 25 Mar 2020 15:58:14 +0100 >Subject: [PATCH] Bug 24977: Enable translations for authorised values (POC) >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Only a proof of concept to illustrate what's needed to enable >translation for a new kind of object. > >Only authorised values retrieved with >Koha::AuthorisedValues->get_descriptions_by_koha_field and >Koha::AuthorisedValues->get_description_by_koha_field are translated. >This is used for instance for shelving locations in >catalogue/itemsearch.pl > >Test plan: >1. Run updatedatabase && update_dbix_class_files && reload starman >2. Go to Admin » Localization >3. Find a LOC authorised value and translate it >4. Go to Item search form and verify that it is translated >4. Verify that it is translated in results too > >Requires bug 24975 >--- > Koha/AuthorisedValues.pm | 11 ++-- > Koha/DBIx/Component/L10nSource.pm | 22 ++++---- > Koha/Schema/Result/AuthorisedValue.pm | 53 ++++++++++++++++++- > .../data/mysql/atomicupdate/bug-24977.perl | 12 +++++ > 4 files changed, 85 insertions(+), 13 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug-24977.perl > >diff --git a/Koha/AuthorisedValues.pm b/Koha/AuthorisedValues.pm >index b52c6c79e62..dda7df24a90 100644 >--- a/Koha/AuthorisedValues.pm >+++ b/Koha/AuthorisedValues.pm >@@ -23,6 +23,7 @@ use Modern::Perl; > use Koha::Database; > > use Koha::AuthorisedValue; >+use Koha::I18N; > use Koha::MarcSubfieldStructures; > use Koha::Cache::Memory::Lite; > >@@ -111,7 +112,11 @@ sub get_description_by_koha_field { > > my $av = $self->find_by_koha_field($params); > return {} unless defined $av; >- my $descriptions = { lib => $av->lib, opac_description => $av->opac_description }; >+ my $l10n_group = 'authorised_value:' . $av->category; >+ my $descriptions = { >+ lib => db_t($l10n_group, $av->lib), >+ opac_description => db_t($l10n_group, $av->opac_description), >+ }; > $memory_cache->set_in_cache( $cache_key, $descriptions ); > return $descriptions; > } >@@ -130,8 +135,8 @@ sub get_descriptions_by_koha_field { > my @descriptions = map { > { > authorised_value => $_->authorised_value, >- lib => $_->lib, >- opac_description => $_->opac_description >+ lib => db_t('authorised_value:' . $_->category, $_->lib), >+ opac_description => db_t('authorised_value:' . $_->category, $_->opac_description), > } > } @avs; > $memory_cache->set_in_cache( $cache_key, \@descriptions ); >diff --git a/Koha/DBIx/Component/L10nSource.pm b/Koha/DBIx/Component/L10nSource.pm >index 1a3a4c0a9c4..a8f692f98b6 100644 >--- a/Koha/DBIx/Component/L10nSource.pm >+++ b/Koha/DBIx/Component/L10nSource.pm >@@ -55,15 +55,19 @@ sub update_l10n_source { > $self->result_source->schema->resultset('L10nSource') > ->find( { group => $group, key => $key }, { key => 'group_key' } ); > >- if ($l10n_source_rs) { >- $l10n_source_rs->update( { text => $source_text } ); >- my $l10n_target_rs = $l10n_source_rs->l10n_targets_rs; >- $l10n_target_rs->update( { fuzzy => 1 } ); >- } >- else { >- $l10n_source_rs = >- $self->result_source->schema->resultset('L10nSource') >- ->create( { group => $group, key => $key, text => $source_text } ); >+ if ($source_text) { >+ if ($l10n_source_rs) { >+ $l10n_source_rs->update( { text => $source_text } ); >+ my $l10n_target_rs = $l10n_source_rs->l10n_targets_rs; >+ $l10n_target_rs->update( { fuzzy => 1 } ); >+ } >+ else { >+ $l10n_source_rs = >+ $self->result_source->schema->resultset('L10nSource') >+ ->create( { group => $group, key => $key, text => $source_text } ); >+ } >+ } else { >+ $self->delete_l10n_source($group, $key); > } > } > >diff --git a/Koha/Schema/Result/AuthorisedValue.pm b/Koha/Schema/Result/AuthorisedValue.pm >index 874c166b02a..71d982f0d92 100644 >--- a/Koha/Schema/Result/AuthorisedValue.pm >+++ b/Koha/Schema/Result/AuthorisedValue.pm >@@ -176,6 +176,57 @@ __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 > >+__PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource'); >+ >+sub insert { >+ my $self = shift; >+ >+ my $result = $self->next::method(@_); >+ >+ my $group = sprintf('authorised_value:%s', $self->get_column('category')); >+ $self->update_l10n_source( $group, >+ $self->authorised_value . ':intranet', >+ $self->lib ); >+ $self->update_l10n_source( $group, >+ $self->authorised_value . ':opac', >+ $self->lib_opac ); >+ >+ return $result; >+} >+ >+sub update { >+ my $self = shift; >+ >+ my $is_lib_changed = $self->is_column_changed('lib'); >+ my $is_lib_opac_changed = $self->is_column_changed('lib_opac'); >+ >+ my $result = $self->next::method(@_); >+ >+ my $group = sprintf('authorised_value:%s', $self->get_column('category')); >+ if ($is_lib_changed) { >+ $self->update_l10n_source( $group, >+ $self->authorised_value . ':intranet', >+ $self->lib ); >+ } >+ if ($is_lib_opac_changed) { >+ $self->update_l10n_source( $group, >+ $self->authorised_value . ':opac', >+ $self->lib_opac ); >+ } >+ >+ return $result; >+} >+ >+sub delete { >+ my $self = shift; >+ >+ my $result = $self->next::method(@_); >+ >+ my $group = sprintf('authorised_value:%s', $self->get_column('category')); >+ $self->delete_l10n_source($group, sprintf('%s:intranet', $self->authorised_value)); >+ $self->delete_l10n_source($group, sprintf('%s:opac', $self->authorised_value)); >+ >+ return $result; >+} > >-# You can replace this text with custom code or comments, and it will be preserved on regeneration > 1; >diff --git a/installer/data/mysql/atomicupdate/bug-24977.perl b/installer/data/mysql/atomicupdate/bug-24977.perl >new file mode 100644 >index 00000000000..0b0e5ff8459 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug-24977.perl >@@ -0,0 +1,12 @@ >+$DBversion = 'XXX'; >+if( CheckVersion( $DBversion ) ) { >+ $dbh->do(q{ >+ INSERT IGNORE INTO l10n_source (`group`, `key`, `text`) >+ SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':intranet'), lib FROM authorised_values WHERE lib IS NOT NULL AND lib != '' >+ UNION >+ SELECT DISTINCT CONCAT('authorised_value:', category), CONCAT(authorised_value, ':opac'), lib_opac FROM authorised_values WHERE lib_opac IS NOT NULL AND lib_opac != '' >+ }); >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 24977 - populate l10n_source with authorised_values)\n"; >+} >-- >2.25.1
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 24977
:
101720
|
101797
|
101798
| 149955 |
150037