Skip to content

Commit 4534dbf

Browse files
Flinschnicolas-grekas
authored andcommitted
[TwigBridge] Fix #37931: BC break where filter method trans did not allow null values for $message parameter anymore
1 parent 3bac6a3 commit 4534dbf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Extension/TranslationExtension.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ public function getTranslationNodeVisitor(): TranslationNodeVisitor
9292
return $this->translationNodeVisitor ?: $this->translationNodeVisitor = new TranslationNodeVisitor();
9393
}
9494

95-
public function trans(string $message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string
95+
public function trans(?string $message, array $arguments = [], string $domain = null, string $locale = null, int $count = null): string
9696
{
97+
if (null === $message || '' === $message) {
98+
return '';
99+
}
100+
97101
if (null !== $count) {
98102
$arguments['%count%'] = $count;
99103
}

Tests/Extension/TranslationExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public function getTransTests()
118118
['{{ "{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]],
119119
['{{ 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%)']],
120120
['{{ "{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]],
121+
122+
// trans filter with null message
123+
['{{ null|trans }}', ''],
124+
['{{ foo|trans }}', '', ['foo' => null]],
121125
];
122126
}
123127

0 commit comments

Comments
 (0)