@@ -, +, @@ db_t('itemtype', $itemtype->description) [% ItemTypes.t(itemtype.description) %] itemtypes. Translations should be kept by the updatedatabase script. Before applying the updatedatabase you may want to comment the 'DROP TABLE localization' statement if you want to keep this table and reload starman their translations. only). entering some text and clicking on the 'Save' button. You can remove a translation by emptying the text box. description appears in Localization page and that the old description is gone appears in Localization page verify that item types are translated (if not, please verify in master too, not all occurrences were translated) --- C4/Biblio.pm | 3 +- C4/Items.pm | 11 +- C4/Search.pm | 11 +- Koha/DBIx/Component/L10nSource.pm | 73 ++++ Koha/I18N.pm | 49 +++ Koha/ItemType.pm | 45 --- Koha/ItemTypes.pm | 31 -- Koha/Localization.pm | 28 -- Koha/Localizations.pm | 34 -- Koha/Schema/Result/Itemtype.pm | 54 ++- Koha/Schema/Result/ItemtypeLocalization.pm | 32 -- Koha/Schema/Result/Localization.pm | 106 ----- Koha/Template/Plugin/ItemTypes.pm | 11 +- acqui/orderreceive.pl | 3 +- admin/itemtypes.pl | 3 - admin/localization.pl | 20 - admin/smart-rules.pl | 32 +- authorities/authorities.pl | 5 +- catalogue/getitem-ajax.pl | 3 +- catalogue/itemsearch.pl | 3 +- catalogue/moredetail.pl | 7 +- catalogue/search.pl | 31 +- cataloguing/addbiblio.pl | 5 +- cataloguing/additem.pl | 7 +- circ/transferstoreceive.pl | 3 +- course_reserves/add_items.pl | 2 +- .../data/mysql/atomicupdate/bug-24975.perl | 48 +++ installer/data/mysql/kohastructure.sql | 33 +- .../prog/en/includes/admin-menu.inc | 1 + .../prog/en/includes/html_helpers.inc | 3 +- .../prog/en/modules/admin/admin-home.tt | 2 + .../prog/en/modules/admin/itemtypes.tt | 20 +- .../prog/en/modules/admin/localization.tt | 369 ++++++------------ .../prog/en/modules/admin/smart-rules.tt | 6 +- .../prog/en/modules/catalogue/advsearch.tt | 3 +- .../prog/en/modules/catalogue/detail.tt | 5 +- .../course_reserves/add_items-step2.tt | 5 +- .../course_reserves/batch_add_items.tt | 2 +- .../en/modules/reports/acquisitions_stats.tt | 3 +- .../prog/en/modules/reports/bor_issues_top.tt | 2 +- .../prog/en/modules/reports/cat_issues_top.tt | 3 +- .../prog/en/modules/reports/catalogue_out.tt | 3 +- .../en/modules/reports/catalogue_stats.tt | 3 +- .../en/modules/reports/issues_avg_stats.tt | 3 +- .../prog/en/modules/reports/issues_stats.tt | 3 +- .../prog/en/modules/reports/itemslost.tt | 2 +- .../prog/en/modules/reports/reserves_stats.tt | 3 +- .../en/modules/serials/subscription-add.tt | 9 +- .../modules/serials/subscription-batchedit.tt | 2 +- .../serials/subscription-bib-search.tt | 3 +- .../prog/en/modules/tools/export.tt | 3 +- .../prog/en/modules/virtualshelves/shelves.tt | 3 +- .../bootstrap/en/includes/opac-topissues.inc | 3 +- .../en/modules/opac-readingrecord.tt | 3 +- .../bootstrap/en/modules/opac-reserve.tt | 4 +- .../bootstrap/en/modules/opac-shelves.tt | 5 +- labels/label-item-search.pl | 13 - opac/opac-detail.pl | 9 +- opac/opac-readingrecord.pl | 5 +- opac/opac-reserve.pl | 8 +- opac/opac-search.pl | 14 +- opac/opac-shelves.pl | 2 +- opac/opac-user.pl | 2 +- reports/acquisitions_stats.pl | 2 +- reports/bor_issues_top.pl | 2 +- reports/cat_issues_top.pl | 2 +- reports/catalogue_out.pl | 2 +- reports/catalogue_stats.pl | 2 +- reports/issues_avg_stats.pl | 2 +- reports/issues_stats.pl | 7 +- reports/itemslost.pl | 2 +- reports/reserves_stats.pl | 5 +- reserve/request.pl | 2 +- serials/subscription-add.pl | 3 +- serials/subscription-bib-search.pl | 3 +- svc/bib_profile | 2 +- svc/checkouts | 7 +- svc/holds | 3 +- svc/localization | 129 +++--- svc/split_callnumbers | 72 ---- t/db_dependent/Koha/ItemTypes.t | 35 +- tools/batchMod.pl | 5 +- tools/export.pl | 2 +- virtualshelves/shelves.pl | 2 +- 84 files changed, 583 insertions(+), 930 deletions(-) create mode 100644 Koha/DBIx/Component/L10nSource.pm delete mode 100644 Koha/Localization.pm delete mode 100644 Koha/Localizations.pm delete mode 100644 Koha/Schema/Result/ItemtypeLocalization.pm delete mode 100644 Koha/Schema/Result/Localization.pm create mode 100644 installer/data/mysql/atomicupdate/bug-24975.perl --- a/C4/Biblio.pm +++ a/C4/Biblio.pm @@ -101,6 +101,7 @@ use Koha::Authority::Types; use Koha::Acquisition::Currencies; use Koha::Biblio::Metadatas; use Koha::Holds; +use Koha::I18N; use Koha::ItemTypes; use Koha::Plugins; use Koha::SearchEngine; @@ -1383,7 +1384,7 @@ sub GetAuthorisedValueDesc { #---- itemtypes if ( $tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { my $itemtype = Koha::ItemTypes->find( $value ); - return $itemtype ? $itemtype->translated_description : q||; + return $itemtype ? db_t('itemtype', $itemtype->description) : q||; } #---- "true" authorized value --- a/C4/Items.pm +++ a/C4/Items.pm @@ -67,6 +67,7 @@ use Koha::DateUtils qw(dt_from_string); use Koha::Database; use Koha::Biblioitems; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; use Koha::SearchEngine; @@ -668,7 +669,6 @@ sub GetItemsInfo { serial.serialseq, serial.publisheddate, itemtypes.description, - COALESCE( localization.translation, itemtypes.description ) AS translated_description, itemtypes.notforloan as notforloan_per_itemtype, holding.branchurl, holding.branchcode, @@ -689,14 +689,11 @@ sub GetItemsInfo { . (C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype'); $query .= q| LEFT JOIN tmp_holdsqueue USING (itemnumber) - LEFT JOIN localization ON itemtypes.itemtype = localization.code - AND localization.entity = 'itemtypes' - AND localization.lang = ? |; $query .= " WHERE items.biblionumber = ? ORDER BY home.branchname, items.enumchron, LPAD( items.copynumber, 8, '0' ), items.dateaccessioned DESC" ; my $sth = $dbh->prepare($query); - $sth->execute($language, $biblionumber); + $sth->execute($biblionumber); my $i = 0; my @results; my $serial; @@ -1667,12 +1664,12 @@ sub PrepareItemrecordDisplay { #----- itemtypes } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; push @authorised_values, "" unless ( $tagslib->{$tag}->{$subfield}->{mandatory} ); while ( my $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->description); } if ($defaultvalues && $defaultvalues->{'itemtype'}) { $defaultvalue = $defaultvalues->{'itemtype'}; --- a/C4/Search.pm +++ a/C4/Search.pm @@ -30,6 +30,7 @@ use C4::Reserves; # GetReserveStatus use C4::Debug; use C4::Charset; use Koha::AuthorisedValues; +use Koha::I18N; use Koha::ItemTypes; use Koha::Libraries; use Koha::Patrons; @@ -539,9 +540,7 @@ sub getRecords { && ref( $itemtypes->{$one_facet} ) eq "HASH" ) { - $facet_label_value = - $itemtypes->{$one_facet} - ->{translated_description}; + $facet_label_value = db_t('itemtype', $itemtypes->{$one_facet}->{description}); } } @@ -1704,7 +1703,7 @@ sub searchResults { my $notforloan_authorised_value = $av->count ? $av->next->authorised_value : undef; #Get itemtype hash - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; my %itemtypes = map { $_->{itemtype} => $_ } @{ $itemtypes->unblessed }; #search item field code @@ -1797,7 +1796,7 @@ sub searchResults { # add imageurl to itemtype if there is one $oldbiblio->{imageurl} = $itemtype ? getitemtypeimagelocation( $search_context->{'interface'}, $itemtype->{imageurl} ) : q{}; # Build summary if there is one (the summary is defined in the itemtypes table) - $oldbiblio->{description} = $itemtype ? $itemtype->{translated_description} : q{}; + $oldbiblio->{description} = $itemtype ? db_t('itemtype', $itemtype->{description}) : q{}; # FIXME: this is only used in the deprecated non-XLST opac results if ( !$xslfile && $is_opac && $itemtype && $itemtype->{summary} ) { @@ -1906,7 +1905,7 @@ sub searchResults { foreach my $code ( keys %subfieldstosearch ) { $item->{$code} = $field->subfield( $subfieldstosearch{$code} ); } - $item->{description} = $itemtypes{ $item->{itype} }{translated_description} if $item->{itype}; + $item->{description} = db_t('itemtype', $itemtypes{ $item->{itype} }{description}) if $item->{itype}; # OPAC hidden items if ($is_opac) { --- a/Koha/DBIx/Component/L10nSource.pm +++ a/Koha/DBIx/Component/L10nSource.pm @@ -0,0 +1,73 @@ +package Koha::DBIx::Component::L10nSource; + +use Modern::Perl; +use base 'DBIx::Class'; + +=head1 NAME + +Koha::DBIx::Component::L10nSource + +=head1 SYNOPSIS + + __PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource') + + sub insert { + my $self = shift; + my $result = $self->next::method(@_); + my @sources = $self->result_source->resultset->get_column('label')->all; + $self->update_l10n_source('somecontext', @sources); + return $result; + } + + sub update { + my $self = shift; + my $is_column_changed = $self->is_column_changed('label'); + my $result = $self->next::method(@_); + if ($is_column_changed) { + my @sources = $self->result_source->resultset->get_column('label')->all; + $self->update_l10n_source('somecontext', @sources); + } + return $result; + } + + sub delete { + my $self = shift; + my $result = $self->next::method(@_); + my @sources = $self->result_source->resultset->get_column('label')->all; + $self->update_l10n_source('somecontext', @sources); + return $result; + } + +=head1 METHODS + +=head2 update_l10n_source + + $self->update_l10n_source($context, @sources) + +Ensure that all sources in C<@sources>and only them are present in l10n_source +for a given C<$context> + +=cut + +sub update_l10n_source { + my ($self, $context, @sources) = @_; + + my $l10n_source_rs = $self->result_source->schema->resultset('L10nSource')->search({ context => $context }); + + # Insert missing l10n_source rows + foreach my $source (@sources) { + my $count = $l10n_source_rs->search({ source => $source })->count; + if ($count == 0) { + $l10n_source_rs->create({ source => $source }); + } + } + + # Remove l10n_source rows that do not match an existing source + my %sources = map { $_ => undef } @sources; + my @l10n_sources = grep { !exists $sources{$_->source} } $l10n_source_rs->all; + foreach my $l10n_source (@l10n_sources) { + $l10n_source->delete; + } +} + +1; --- a/Koha/I18N.pm +++ a/Koha/I18N.pm @@ -27,6 +27,8 @@ use Encode; use Locale::Messages qw(:locale_h LC_MESSAGES); use POSIX qw( setlocale ); use Koha::Cache::Memory::Lite; +use Koha::Caches; +use Koha::Database; use parent 'Exporter'; our @EXPORT = qw( @@ -43,6 +45,8 @@ our @EXPORT = qw( N__n N__p N__np + + db_t ); our $textdomain = 'Koha'; @@ -201,4 +205,49 @@ sub _expand { return $text; } +=head2 db_t + + db_t($context, $source) + db_t('itemtype', $itemtype->description) + +Search for a translation in l10n_target table and return it if found +Return source string otherwise + +=cut + +sub db_t { + my ($context, $source) = @_; + + my $cache = Koha::Caches->get_instance(); + my $language = C4::Languages::getlanguage(); + my $cache_key = sprintf('%s:%s', $context, $language); + + my $translations = $cache->get_from_cache($cache_key); + unless ($translations) { + my $schema = Koha::Database->new->schema; + my $rs = $schema->resultset('L10nTarget'); + + my @targets = $rs->search( + { + 'l10n_source.context' => $context, + language => $language, + }, + { + join => 'l10n_source', + prefetch => 'l10n_source', + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + }, + ); + $translations = { map { $_->{l10n_source}->{source} => $_->{translation} } @targets }; + + $cache->set_in_cache($cache_key, $translations); + } + + if (exists $translations->{$source}) { + return $translations->{$source}; + } + + return $source; +} + 1; --- a/Koha/ItemType.pm +++ a/Koha/ItemType.pm @@ -23,7 +23,6 @@ use C4::Koha; use C4::Languages; use Koha::Database; use Koha::CirculationRules; -use Koha::Localizations; use base qw(Koha::Object Koha::Object::Limit::Library); @@ -46,50 +45,6 @@ sub image_location { return C4::Koha::getitemtypeimagelocation( $interface, $self->SUPER::imageurl ); } -=head3 translated_description - -=cut - -sub translated_description { - my ( $self, $lang ) = @_; - if ( my $translated_description = eval { $self->get_column('translated_description') } ) { - # If the value has already been fetched (eg. from sarch_with_localization), - # do not search for it again - # Note: This is a bit hacky but should be fast - return $translated_description - ? $translated_description - : $self->description; - } - $lang ||= C4::Languages::getlanguage; - my $translated_description = Koha::Localizations->search({ - code => $self->itemtype, - entity => 'itemtypes', - lang => $lang - })->next; - return $translated_description - ? $translated_description->translation - : $self->description; -} - -=head3 translated_descriptions - -=cut - -sub translated_descriptions { - my ( $self ) = @_; - my @translated_descriptions = Koha::Localizations->search( - { entity => 'itemtypes', - code => $self->itemtype, - } - ); - return [ map { - { - lang => $_->lang, - translation => $_->translation, - } - } @translated_descriptions ]; -} - =head3 can_be_deleted my $can_be_deleted = Koha::ItemType->can_be_deleted(); --- a/Koha/ItemTypes.pm +++ a/Koha/ItemTypes.pm @@ -32,37 +32,6 @@ Koha::ItemTypes - Koha ItemType Object set class =head1 API -=head2 Class methods - -=cut - -=head3 search_with_localization - -my $itemtypes = Koha::ItemTypes->search_with_localization - -=cut - -sub search_with_localization { - my ( $self, $params, $attributes ) = @_; - - my $language = C4::Languages::getlanguage(); - $Koha::Schema::Result::Itemtype::LANGUAGE = $language; - $attributes->{order_by} = 'translated_description' unless exists $attributes->{order_by}; - $attributes->{join} = 'localization'; - $attributes->{'+select'} = [ - { - coalesce => [qw( localization.translation me.description )], - -as => 'translated_description' - } - ]; - if(defined $params->{branchcode}) { - my $branchcode = delete $params->{branchcode}; - $self->search_with_library_limits( $params, $attributes, $branchcode ); - } else { - $self->SUPER::search( $params, $attributes ); - } -} - =head2 Internal methods =head3 type --- a/Koha/Localization.pm +++ a/Koha/Localization.pm @@ -1,28 +0,0 @@ -package Koha::Localization; - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; - -use Koha::Database; - -use base qw(Koha::Object); - -sub _type { - return 'Localization'; -} - -1; --- a/Koha/Localizations.pm +++ a/Koha/Localizations.pm @@ -1,34 +0,0 @@ -package Koha::Localizations; - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 3 of the License, or -# (at your option) any later version. -# -# Koha is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Koha; if not, see . - -use Modern::Perl; - -use Koha::Database; - -use Koha::Localization; - -use base qw(Koha::Objects); - -sub _type { - return 'Localization'; -} - -sub object_class { - return 'Koha::Localization'; -} - -1; --- a/Koha/Schema/Result/Itemtype.pm +++ a/Koha/Schema/Result/Itemtype.pm @@ -230,22 +230,7 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07048 @ 2019-07-04 04:56:48 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Qo6jabJSQGeYJ542ebSJfg -# Use the ItemtypeLocalization view to create the join on localization -our $LANGUAGE; -__PACKAGE__->has_many( - "localization" => "Koha::Schema::Result::ItemtypeLocalization", - sub { - my $args = shift; - - die "no lang specified!" unless $LANGUAGE; - - return ({ - "$args->{self_alias}.itemtype" => { -ident => "$args->{foreign_alias}.code" }, - "$args->{foreign_alias}.lang" => $LANGUAGE, - }); - - } -); +__PACKAGE__->load_components('+Koha::DBIx::Component::L10nSource'); sub koha_object_class { 'Koha::ItemType'; @@ -254,4 +239,41 @@ sub koha_objects_class { 'Koha::ItemTypes'; } +sub insert { + my $self = shift; + + my $result = $self->next::method(@_); + + my @sources = $self->result_source->resultset->get_column('description')->all; + $self->update_l10n_source('itemtype', @sources); + + return $result; +} + +sub update { + my $self = shift; + + my $is_description_changed = $self->is_column_changed('description'); + + my $result = $self->next::method(@_); + + if ($is_description_changed) { + my @sources = $self->result_source->resultset->get_column('description')->all; + $self->update_l10n_source('itemtype', @sources); + } + + return $result; +} + +sub delete { + my $self = shift; + + my $result = $self->next::method(@_); + + my @sources = $self->result_source->resultset->get_column('description')->all; + $self->update_l10n_source('itemtype', @sources); + + return $result; +} + 1; --- a/Koha/Schema/Result/ItemtypeLocalization.pm +++ a/Koha/Schema/Result/ItemtypeLocalization.pm @@ -1,32 +0,0 @@ -package Koha::Schema::Result::ItemtypeLocalization; - -use base 'DBIx::Class::Core'; - -use Modern::Perl; - -__PACKAGE__->table_class('DBIx::Class::ResultSource::View'); - -__PACKAGE__->table('itemtype_localizations'); -__PACKAGE__->result_source_instance->is_virtual(1); -__PACKAGE__->result_source_instance->view_definition( - "SELECT localization_id, code, lang, translation FROM localization WHERE entity='itemtypes'" -); - -__PACKAGE__->add_columns( - "localization_id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "code", - { data_type => "varchar", is_nullable => 0, size => 64 }, - "lang", - { data_type => "varchar", is_nullable => 0, size => 25 }, - "translation", - { data_type => "text", is_nullable => 1 }, -); - -__PACKAGE__->belongs_to( - "itemtype", - "Koha::Schema::Result::Itemtype", - { code => 'itemtype' } -); - -1; --- a/Koha/Schema/Result/Localization.pm +++ a/Koha/Schema/Result/Localization.pm @@ -1,106 +0,0 @@ -use utf8; -package Koha::Schema::Result::Localization; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Koha::Schema::Result::Localization - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("localization"); - -=head1 ACCESSORS - -=head2 localization_id - - data_type: 'integer' - is_auto_increment: 1 - is_nullable: 0 - -=head2 entity - - data_type: 'varchar' - is_nullable: 0 - size: 16 - -=head2 code - - data_type: 'varchar' - is_nullable: 0 - size: 64 - -=head2 lang - - data_type: 'varchar' - is_nullable: 0 - size: 25 - -=head2 translation - - data_type: 'mediumtext' - is_nullable: 1 - -=cut - -__PACKAGE__->add_columns( - "localization_id", - { data_type => "integer", is_auto_increment => 1, is_nullable => 0 }, - "entity", - { data_type => "varchar", is_nullable => 0, size => 16 }, - "code", - { data_type => "varchar", is_nullable => 0, size => 64 }, - "lang", - { data_type => "varchar", is_nullable => 0, size => 25 }, - "translation", - { data_type => "mediumtext", is_nullable => 1 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("localization_id"); - -=head1 UNIQUE CONSTRAINTS - -=head2 C - -=over 4 - -=item * L - -=item * L - -=item * L - -=back - -=cut - -__PACKAGE__->add_unique_constraint("entity_code_lang", ["entity", "code", "lang"]); - - -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-02-16 17:54:54 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4642LmshpGd3JW7YxM5pIA - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; --- a/Koha/Template/Plugin/ItemTypes.pm +++ a/Koha/Template/Plugin/ItemTypes.pm @@ -22,16 +22,23 @@ use Modern::Perl; use Template::Plugin; use base qw( Template::Plugin ); +use Koha::I18N; use Koha::ItemTypes; sub GetDescription { my ( $self, $itemtypecode ) = @_; my $itemtype = Koha::ItemTypes->find( $itemtypecode ); - return $itemtype ? $itemtype->translated_description : q{}; + return $itemtype ? $self->t($itemtype->description) : q{}; } sub Get { - return Koha::ItemTypes->search_with_localization->unblessed; + return Koha::ItemTypes->search->unblessed; +} + +sub t { + my ($self, $description) = @_; + + return db_t('itemtype', $description); } 1; --- a/acqui/orderreceive.pl +++ a/acqui/orderreceive.pl @@ -76,6 +76,7 @@ use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::Acquisition::Orders; use Koha::DateUtils qw( dt_from_string ); +use Koha::I18N; use Koha::ItemTypes; use Koha::Patrons; @@ -153,7 +154,7 @@ if ($AcqCreateItem eq 'receiving') { my $itemtype = Koha::ItemTypes->find($i->effective_itemtype); if (defined $itemtype) { # We should not do that here, but call ->itemtype->description when needed instead - $item->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description? + $item->{itemtype} = db_t('itemtype', $itemtype->description); } push @items, $item; } --- a/admin/itemtypes.pl +++ a/admin/itemtypes.pl @@ -33,7 +33,6 @@ use C4::Auth; use C4::Output; use Koha::ItemTypes; use Koha::ItemType; -use Koha::Localizations; my $input = new CGI; my $searchfield = $input->param('description'); @@ -73,12 +72,10 @@ if ( $op eq 'add_form' ) { my $imagesets = C4::Koha::getImageSets( checked => ( $itemtype ? $itemtype->imageurl : undef ) ); my $searchcategory = GetAuthorisedValues("ITEMTYPECAT"); - my $translated_languages = C4::Languages::getTranslatedLanguages( undef , C4::Context->preference('template') ); $template->param( itemtype => $itemtype, imagesets => $imagesets, searchcategory => $searchcategory, - can_be_translated => ( scalar(@$translated_languages) > 1 ? 1 : 0 ), branches_loop => \@branches_loop, ); } elsif ( $op eq 'add_validate' ) { --- a/admin/localization.pl +++ a/admin/localization.pl @@ -21,9 +21,6 @@ use Modern::Perl; use C4::Auth; use C4::Output; -use Koha::Localization; -use Koha::Localizations; - use CGI qw( -utf8 ); my $query = new CGI; @@ -38,27 +35,10 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( } ); -my $entity = $query->param('entity'); -my $code = $query->param('code'); -my $rs = Koha::Localizations->search( { entity => $entity, code => $code } ); -my @translations; -while ( my $s = $rs->next ) { - push @translations, - { id => $s->localization_id, - entity => $s->entity, - code => $s->code, - lang => $s->lang, - translation => $s->translation, - }; -} - my $translated_languages = C4::Languages::getTranslatedLanguages( 'intranet', C4::Context->preference('template') ); $template->param( - translations => \@translations, languages => $translated_languages, - entity => $entity, - code => $code, ); output_html_with_http_headers $query, $cookie, $template->output; --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -556,7 +556,7 @@ $template->param( my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] }); -my $itemtypes = Koha::ItemTypes->search_with_localization; +my $itemtypes = Koha::ItemTypes->search; my $humanbranch = ( $branch ne '*' ? $branch : undef ); @@ -583,36 +583,6 @@ output_html_with_http_headers $input, $cookie, $template->output; exit 0; -# sort by patron category, then item type, putting -# default entries at the bottom -sub by_category_and_itemtype { - unless (by_category($a, $b)) { - return by_itemtype($a, $b); - } -} - -sub by_category { - my ($a, $b) = @_; - if ($a->{'default_humancategorycode'}) { - return ($b->{'default_humancategorycode'} ? 0 : 1); - } elsif ($b->{'default_humancategorycode'}) { - return -1; - } else { - return $a->{'humancategorycode'} cmp $b->{'humancategorycode'}; - } -} - -sub by_itemtype { - my ($a, $b) = @_; - if ($a->{default_translated_description}) { - return ($b->{'default_translated_description'} ? 0 : 1); - } elsif ($b->{'default_translated_description'}) { - return -1; - } else { - return lc $a->{'translated_description'} cmp lc $b->{'translated_description'}; - } -} - sub strip_non_numeric { my $string = shift; $string =~ s/\s//g; --- a/authorities/authorities.pl +++ a/authorities/authorities.pl @@ -33,6 +33,7 @@ use MARC::File::XML; use C4::Biblio; use Koha::Authority::Types; use Koha::ItemTypes; +use Koha::I18N; use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); @@ -92,10 +93,10 @@ sub build_authorized_values_list { && ( $value || $tagslib->{$tag}->{$subfield}->{defaultvalue} ) ); my $itemtype; - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; while ( $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->description); } $value = $itemtype unless ($value); --- a/catalogue/getitem-ajax.pl +++ a/catalogue/getitem-ajax.pl @@ -29,6 +29,7 @@ use C4::Output; use Koha::Libraries; use Koha::AuthorisedValues; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; @@ -77,7 +78,7 @@ if($itemnumber) { my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); # We should not do that here, but call ->itemtype->description when needed instea - $item_unblessed->{itemtype} = $itemtype->description; # FIXME Should not it be translated_description? + $item_unblessed->{itemtype} = db_t('itemtype', $itemtype->description); } my $json_text = to_json( $item_unblessed, { utf8 => 1 } ); --- a/catalogue/itemsearch.pl +++ a/catalogue/itemsearch.pl @@ -29,6 +29,7 @@ use C4::Koha; use Koha::AuthorisedValues; use Koha::Biblios; +use Koha::I18N; use Koha::Item::Search::Field qw(GetItemSearchFields); use Koha::ItemTypes; use Koha::Libraries; @@ -259,7 +260,7 @@ my @itemtypes; foreach my $itemtype ( Koha::ItemTypes->search ) { push @itemtypes, { value => $itemtype->itemtype, - label => $itemtype->translated_description, + label => db_t('itemtype', $itemtype->description), }; } --- a/catalogue/moredetail.pl +++ a/catalogue/moredetail.pl @@ -37,6 +37,7 @@ use Koha::Biblios; use Koha::DateUtils; use Koha::Items; use Koha::Patrons; +use Koha::I18N; my $query=new CGI; @@ -132,9 +133,9 @@ my $ccodes = my $copynumbers = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) }; -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; -$data->{'itemtypename'} = $itemtypes->{ $data->{'itemtype'} }->{'translated_description'} +$data->{'itemtypename'} = db_t('itemtype', $itemtypes->{ $data->{'itemtype'} }->{description}); if $data->{itemtype} && exists $itemtypes->{ $data->{itemtype} }; foreach ( keys %{$data} ) { $template->param( "$_" => defined $data->{$_} ? $data->{$_} : '' ); @@ -144,7 +145,7 @@ foreach ( keys %{$data} ) { foreach my $item (@items){ $item->{object} = Koha::Items->find( $item->{itemnumber} ); $item->{'collection'} = $ccodes->{ $item->{ccode} } if $ccodes && $item->{ccode} && exists $ccodes->{ $item->{ccode} }; - $item->{'itype'} = $itemtypes->{ $item->{'itype'} }->{'translated_description'} if exists $itemtypes->{ $item->{'itype'} }; + $item->{'itype'} = db_t('itemtype', $itemtypes->{ $item->{'itype'} }->{description}) if exists $itemtypes->{ $item->{'itype'} }; $item->{'replacementprice'} = $item->{'replacementprice'}; if ( defined $item->{'copynumber'} ) { $item->{'displaycopy'} = 1; --- a/catalogue/search.pl +++ a/catalogue/search.pl @@ -156,6 +156,7 @@ use Koha::SearchEngine::Search; use Koha::SearchEngine::QueryBuilder; use Koha::Virtualshelves; use Koha::SearchFields; +use Koha::I18N; use URI::Escape; @@ -237,7 +238,14 @@ $template->param( ); # load the Type stuff -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { + map { + $_->{itemtype} => { + %$_, + description => db_t( 'itemtype', $_->{description} ), + } + } @{ Koha::ItemTypes->search->unblessed } +}; # the index parameter is different for item-level itemtypes my $itype_or_itemtype = (C4::Context->preference("item-level_itypes"))?'itype':'itemtype'; my @advancedsearchesloop; @@ -251,11 +259,11 @@ foreach my $advanced_srch_type (@advanced_search_types) { if ($advanced_srch_type eq 'itemtypes') { # itemtype is a special case, since it's not defined in authorized values my @itypesloop; - foreach my $thisitemtype ( sort {$itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } keys %$itemtypes ) { + foreach my $thisitemtype ( sort {$itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description} } keys %$itemtypes ) { my %row =( number=>$cnt++, ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{translated_description}, + description => $itemtypes->{$thisitemtype}->{description}, imageurl=> getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ), ); push @itypesloop, \%row; @@ -546,7 +554,7 @@ my $facets; # this object stores the faceted results that display on the left-ha my $results_hashref; eval { - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; ( $error, $results_hashref, $facets ) = $searcher->search_compat( $query, $simple_query, \@sort_by, \@servers, $results_per_page, $offset, undef, $itemtypes, @@ -818,7 +826,14 @@ sub prepare_adv_search_types { # the index parameter is different for item-level itemtypes my $itype_or_itemtype = ( C4::Context->preference("item-level_itypes") ) ? 'itype' : 'itemtype'; - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes = { + map { + $_->{itemtype} => { + %$_, + description => db_t( 'itemtype', $_->{description} ), + } + } @{ Koha::ItemTypes->search->unblessed } + }; my ( $cnt, @result ); foreach my $advanced_srch_type (@advanced_search_types) { @@ -830,8 +845,8 @@ sub prepare_adv_search_types { my @itypesloop; foreach my $thisitemtype ( sort { - $itemtypes->{$a}->{'translated_description'} - cmp $itemtypes->{$b}->{'translated_description'} + $itemtypes->{$a}->{'description'} + cmp $itemtypes->{$b}->{'description'} } keys %$itemtypes ) { @@ -839,7 +854,7 @@ sub prepare_adv_search_types { number => $cnt++, ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'translated_description'}, + description => $itemtypes->{$thisitemtype}->{'description'}, imageurl => getitemtypeimagelocation( 'intranet', $itemtypes->{$thisitemtype}->{'imageurl'} ), --- a/cataloguing/addbiblio.pl +++ a/cataloguing/addbiblio.pl @@ -46,6 +46,7 @@ use Date::Calc qw(Today); use MARC::File::USMARC; use MARC::File::XML; use URI::Escape; +use Koha::I18N; if ( C4::Context->preference('marcflavour') eq 'UNIMARC' ) { MARC::File::XML->default_record_format('UNIMARC'); @@ -181,10 +182,10 @@ sub build_authorized_values_list { push @authorised_values, ""; my $itemtype; - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; while ( $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->description); } $value = $itemtype unless ($value); } --- a/cataloguing/additem.pl +++ a/cataloguing/additem.pl @@ -31,6 +31,7 @@ use C4::Circulation; use C4::Koha; use C4::ClassSource; use Koha::DateUtils; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; @@ -182,13 +183,13 @@ sub generate_subfield_form { my $branch_limit = C4::Context->userenv && C4::Context->userenv->{"branch"}; my $itemtypes; if($branch_limit) { - $itemtypes = Koha::ItemTypes->search_with_localization({branchcode => $branch_limit}); + $itemtypes = Koha::ItemTypes->search({branchcode => $branch_limit}); } else { - $itemtypes = Koha::ItemTypes->search_with_localization; + $itemtypes = Koha::ItemTypes->search; } while ( my $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->description); } unless ( $value ) { --- a/circ/transferstoreceive.pl +++ a/circ/transferstoreceive.pl @@ -34,6 +34,7 @@ use Date::Calc qw( use C4::Koha; use C4::Reserves; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; use Koha::Libraries; @@ -95,7 +96,7 @@ while ( my $library = $libraries->next ) { my $itemtype = Koha::ItemTypes->find( $item->effective_itemtype ); $getransf{'datetransfer'} = $num->{'datesent'}; - $getransf{'itemtype'} = $itemtype->description; # FIXME Should not it be translated_description? + $getransf{'itemtype'} = db_t('itemtype', $itemtype->description); %getransf = ( %getransf, title => $biblio->title, --- a/course_reserves/add_items.pl +++ a/course_reserves/add_items.pl @@ -84,7 +84,7 @@ if ( $action eq 'lookup' and $item ) { ccodes => GetAuthorisedValues('CCODE'), locations => GetAuthorisedValues('LOC'), - itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template + itypes => $itemtypes, return => $return, ); --- a/installer/data/mysql/atomicupdate/bug-24975.perl +++ a/installer/data/mysql/atomicupdate/bug-24975.perl @@ -0,0 +1,48 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS l10n_source ( + l10n_source_id INT(11) NOT NULL AUTO_INCREMENT, + context VARCHAR(100) NULL DEFAULT NULL, + source TEXT NOT NULL, + PRIMARY KEY (l10n_source_id), + KEY context_source (context, source(60)) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + }); + + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS l10n_target ( + l10n_target_id INT(11) NOT NULL AUTO_INCREMENT, + l10n_source_id INT(11) NOT NULL, + language VARCHAR(10) NOT NULL, + translation TEXT NOT NULL, + PRIMARY KEY (l10n_target_id), + UNIQUE KEY l10n_source_language (l10n_source_id, language), + FOREIGN KEY l10n_source (l10n_source_id) REFERENCES l10n_source (l10n_source_id) + ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + }); + + # Populate l10n_source and l10n_target for itemtypes + $dbh->do(q{ + INSERT INTO l10n_source (context, source) + SELECT DISTINCT 'itemtype', description FROM itemtypes + }); + + if (TableExists('localization')) { + $dbh->do(q{ + INSERT INTO l10n_target (l10n_source_id, language, translation) + SELECT DISTINCT l10n_source_id, lang, translation + FROM localization + JOIN itemtypes ON (localization.code = itemtypes.itemtype) + JOIN l10n_source ON (itemtypes.description = l10n_source.source AND l10n_source.context = 'itemtype') + WHERE entity = 'itemtypes' + }); + + $dbh->do('DROP TABLE localization'); + } + + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 24975 - l10n_source, l10n_target)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -3695,20 +3695,27 @@ CREATE TABLE `additional_field_values` ( CONSTRAINT `afv_fk` FOREIGN KEY (`field_id`) REFERENCES `additional_fields` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; --- --- Table structure for table 'localization' --- -DROP TABLE IF EXISTS localization; -CREATE TABLE `localization` ( - localization_id int(11) NOT NULL AUTO_INCREMENT, - entity varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL, - code varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL, - lang varchar(25) COLLATE utf8mb4_unicode_ci NOT NULL, -- could be a foreign key - translation MEDIUMTEXT COLLATE utf8mb4_unicode_ci, - PRIMARY KEY (localization_id), - UNIQUE KEY `entity_code_lang` (`entity`,`code`,`lang`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; +DROP TABLE IF EXISTS l10n_source; +CREATE TABLE l10n_source ( + l10n_source_id INT(11) NOT NULL AUTO_INCREMENT, + context VARCHAR(100) NULL DEFAULT NULL, + source TEXT NOT NULL, + PRIMARY KEY (l10n_source_id), + KEY context_source (context, source(60)) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +DROP TABLE IF EXISTS l10n_target; +CREATE TABLE l10n_target ( + l10n_target_id INT(11) NOT NULL AUTO_INCREMENT, + l10n_source_id INT(11) NOT NULL, + language VARCHAR(10) NOT NULL, + translation TEXT NOT NULL, + PRIMARY KEY (l10n_target_id), + UNIQUE KEY l10n_source_language (l10n_source_id, language), + FOREIGN KEY l10n_source (l10n_source_id) REFERENCES l10n_source (l10n_source_id) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; -- -- Table structure for table 'audio_alerts' --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -150,6 +150,7 @@ [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) %]
  • Keyboard shortcuts
  • [% END %] +
  • Localization
  • [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -1,3 +1,4 @@ +[% USE ItemTypes %] [% BLOCK options_for_libraries %] [% FOREACH l IN libraries %] [% IF l.selected %] @@ -25,7 +26,7 @@ [% ELSE %] [% END %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -236,6 +236,8 @@
    Keyboard shortcuts
    Define which keys trigger actions in the advanced cataloging editor
    [% END %] +
    Localization
    +
    Translate user-defined strings
    [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE ItemTypes %] [% USE Koha %] [% USE AuthorisedValues %] [% USE Price %] @@ -118,9 +119,6 @@ Item types administration
  • Required - [% IF can_be_translated %] - Translate into other languages - [% END %]
  • Search category @@ -323,7 +321,7 @@ Item types administration Item type [% itemtype.itemtype | html %] - Description[% itemtype.translated_description | html %] + Description[% ItemTypes.t(itemtype.description) | html %] [% UNLESS Koha.Preference('noItemTypeImages') %] Image @@ -379,19 +377,7 @@ Item types administration - [% IF itemtype.translated_descriptions.size %] - [% itemtype.description | html %] (default)
    - [% FOR description IN itemtype.translated_descriptions %] - [% IF description.translation == itemtype.translated_description %] - [% description.translation | html %] - [% ELSE %] - [% description.translation | html %] ([% description.lang | html %]) - [% END %] -
    - [% END %] - [% ELSE %] - [% itemtype.description | html %] - [% END %] + [% itemtype.description | html %] [% itemtype.searchcategory | html %] [% IF ( itemtype.notforloan ) %]Yes[% ELSE %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/localization.tt @@ -1,277 +1,160 @@ -[% USE raw %] -[% USE Asset %] +[% USE JSON.Escape %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Localization -[% INCLUDE 'doc-head-close.inc' popup => 1 %] - +[% INCLUDE 'doc-head-close.inc' %] + -
    -
    -
    -
    - - - -
    -
      -
    1. - Authorized value: - [% code | html %] -
    2. -
    3. - - -
    4. -
    5. - - -
    6. -
    7. -   - -
    8. -
    -
    -
    -
    -
    + [% INCLUDE 'header.inc' %] + [% INCLUDE 'prefs-admin-search.inc' %] -
    -
    -
    -
    -
    + + +
    -
    - - - - - - - - - - - - - [% FOR t IN translations %] - - - - - - - - - [% END %] - -
    IdEntityCodeLanguageTranslation 
    [% t.id | html %][% t.entity | html %][% t.code | html %][% t.lang | html %][% t.translation | html %] Delete
    -
    -
    -
    +
    +
    +

    Localization

    + + + + + + + + + + + +
    ContextSourceTranslations
    +
    +
    + +
    + +
    +
    + [% MACRO jsinclude BLOCK %] [% INCLUDE 'datatables.inc' %] [% END %] -[% INCLUDE 'popup-bottom.inc' %] +[% INCLUDE 'intranet-bottom.inc' %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -322,7 +322,7 @@ @@ -818,7 +818,7 @@ [% IF holdallowed || hold_fulfillment_policy || returnbranch %] - [% i.translated_description | html %] + [% ItemTypes.t(i.description) | html %] [% IF holdallowed == 2 %] @@ -863,7 +863,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/advsearch.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE ItemTypes %] [% USE Koha %] [% USE Asset %] [% USE Branches %] @@ -143,7 +144,7 @@ [% FOREACH itemtypeloo IN advsearchloo.code_loop %] + [% ItemTypes.t(itemtypeloo.description) | html %] [% IF ( loop.last ) %][% ELSE %][% UNLESS ( loop.count % 5 ) %][% END %][% END %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE ItemTypes %] [% USE Koha %] [% USE KohaDates %] [% USE AuthorisedValues %] @@ -264,9 +265,9 @@ [% IF ( item_level_itypes ) %] [% IF !noItemTypeImages && item.imageurl %] - [% item.translated_description | html %] + [% ItemTypes.t(item.description) | html %] [% END %] - [% item.translated_description | html %] + [% ItemTypes.t(item.description) | html %] [% END %] [% UNLESS ( singlebranchmode ) %][% Branches.GetName( item.branchcode ) | html %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% INCLUDE 'doc-head-open.inc' %] Koha › Course reserves ›[% IF is_edit || course_reserve %] Edit item[% ELSE %] Add items[% END %] [% INCLUDE 'doc-head-close.inc' %] @@ -44,9 +45,9 @@ [% FOREACH it IN itypes %] [% IF course_item.itype.defined && ( ( course.enabled == 'yes' && it.itemtype == item.itype ) || ( course.enabled == 'no' && it.itemtype == course_item.itype ) ) %] - + [% ELSE %] - + [% END %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt @@ -39,7 +39,7 @@ [% FOREACH it IN ItemTypes.Get() %] - + [% END %]
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/acquisitions_stats.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/acquisitions_stats.tt @@ -1,3 +1,4 @@ +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports [% IF ( do_it ) %]› Acquisitions statistics › Results[% ELSE %]› Acquisitions statistics[% END %] @@ -191,7 +192,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/bor_issues_top.tt @@ -108,7 +108,7 @@
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/cat_issues_top.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Most-circulated items[% IF ( do_it ) %] › Results[% END %] @@ -85,7 +86,7 @@
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_out.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Items with no checkouts [% INCLUDE 'doc-head-close.inc' %] @@ -98,7 +99,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_stats.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/catalogue_stats.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports [% IF ( do_it ) %]› Catalog statistics › Results[% ELSE %]› Catalog statistics[% END %] @@ -103,7 +104,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_avg_stats.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Average loan time @@ -137,7 +138,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/issues_stats.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Circulation statistics [% IF ( do_it ) %]› Results[% END %] @@ -168,7 +169,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt @@ -137,7 +137,7 @@
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reserves_stats.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Reports › Holds statistics [% IF ( do_it ) %]› Results[% END %] @@ -153,7 +154,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE ItemTypes %] [% USE KohaDates %] [% USE Branches %] [% USE Koha %] @@ -175,9 +176,9 @@ fieldset.rows table { clear: none; margin: 0; } [% FOREACH type IN typeloop %] [% IF ( type.selected ) %] - + [% ELSE %] - + [% END %] [% END %] @@ -189,9 +190,9 @@ fieldset.rows table { clear: none; margin: 0; } [% FOREACH previous IN previoustypeloop %] [% IF ( previous.selected ) %] - + [% ELSE %] - + [% END %] [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-batchedit.tt @@ -111,7 +111,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-bib-search.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-bib-search.tt @@ -1,3 +1,4 @@ +[% USE ItemTypes %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › Catalog search [% INCLUDE 'doc-head-close.inc' %] @@ -25,7 +26,7 @@ [%- FOREACH itemtypeloo IN itemtypeloop %] [%- END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/export.tt @@ -1,6 +1,7 @@ [% USE raw %] [% USE Asset %] [% USE Branches %] +[% USE ItemTypes %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Tools › Export data @@ -66,7 +67,7 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE ItemTypes %] [% USE Koha %] [% USE KohaDates %] [% SET PRIVATE = 1 %] @@ -203,7 +204,7 @@ [% END %] [% UNLESS ( item_level_itypes ) %] - [% UNLESS ( noItemTypeImages || !itemsloo.imageurl ) %][% itemsloo.description | html %][% END %][% itemsloo.description | html %] + [% UNLESS ( noItemTypeImages || !itemsloo.imageurl ) %][% ItemTypes.t(itemsloo.description) | html %][% END %][% ItemTypes.t(itemsloo.description) | html %] [% END %] [% IF ( itemsloo.XSLTBloc ) %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc +++ a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-topissues.inc @@ -1,3 +1,4 @@ +[% USE ItemTypes %] [% USE Koha %] [% USE Branches %] [% PROCESS 'html_helpers.inc' %] @@ -37,7 +38,7 @@ [% ELSE %] [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-readingrecord.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE ItemTypes %] [% USE Koha %] [% USE KohaDates %] [% INCLUDE 'doc-head-open.inc' %] @@ -172,7 +173,7 @@ [% END %] [% END %] Item type: - [% issue.translated_description | html %] + [% ItemTypes.t(issue.description) | html %] Call number: [% issue.itemcallnumber | html %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-reserve.tt @@ -214,7 +214,7 @@
  • Item type: [% IF ( bibitemloo.imageurl ) %][% END %] - [% bibitemloo.translated_description | html %] + [% ItemTypes.t(bibitemloo.description) | html %]
  • [% END %] @@ -380,7 +380,7 @@ [% END %] [% END %] - [% itemLoo.translated_description | html %] + [% ItemTypes.t(itemLoo.description) | html %] [% END %] --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -1,5 +1,6 @@ [% USE raw %] [% USE Asset %] +[% USE ItemTypes %] [% USE Koha %] [% SET PRIVATE = 1 %] [% SET PUBLIC = 2 %] @@ -315,9 +316,9 @@ [% UNLESS ( item_level_itypes ) %] [% UNLESS ( noItemTypeImages ) %] - [% itemsloo.description | html %] + [% ItemTypes.t(itemsloo.description) | html %] [% END %] - [% itemsloo.description | html %] + [% ItemTypes.t(itemsloo.description) | html %] [% END %] --- a/labels/label-item-search.pl +++ a/labels/label-item-search.pl @@ -231,20 +231,7 @@ else { debug => 1, } ); - my $itemtypes = Koha::ItemTypes->search; - my @itemtypeloop; - while ( my $itemtype = $itemtypes->next ) { - # FIXME This must be improved: - # - pass the iterator to the template - # - display the translated_description - my %row = ( - value => $itemtype->itemtype, - description => $itemtype->description, - ); - push @itemtypeloop, \%row; - } $template->param( - itemtypeloop => \@itemtypeloop, batch_id => $batch_id, type => $type, ); --- a/opac/opac-detail.pl +++ a/opac/opac-detail.pl @@ -54,6 +54,7 @@ use Koha::Biblios; use Koha::RecordProcessor; use Koha::AuthorisedValues; use Koha::CirculationRules; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; use Koha::Acquisition::Orders; @@ -220,7 +221,7 @@ if ($session->param('busc')) { { my ($arrParamsBusc, $offset, $results_per_page) = @_; - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my @servers; @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'}; @servers = ("biblioserver") unless (@servers); @@ -557,12 +558,12 @@ my $HideMARC = $record_processor->filters->[0]->should_hide_marc( interface => 'opac', } ); -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; # imageurl: my $itemtype = $dat->{'itemtype'}; if ( $itemtype ) { $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); - $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description}; + $dat->{'description'} = db_t('itemtype', $itemtypes->{$itemtype}->{description}); } my $shelflocations = @@ -696,7 +697,7 @@ if ( not $viewallitems and @items > $max_items_to_display ) { } if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) { $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} ); - $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description}; + $itm->{'description'} = db_t('itemtype', $itemtypes->{ $itm->{itype} }->{description}); } foreach (qw(ccode enumchron copynumber itemnotes location_description uri)) { $itemfields{$_} = 1 if ($itm->{$_}); --- a/opac/opac-readingrecord.pl +++ a/opac/opac-readingrecord.pl @@ -58,7 +58,7 @@ my $borr = Koha::Patrons->find( $borrowernumber )->unblessed; $template->param(%{$borr}); -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; # get the record my $order = $query->param('order') || ''; @@ -87,8 +87,7 @@ my $opac_summary_html = C4::Context->preference('OPACMySummaryHTML'); foreach my $issue ( @{$issues} ) { $issue->{normalized_isbn} = GetNormalizedISBN( $issue->{isbn} ); if ( $issue->{$itype_attribute} ) { - $issue->{translated_description} = - $itemtypes->{ $issue->{$itype_attribute} }->{translated_description}; + $issue->{description} = $itemtypes->{ $issue->{$itype_attribute} }->{description}; $issue->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $issue->{$itype_attribute} }->{imageurl} ); --- a/opac/opac-reserve.pl +++ a/opac/opac-reserve.pl @@ -100,7 +100,7 @@ if ( $reservefee > 0){ $template->param( RESERVE_CHARGE => $reservefee); } -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; # There are two ways of calling this script, with a single biblio num # or multiple biblio nums. @@ -444,13 +444,13 @@ foreach my $biblioNum (@biblionumbers) { $biblioLoopIter{reqholdnotes}=0; #TODO: For future use if (!$itemLevelTypes && $biblioData->{itemtype}) { - $biblioLoopIter{translated_description} = $itemtypes->{$biblioData->{itemtype}}{translated_description}; + $biblioLoopIter{description} = $itemtypes->{$biblioData->{itemtype}}{description}; $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$biblioData->{itemtype}}{imageurl}; } foreach my $itemInfo (@{$biblioData->{itemInfos}}) { if ($itemLevelTypes && $itemInfo->{itype}) { - $itemInfo->{translated_description} = $itemtypes->{$itemInfo->{itype}}{translated_description}; + $itemInfo->{description} = $itemtypes->{$itemInfo->{itype}}{description}; $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$itemInfo->{itype}}{imageurl}; } @@ -478,7 +478,7 @@ foreach my $biblioNum (@biblionumbers) { $itemLoopIter->{ccode} = $itemInfo->{ccode}; $itemLoopIter->{copynumber} = $itemInfo->{copynumber}; if ($itemLevelTypes) { - $itemLoopIter->{translated_description} = $itemInfo->{translated_description}; + $itemLoopIter->{description} = $itemInfo->{description}; $itemLoopIter->{itype} = $itemInfo->{itype}; $itemLoopIter->{imageurl} = $itemInfo->{imageurl}; } --- a/opac/opac-search.pl +++ a/opac/opac-search.pl @@ -55,6 +55,7 @@ use C4::External::BakerTaylor qw( image_url link_url ); use Koha::CirculationRules; use Koha::Libraries; +use Koha::I18N; use Koha::ItemTypes; use Koha::Ratings; use Koha::Virtualshelves; @@ -225,14 +226,13 @@ $template->param(search_languages_loop => $languages_limit_loop,); # load the Type stuff my $itemtypes = GetItemTypesCategorized; -# add translated_description to itemtypes foreach my $itemtype ( keys %{$itemtypes} ) { # Itemtypes search categories don't have (yet) translated descriptions, they are auth values (and could still have no descriptions too BZ 18400) # If 'iscat' (see ITEMTYPECAT) then there is no itemtype and the description is not translated - my $translated_description = $itemtypes->{$itemtype}->{iscat} + my $description = $itemtypes->{$itemtype}->{iscat} ? $itemtypes->{$itemtype}->{description} - : Koha::ItemTypes->find($itemtype)->translated_description; - $itemtypes->{$itemtype}->{translated_description} = $translated_description || $itemtypes->{$itemtype}->{description} || q{}; + : db_t('itemtype', Koha::ItemTypes->find($itemtype)->description); + $itemtypes->{$itemtype}->{description} = $description || $itemtypes->{$itemtype}->{description} || q{}; } # the index parameter is different for item-level itemtypes @@ -254,7 +254,7 @@ if ( $yaml =~ /\S/ ) { } } -my @sorted_itemtypes = sort { $itemtypes->{$a}->{translated_description} cmp $itemtypes->{$b}->{translated_description} } keys %$itemtypes; +my @sorted_itemtypes = sort { $itemtypes->{$a}->{description} cmp $itemtypes->{$b}->{description} } keys %$itemtypes; foreach my $advanced_srch_type (@advanced_search_types) { $advanced_srch_type =~ s/^\s*//; $advanced_srch_type =~ s/\s*$//; @@ -267,7 +267,7 @@ foreach my $advanced_srch_type (@advanced_search_types) { my %row =( number=>$cnt++, ccl => "$itype_or_itemtype,phr", code => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{translated_description}, + description => $itemtypes->{$thisitemtype}->{description}, imageurl=> getitemtypeimagelocation( 'opac', $itemtypes->{$thisitemtype}->{'imageurl'} ), cat => $itemtypes->{$thisitemtype}->{'iscat'}, hideinopac => $itemtypes->{$thisitemtype}->{'hideinopac'}, @@ -628,7 +628,7 @@ if ($tag) { $pasarParams .= '&count=' . uri_escape_utf8($results_per_page); $pasarParams .= '&simple_query=' . uri_escape_utf8($simple_query); $pasarParams .= '&query_type=' . uri_escape_utf8($query_type) if ($query_type); - my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes_nocategory = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; eval { ($error, $results_hashref, $facets) = $searcher->search_compat($query,$simple_query,\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes_nocategory,$query_type,$scan,1); }; --- a/opac/opac-shelves.pl +++ a/opac/opac-shelves.pl @@ -326,7 +326,7 @@ if ( $op eq 'view' ) { $itemtype = Koha::ItemTypes->find( $itemtype ); if( $itemtype ) { $this_item->{imageurl} = C4::Koha::getitemtypeimagelocation( 'opac', $itemtype->imageurl ); - $this_item->{description} = $itemtype->description; #FIXME Should not it be translated_description? + $this_item->{description} = $itemtype->description; $this_item->{notforloan} = $itemtype->notforloan; } $this_item->{'coins'} = $biblio->get_coins; --- a/opac/opac-user.pl +++ a/opac/opac-user.pl @@ -172,7 +172,7 @@ my $count = 0; my $overdues_count = 0; my @overdues; my @issuedat; -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $pending_checkouts = $patron->pending_checkouts->search({}, { order_by => [ { -desc => 'date_due' }, { -asc => 'issue_id' } ] }); if ( $pending_checkouts->count ) { # Useless test while ( my $c = $pending_checkouts->next ) { --- a/reports/acquisitions_stats.pl +++ a/reports/acquisitions_stats.pl @@ -194,7 +194,7 @@ else { $ccode_avlist = GetAuthorisedValues($ccode_subfield_structure->{authorised_value}); } - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; $template->param( booksellers => $booksellers, itemtypes => $itemtypes, # FIXME Should use the TT plugin instead --- a/reports/bor_issues_top.pl +++ a/reports/bor_issues_top.pl @@ -111,7 +111,7 @@ my @mime = ( map { {type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation my $delims = GetDelimiterChoices; my $patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['categorycode']}); -my $itemtypes = Koha::ItemTypes->search_with_localization; +my $itemtypes = Koha::ItemTypes->search; $template->param( mimeloop => \@mime, CGIseplist => $delims, --- a/reports/cat_issues_top.pl +++ a/reports/cat_issues_top.pl @@ -107,7 +107,7 @@ if ($do_it) { my $CGIsepChoice=GetDelimiterChoices; #doctype - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; #ccode my $ccodes = GetAuthorisedValues('CCODE'); --- a/reports/catalogue_out.pl +++ a/reports/catalogue_out.pl @@ -58,7 +58,7 @@ if ($do_it) { exit; # in either case, exit after do_it } -my $itemtypes = Koha::ItemTypes->search_with_localization; +my $itemtypes = Koha::ItemTypes->search; $template->param( itemtypes => $itemtypes, ); --- a/reports/catalogue_stats.pl +++ a/reports/catalogue_stats.pl @@ -120,7 +120,7 @@ if ($do_it) { my $req; my @select; - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; my @authvals = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } ); my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } ); --- a/reports/issues_avg_stats.pl +++ a/reports/issues_avg_stats.pl @@ -120,7 +120,7 @@ if ($do_it) { } else { my $patron_categories = Koha::Patron::Categories->search({}, {order_by => ['description']}); - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; my $dbh = C4::Context->dbh; my $req = $dbh->prepare("select distinctrow sort1 from borrowers where sort1 is not null order by sort1"); --- a/reports/issues_stats.pl +++ a/reports/issues_stats.pl @@ -33,6 +33,7 @@ use C4::Members; use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::I18N; use Koha::ItemTypes; use Koha::Patron::Attribute::Types; @@ -87,7 +88,7 @@ $sep = "\t" if ($sep eq 'tabulation'); $template->param(do_it => $do_it, ); -our $itemtypes = Koha::ItemTypes->search_with_localization->unblessed; +our $itemtypes = Koha::ItemTypes->search->unblessed; our @patron_categories = Koha::Patron::Categories->search_limited({}, {order_by => ['description']}); @@ -361,7 +362,7 @@ sub calculate { $cell{rowtitle_display} = ( $line =~ /ccode/ ) ? $ccodes->{$celvalue} : ( $line =~ /location/ ) ? $locations->{$celvalue} - : ( $line =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description} + : ( $line =~ /itemtype/ ) ? db_t('itemtype', $itemtypes_map->{$celvalue}->{description}) : $celvalue; # default fallback if ( $line =~ /sort1/ ) { foreach (@$Bsort1) { @@ -450,7 +451,7 @@ sub calculate { $cell{coltitle_display} = ( $column =~ /ccode/ ) ? $ccodes->{$celvalue} : ( $column =~ /location/ ) ? $locations->{$celvalue} - : ( $column =~ /itemtype/ ) ? $itemtypes_map->{$celvalue}->{translated_description} + : ( $column =~ /itemtype/ ) ? db_t('itemtype', $itemtypes_map->{$celvalue}->{description}); : $celvalue; # default fallback if ( $column =~ /sort1/ ) { foreach (@$Bsort1) { --- a/reports/itemslost.pl +++ a/reports/itemslost.pl @@ -150,7 +150,7 @@ if ( $op eq 'export' ) { } # getting all itemtypes -my $itemtypes = Koha::ItemTypes->search_with_localization; +my $itemtypes = Koha::ItemTypes->search; my $csv_profiles = Koha::CsvProfiles->search({ type => 'sql', used_for => 'export_lost_items' }); --- a/reports/reserves_stats.pl +++ a/reports/reserves_stats.pl @@ -30,6 +30,7 @@ use C4::Reports; use C4::Members; use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::I18N; use Koha::ItemTypes; use Koha::Libraries; use Koha::Patron::Categories; @@ -130,7 +131,7 @@ my @values; my %labels; my %select; -my $itemtypes = Koha::ItemTypes->search_with_localization; +my $itemtypes = Koha::ItemTypes->search; # location list my @locations; @@ -320,7 +321,7 @@ sub display_value { my $display_value = ( $crit =~ /ccode/ ) ? $ccodes->{$value} : ( $crit =~ /location/ ) ? $locations->{$value} - : ( $crit =~ /itemtype/ ) ? Koha::ItemTypes->find( $value )->translated_description + : ( $crit =~ /itemtype/ ) ? db_t('itemtype', Koha::ItemTypes->find( $value )->description) : ( $crit =~ /branch/ ) ? Koha::Libraries->find($value)->branchname : ( $crit =~ /reservestatus/ ) ? reservestatushuman($value) : $value; # default fallback --- a/reserve/request.pl +++ a/reserve/request.pl @@ -70,7 +70,7 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user( my $showallitems = $input->param('showallitems'); my $pickup = $input->param('pickup') || C4::Context->userenv->{'branch'}; -my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; # Select borrowers infos my $findborrower = $input->param('findborrower'); --- a/serials/subscription-add.pl +++ a/serials/subscription-add.pl @@ -158,9 +158,8 @@ $template->param( additional_field_values => \%additional_field_values, ); -my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; +my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; -# FIXME We should use the translated_description for item types my @typearg = map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop}; my @previoustypearg = --- a/serials/subscription-bib-search.pl +++ a/serials/subscription-bib-search.pl @@ -199,10 +199,9 @@ else { ); # load the itemtypes - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my @itemtypesloop; # FIXME This is uselessly complex, the iterator should be send to the template - # FIXME The translated_description should be used foreach my $thisitemtype ( sort { $itemtypes->{$a}->{'description'} --- a/svc/bib_profile +++ a/svc/bib_profile @@ -113,7 +113,7 @@ sub _get_bib_number_tag { sub _get_biblioitem_itemtypes { my $result = shift; - my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; + my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } }; my $sth = $dbh->prepare_cached("SELECT tagfield, tagsubfield FROM marc_subfield_structure WHERE frameworkcode = '' --- a/svc/checkouts +++ a/svc/checkouts @@ -29,6 +29,7 @@ use C4::Context; use Koha::AuthorisedValues; use Koha::DateUtils; +use Koha::I18N; use Koha::ItemTypes; my $input = new CGI; @@ -196,9 +197,9 @@ while ( my $c = $sth->fetchrow_hashref() ) { part_name => $c->{part_name} // '', author => $c->{author}, barcode => $c->{barcode}, - type_for_stat => $type_for_stat ? $type_for_stat->translated_description : q{}, - itemtype_description => $itemtype ? $itemtype->translated_description : q{}, - recordtype_description => $recordtype ? $recordtype->translated_description : q{}, + type_for_stat => $type_for_stat ? db_t('itemtype', $type_for_stat->description) : q{}, + itemtype_description => $itemtype ? db_t('itemtype', $itemtype->description) : q{}, + recordtype_description => $recordtype ? db_t('itemtype', $recordtype->description) : q{}, collection => $collection, location => $location, homebranch => $c->{homebranch}, --- a/svc/holds +++ a/svc/holds @@ -29,6 +29,7 @@ use C4::Context; use Koha::DateUtils; use Koha::Holds; +use Koha::I18N; use Koha::ItemTypes; use Koha::Libraries; @@ -76,7 +77,7 @@ while ( my $h = $holds_rs->next() ) { my $itemtype_limit; if ( $h->itemtype ) { my $itemtype = Koha::ItemTypes->find( $h->itemtype ); - $itemtype_limit = $itemtype->translated_description; + $itemtype_limit = db_t('itemtype', $itemtype->description); } my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed; --- a/svc/localization +++ a/svc/localization @@ -4,101 +4,82 @@ use Modern::Perl; use Encode qw( encode ); use C4::Service; -use Koha::Localizations; +use Koha::Caches; +use Koha::Database; -our ( $query, $response ) = C4::Service->init( parameters => 'manage_itemtypes' ); +our ( $query, $response ) = C4::Service->init( parameters => 'parameters_remaining_permissions' ); sub get_translations { - my $rs = Koha::Localizations->search({ entity => $query->param('entity'), code => $query->param('code') }); - my @translations; - while ( my $s = $rs->next ) { - push @translations, { - id => $s->localization_id, - entity => $s->entity, - code => $s->code, - lang => $s->lang, - translation => $s->translation, - } - } - $response->param( translations => \@translations ); - C4::Service->return_success( $response ); -} + my $draw = $query->param('draw'); + my $start = $query->param('start'); + my $length = $query->param('length'); + my $search = $query->param('search[value]'); -sub update_translation { - my $id = $query->param('id'); - my $translation = $query->param('translation'); - my $lang = $query->param('lang'); + my $schema = Koha::Database->new->schema; + my $rs = $schema->resultset('L10nSource'); + my $recordsTotal = $rs->count; - my $localization = Koha::Localizations->find( $id ); - if ( defined $lang and $localization->lang ne $lang ) { - $localization->lang( $lang ) - } - if ( defined $translation and $localization->translation ne $translation ) { - $localization->translation( $translation ) - } - my %params; - my $is_changed; - if ( $localization->is_changed ) { - $is_changed = 1; - unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) { - $localization->store; - } else { - $params{error} = 1; - $params{error_code} = 'already_exists'; + my $cond = {}; + if ($search) { + my @and; + my @words = split /\s+/, $search; + foreach my $word (@words) { + push @and, \['source LIKE ? COLLATE utf8mb4_unicode_ci', "%$word%"]; } + $cond->{-and} = \@and; } + + $rs = $rs->search($cond); + my $recordsFiltered = $rs->count; + + my @sources = $rs->search({}, { + prefetch => 'l10n_targets', + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + rows => $length, + offset => $start, + order_by => { -asc => ['context', 'source'] }, + }); + $response->param( - %params, - id => $localization->localization_id, - entity => $localization->entity, - code => $localization->code, - lang => $localization->lang, - translation => $localization->translation, - is_changed => $is_changed, + draw => $draw, + recordsTotal => $recordsTotal, + recordsFiltered => $recordsFiltered, + data => \@sources, ); C4::Service->return_success( $response ); } -sub add_translation { - my $entity = $query->param('entity'); - my $code = $query->param('code'); - my $lang = $query->param('lang'); +sub update_translation { + my $id = $query->param('id'); my $translation = $query->param('translation'); + my $lang = $query->param('lang'); - unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) { - my $localization = Koha::Localization->new( - { - entity => $entity, - code => $code, - lang => $lang, - translation => $translation, - } - ); - $localization->store; - $response->param( - id => $localization->localization_id, - entity => $localization->entity, - code => $localization->code, - lang => $localization->lang, - translation => $localization->translation, - ); + my $schema = Koha::Database->new->schema; + my $rs = $schema->resultset('L10nTarget'); + if (defined $translation && $translation ne '') { + $rs->update_or_create({ + l10n_source_id => $id, + language => $lang, + translation => $translation, + }, { + key => 'l10n_source_language', + }); } else { - $response->param( error => 1, error_code => 'already_exists', ); + $rs->search({ + l10n_source_id => $id, + language => $lang, + })->delete; } - C4::Service->return_success( $response ); -} -sub delete_translation { - my $id = $query->param('id'); - Koha::Localizations->find($id)->delete; - $response->param( id => $id ); + my $source = $schema->resultset('L10nSource')->find($id); + my $cache_key = sprintf('%s:%s', $source->context, $lang); + Koha::Caches->get_instance()->clear_from_cache($cache_key); + C4::Service->return_success( $response ); } C4::Service->dispatch( - [ 'GET /', [ 'id' ], \&get_translations ], + [ 'GET /', [], \&get_translations ], [ 'PUT /', [ 'id' ], \&update_translation ], - [ 'POST /', [ 'entity', 'code', 'lang', 'translation' ], \&add_translation ], - [ 'DELETE /', ['id'], \&delete_translation ], ); --- a/svc/split_callnumbers +++ a/svc/split_callnumbers @@ -20,78 +20,6 @@ sub get_split_callnumbers { C4::Service->return_success( $response ); } -sub update_translation { - my $id = $query->param('id'); - my $translation = $query->param('translation'); - my $lang = $query->param('lang'); - - my $localization = Koha::Localizations->find( $id ); - if ( defined $lang and $localization->lang ne $lang ) { - $localization->lang( $lang ) - } - if ( defined $translation and $localization->translation ne $translation ) { - $localization->translation( $translation ) - } - my %params; - my $is_changed; - if ( $localization->is_changed ) { - $is_changed = 1; - unless ( Koha::Localizations->search( { entity => $localization->entity, code => $localization->code, lang => $lang, localization_id => { '!=' => $localization->localization_id }, } )->count ) { - $localization->store; - } else { - $params{error} = 1; - $params{error_code} = 'already_exists'; - } - } - $response->param( - %params, - id => $localization->localization_id, - entity => $localization->entity, - code => $localization->code, - lang => $localization->lang, - translation => $localization->translation, - is_changed => $is_changed, - ); - C4::Service->return_success( $response ); -} - -sub add_translation { - my $entity = $query->param('entity'); - my $code = $query->param('code'); - my $lang = $query->param('lang'); - my $translation = $query->param('translation'); - - unless ( Koha::Localizations->search({entity => $entity, code => $code, lang => $lang, })->count ) { - my $localization = Koha::Localization->new( - { - entity => $entity, - code => $code, - lang => $lang, - translation => $translation, - } - ); - $localization->store; - $response->param( - id => $localization->localization_id, - entity => $localization->entity, - code => $localization->code, - lang => $localization->lang, - translation => $localization->translation, - ); - - } else { - $response->param( error => 1, error_code => 'already_exists', ); - } - C4::Service->return_success( $response ); -} - -sub delete_translation { - my $id = $query->param('id'); - Koha::Localizations->find($id)->delete; - $response->param( id => $id ); - C4::Service->return_success( $response ); -} - C4::Service->dispatch( [ 'GET /', [ 'callnumbers', 'regexs' ], \&get_split_callnumbers ], ); --- a/t/db_dependent/Koha/ItemTypes.t +++ a/t/db_dependent/Koha/ItemTypes.t @@ -20,7 +20,7 @@ use Modern::Perl; use Data::Dumper; -use Test::More tests => 24; +use Test::More tests => 22; use t::lib::Mocks; use t::lib::TestBuilder; @@ -84,31 +84,6 @@ Koha::ItemType->new( } )->store; -Koha::Localization->new( - { - entity => 'itemtypes', - code => 'type1', - lang => 'en', - translation => 'b translated itemtype desc' - } -)->store; -Koha::Localization->new( - { - entity => 'itemtypes', - code => 'type2', - lang => 'en', - translation => 'a translated itemtype desc' - } -)->store; -Koha::Localization->new( - { - entity => 'something_else', - code => 'type2', - lang => 'en', - translation => 'another thing' - } -)->store; - my $type = Koha::ItemTypes->find('type1'); ok( defined($type), 'first result' ); is( $type->itemtype, 'type1', 'itemtype/code' ); @@ -131,14 +106,6 @@ is( $type->checkinmsgtype, 'checkinmsgtype', 'checkinmsgtype' ); t::lib::Mocks::mock_preference('language', 'en'); t::lib::Mocks::mock_preference('opaclanguages', 'en'); -my $itemtypes = Koha::ItemTypes->search_with_localization; -is( $itemtypes->count, 3, 'There are 3 item types' ); -my $first_itemtype = $itemtypes->next; -is( - $first_itemtype->translated_description, - 'a translated itemtype desc', - 'item types should be sorted by translated description' -); my $builder = t::lib::TestBuilder->new; my $item_type = $builder->build_object({ class => 'Koha::ItemTypes' }); --- a/tools/batchMod.pl +++ a/tools/batchMod.pl @@ -37,6 +37,7 @@ use List::MoreUtils qw/uniq/; use Koha::AuthorisedValues; use Koha::Biblios; use Koha::DateUtils; +use Koha::I18N; use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; @@ -420,10 +421,10 @@ foreach my $tag (sort keys %{$tagslib}) { } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes" ) { push @authorised_values, ""; - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; while ( my $itemtype = $itemtypes->next ) { push @authorised_values, $itemtype->itemtype; - $authorised_lib{$itemtype->itemtype} = $itemtype->translated_description; + $authorised_lib{$itemtype->itemtype} = db_t('itemtype', $itemtype->description); } $value = ""; --- a/tools/export.pl +++ a/tools/export.pl @@ -271,7 +271,7 @@ if ( $op eq "export" ) { else { - my $itemtypes = Koha::ItemTypes->search_with_localization; + my $itemtypes = Koha::ItemTypes->search; my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); --- a/virtualshelves/shelves.pl +++ a/virtualshelves/shelves.pl @@ -281,7 +281,7 @@ if ( $op eq 'view' ) { $this_item->{author} = $biblio->author; $this_item->{dateadded} = $content->dateadded; $this_item->{imageurl} = $itemtype ? C4::Koha::getitemtypeimagelocation( 'intranet', $itemtype->imageurl ) : q{}; - $this_item->{description} = $itemtype ? $itemtype->description : q{}; #FIXME Should this be translated_description ? + $this_item->{description} = $itemtype ? $itemtype->description : q{}; $this_item->{notforloan} = $itemtype->notforloan if $itemtype; $this_item->{'coins'} = $biblio->get_coins; $this_item->{'normalized_upc'} = GetNormalizedUPC( $record, $marcflavour ); --