8000 [TwigBridge] allow null for $message of filter method `trans` by Flinsch · Pull Request #37941 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBridge] allow null for $message of filter method trans #37941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files. 8000
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Symfony/Bridge/Twig/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
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