From c50bb140a872e67e07426fc3fc20bceb88c7d1e3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 24 Apr 2024 16:39:52 +0100 Subject: [PATCH] Bug 33237: Move and simplify language selection logic This patch moves the language selection into GetPreparedLetter, drops the interface check step and ensures the default template always uses the default include language as per the OPACLanguages settings. Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- C4/Letters.pm | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index f099686bb0..dc1db2190b 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -607,6 +607,7 @@ sub GetPreparedLetter { $letter = $template->unblessed; $letter->{'content-type'} = 'text/html; charset="UTF-8"' if $letter->{is_html}; } + $lang = $letter->{'lang'}; my $objects = $params{objects} || {}; my $tables = $params{tables} || {}; @@ -618,6 +619,14 @@ sub GetPreparedLetter { return; my $want_librarian = $params{want_librarian}; + # Best guess at language 'default' notice is written for include handling + if ( $lang eq 'default' ) { + + # Pick the first selected syspref language + my @languages = split /,/, C4::Context->preference('OPACLanguages'); + $lang = shift @languages; + } + $letter->{content} = _process_tt( { content => $letter->{content}, @@ -1671,21 +1680,7 @@ sub _process_tt { my $loops = $params->{loops}; my $objects = $params->{objects} || {}; my $substitute = $params->{substitute} || {}; - my $interface = C4::Context->interface; - my $lang; - if ( defined( $params->{lang} ) && $params->{lang} ne 'default' ) { - $lang = $params->{lang}; - } elsif ( $interface eq 'intranet' || $interface eq 'opac' ) { - - #use interface language - $lang = C4::Languages::getlanguage(); - } else { - - # Pick the first selected syspref language - my @languages = split /,/, C4::Context->preference('language'); - $lang = shift @languages; - } - $lang //= 'en'; + my $lang = $params->{lang} // 'en'; my ($theme, $availablethemes); my $htdocs = C4::Context->config('intrahtdocs'); -- 2.39.5