Commit c49bdc3a authored by joubu's avatar joubu Committed by Kyle M Hall

Bug 17762: Add the lang parameter to C4::Letters::getletter

Sponsored-by: Orex Digital
Signed-off-by: default avatarHugo Agud <hagud@orex.es>
Signed-off-by: Wm. Nick Clemens's avatarNick Clemens <nick@bywatersolutions.com>
Signed-off-by: default avatarKyle M Hall <kyle@bywatersolutions.com>
parent f7b11f38
......@@ -198,8 +198,9 @@ sub GetLettersAvailableForALibrary {
}
sub getletter {
my ( $module, $code, $branchcode, $message_transport_type ) = @_;
my ( $module, $code, $branchcode, $message_transport_type, $lang) = @_;
$message_transport_type //= '%';
$lang //= 'default';
if ( C4::Context->preference('IndependentBranches')
and $branchcode
......@@ -215,9 +216,10 @@ sub getletter {
FROM letter
WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '')
AND message_transport_type LIKE ?
AND lang =?
ORDER BY branchcode DESC LIMIT 1
});
$sth->execute( $module, $code, $branchcode, $message_transport_type );
$sth->execute( $module, $code, $branchcode, $message_transport_type, $lang );
my $line = $sth->fetchrow_hashref
or return;
$line->{'content-type'} = 'text/html; charset="UTF-8"' if $line->{is_html};
......@@ -688,9 +690,13 @@ sub GetPreparedLetter {
my $mtt = $params{message_transport_type} || 'email';
my $lang = $params{lang} || 'default';
my $letter = getletter( $module, $letter_code, $branchcode, $mtt )
or warn( "No $module $letter_code letter transported by " . $mtt ),
return;
my $letter = getletter( $module, $letter_code, $branchcode, $mtt, $lang );
unless ( $letter ) {
$letter = getletter( $module, $letter_code, $branchcode, $mtt, 'default' )
or warn( "No $module $letter_code letter transported by " . $mtt ),
return;
}
my $tables = $params{tables} || {};
my $substitute = $params{substitute} || {};
......
......@@ -18,7 +18,7 @@
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use Test::More tests => 81;
use Test::More tests => 82;
use Test::MockModule;
use Test::Warn;
......@@ -534,6 +534,52 @@ is($mail{'To'}, 'john.smith@test.de', "mailto correct in sent serial notificatio
is($mail{'Message'}, 'Silence in the library,'.$subscriptionid.',No. 0', 'Serial notification text constructed successfully');
}
subtest 'TranslateNotices' => sub {
plan tests => 3;
$dbh->do(
q|
INSERT INTO letter (module, code, branchcode, name, title, content, message_transport_type, lang) VALUES
('test', 'code', '', 'test', 'a test', 'just a test', 'email', 'default'),
('test', 'code', '', 'test', 'una prueba', 'solo una prueba', 'email', 'es-ES');
| );
my $substitute = {};
my $letter = C4::Letters::GetPreparedLetter(
module => 'test',
letter_code => 'code',
message_transport_type => 'email',
substitute => $substitute,
);
is(
$letter->{title},
'a test',
'GetPreparedLetter should return the default one if the lang parameter is not provided'
);
$letter = C4::Letters::GetPreparedLetter(
module => 'test',
letter_code => 'code',
message_transport_type => 'email',
substitute => $substitute,
lang => 'es-ES',
);
is( $letter->{title}, 'una prueba',
'GetPreparedLetter should return the required notice if it exists' );
$letter = C4::Letters::GetPreparedLetter(
module => 'test',
letter_code => 'code',
message_transport_type => 'email',
substitute => $substitute,
lang => 'fr-FR',
);
is(
$letter->{title},
'a test',
'GetPreparedLetter should return the default notice if the one required does not exist'
);
};
subtest 'SendQueuedMessages' => sub {
plan tests => 1;
t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment