From 7f3a0bb76bf8edb2209d06961bc2addbbc7ceab6 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 10 May 2024 13:15:39 +0100 Subject: [PATCH] Bug 36815: (follow-up) Fix logic for new languages If a notice doesn't already have any data in it we weren't able to use the object to lookup the sample.. with this patch we now always load the samples if they exist for each installed and enabled language, regardless of whether there's already a notice stored in that language. Test plan 1. Install Spanish by running koha-translate --install es-ES from inside the kohashell 2. restart all 3. Set TranslateNotices to Allow 4. Verify that the Spanish-language sample_notices.yml exists 5. Open a notice that has at least one Spanish default notice defined 6. Confirm you see the 'View default' button for the spanish notice and that the displayed notice is indeed the spanish translation Signed-off-by: Emily Lamancusa Signed-off-by: Kyle M Hall Signed-off-by: Katrin Fischer --- tools/letter.pl | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/tools/letter.pl b/tools/letter.pl index dbe84aa26c..20472c1810 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -159,7 +159,7 @@ sub add_form { my $message_transport_types = GetMessageTransportTypes(); my $templates = { map { $_ => { message_transport_type => $_ } } sort @$message_transport_types }; - my %letters = ( default => { templates => $templates } ); + my %letters = ( default => { templates => {%$templates} } ); my $translated_languages = C4::Languages::getTranslatedLanguages( 'opac', @@ -189,19 +189,20 @@ sub add_form { $template->param( default_language => $default_language ); if ($letters) { $template->param( - modify => 1, - code => $code, + modify => 1, + code => $code, ); my $first_flag_name = 1; my $lang; # The letter name is contained into each mtt row. # So we can only sent the first one to the template. - for my $letter ( @$letters ) { + for my $letter (@$letters) { + # The letter_name if ( $first_flag_name and $letter->{name} ) { $template->param( - letter_name=> $letter->{name}, + letter_name => $letter->{name}, ); $first_flag_name = 0; } @@ -217,23 +218,31 @@ sub add_form { }; my $lang = $letter->{lang}; - my $mtt = $letter->{message_transport_type}; - $letters{ $lang }{templates}{$mtt} = { + my $mtt = $letter->{message_transport_type}; + $letters{$lang}{templates}{$mtt} = { message_transport_type => $letter->{message_transport_type}, - is_html => $letter->{is_html}, - updated_on => $letter->{updated_on}, - title => $letter->{title}, - content => $letter->{content} // '', - tt_error => $letter->{tt_error}, + is_html => $letter->{is_html}, + updated_on => $letter->{updated_on}, + title => $letter->{title}, + content => $letter->{content} // '', + tt_error => $letter->{tt_error}, }; - $letters{ $lang }{params} = $letter; - - my $object = Koha::Notice::Templates->find( { id => $letter->{id} } ); - $letters{ $lang }{templates}{$mtt}{sample} = $object->get_default; - $letters{ $lang }{templates}{$mtt}{id} = $letter->{id}; + $letters{$lang}{params} = $letter; } - } - else { + + # Fetch sample notices + for my $lang_key ( keys %letters ) { + for my $mtt_key ( keys %{ $letters{$lang_key}{templates} } ) { + my $object = Koha::Notice::Template->new( + { module => $module, code => $code, message_transport_type => $mtt_key, lang => $lang_key } ); + my $sample = $object->get_default; + my $template = { %{ $letters{$lang_key}{templates}{$mtt_key} } }; + $template->{sample} = $sample; + $template->{id} = lc( "$module" . "_" . $code . "_" . $mtt_key . "_" . $lang_key ); + $letters{$lang_key}{templates}{$mtt_key} = $template; + } + } + } else { $template->param( adding => 1 ); }