[TwigBridge] Fix #37931: BC break where filter method trans did not allow null values for $message parameter anymore

This commit is contained in:
Flinsch 2020-08-25 14:44:21 +02:00 committed by Nicolas Grekas
parent 92cb709222
commit 039fc80d6c
2 changed files with 9 additions and 1 deletions

View File

@ -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;
}

View File

@ -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]],
];
}