Skip to content

Commit 4b4b345

Browse files
javiereguiluznicolas-grekas
authored andcommitted
[Translation] Handle the translation of empty strings
1 parent 5a35a66 commit 4b4b345

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Extension/TranslationExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function trans($message, $arguments = [], string $domain = null, string $
116116
throw new \TypeError(sprintf('Argument 2 passed to "%s()" must be a locale passed as a string when the message is a "%s", "%s" given.', __METHOD__, TranslatableInterface::class, get_debug_type($arguments)));
117117
}
118118

119+
if ($message instanceof TranslatableMessage && '' === $message->getMessage()) {
120+
return '';
121+
}
122+
119123
return $message->trans($this->getTranslator(), $locale ?? (\is_string($arguments) ? $arguments : null));
120124
}
121125

Tests/Extension/TranslationExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function getTransTests()
124124
['{{ foo|trans }}', '', ['foo' => null]],
125125

126126
// trans object
127+
['{{ t("")|trans }}', ''],
127128
['{{ t("Hello")|trans }}', 'Hello'],
128129
['{{ t(name)|trans }}', 'Symfony', ['name' => 'Symfony']],
129130
['{{ t(hello, { \'%name%\': \'Symfony\' })|trans }}', 'Hello Symfony', ['hello' => 'Hello %name%']],

0 commit comments

Comments
 (0)