Skip to content

Commit

Permalink
[TwigBridge] Fix #37931: BC break where filter method trans did not…
Browse files Browse the repository at this point in the history
… allow null values for `$message` parameter anymore
  • Loading branch information
Flinsch authored and nicolas-grekas committed Aug 26, 2020
1 parent 3bac6a3 commit 4534dbf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Extension/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ public function getTranslationNodeVisitor(): TranslationNodeVisitor
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;
}
Expand Down
4 changes: 4 additions & 0 deletions Tests/Extension/TranslationExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function getTransTests()
['{{ "{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]],
];
}

Expand Down

0 comments on commit 4534dbf

Please sign in to comment.