[TwigBridge] Fix #37931: BC break where filter method trans
did not allow null values for $message
parameter anymore
This commit is contained in:
parent
92cb709222
commit
039fc80d6c
@ -92,8 +92,12 @@ final class TranslationExtension extends AbstractExtension
|
||||
return $this->translationNodeVisitor ?: $this->translationNodeVisitor = new TranslationNodeVisitor();
|
||||
}
|
||||
|
||||
public function trans(string $message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string
|
||||
public function trans(?string $message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string
|
||||
{
|
||||
if (null === $message || '' === $message) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (null !== $count) {
|
||||
$arguments['%count%'] = $count;
|
||||
}
|
||||
|
@ -118,6 +118,10 @@ class TranslationExtensionTest extends TestCase
|
||||
['{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|trans(count=count) }}', 'There is 5 apples', ['count' => 5]],
|
||||
['{{ text|trans(count=5, arguments={\'%name%\': \'Symfony\'}) }}', 'There is 5 apples (Symfony)', ['text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)']],
|
||||
['{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|trans({}, "messages", "fr", count) }}', 'There is 5 apples', ['count' => 5]],
|
||||
|
||||
// trans filter with null message
|
||||
['{{ null|trans }}', ''],
|
||||
['{{ foo|trans }}', '', ['foo' => null]],
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user