-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Translation] Handle the translation of empty strings #48833
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
Conversation
Hey! I think @rvanlaak has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
Hi @javiereguiluz, i can't reproduce the problem. When I translate Tried with a clean symfony 5.4 and 6.1 environment. UPDATE |
Why don't you use this code instead? $someCondition ? new TranslatableMessage($someObject->someMethod()) : '' It would make more sense to me. Why wrap the empty string in a translatable when it's not translatable content? |
Looking at Twig Bridge symfony/src/Symfony/Bridge/Twig/Extension/TranslationExtension.php Lines 99 to 122 in 1f7bc10
The behavior is different: (1) If we pass a string:
(2) It we pass a
That's why we don't get a "missing translation" warning when doing Would you agree to update |
I've changed the proposed solution completely. If you can, please review it again. Thanks. |
fbcc902
to
f195579
Compare
Thank you @javiereguiluz. |
In some apps, you might use an expression as the value of some
TranslatableMessage
object. The result of this expression can result in using an empty string as the value of the that object:The issue is that Symfony will report that empty string in the list of "missing translations" (like in the first row of this image):
I think this is a bug and an empty string should just be output "as is" without reporting it as missing.
What do you think? Is this truly a bug? Would it be a new feature for 6.3? The current behavior is correct and we should close without merging? Thanks.