diff --git a/Kernel/Language.pm b/Kernel/Language.pm index 72962c9613..129cd505c9 100644 --- a/Kernel/Language.pm +++ b/Kernel/Language.pm @@ -285,8 +285,16 @@ sub Translate { $Text = $Self->{Translation}->{$Text} || $Text; + my $SubRef; + + if ( ref $Text && 'ARRAY' eq ref $Text ) { + ($Text, $SubRef) = @{ $Text || [] }; + } + return $Text if !@Parameters; + @Parameters = $SubRef->( @Parameters ) if $SubRef && ref $SubRef && 'CODE' eq ref $SubRef; + for my $Count ( 0 .. $#Parameters ) { return $Text if !defined $Parameters[$Count]; $Text =~ s/\%(s|d)/$Parameters[$Count]/; diff --git a/scripts/test/Language.t b/scripts/test/Language.t index 9106bb8883..60782f7227 100644 --- a/scripts/test/Language.t +++ b/scripts/test/Language.t @@ -238,4 +238,19 @@ for my $Test (@Tests) { ); } +{ + $LanguageObject->{Translation}->{"This is a test for a new feature in Translate(). - %s %s"} = [ 'A simple Test - %s %s', \&ReplaceParams ]; + my $Translated = $LanguageObject->Translate("This is a test for a new feature in Translate(). - %s %s", "Znuny", "rocks!"); + + $Self->Is( + $Translated, + 'A simple Test - Perl is great!', + 'Replaced params for translated string', + ); + + sub ReplaceParams { + return "Perl", "is great!"; + } +} + 1;