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
Web Profiler logs missing messages when setting the translation domain to false #21110
Comments
|
According to New in Symfony 2.7: Form and Validator Updates:
|
That's when you are using the Form component, but your example uses the |
My example was the simplest way to recreate the issue. I mentioned the form component in the description. No methods use the same underlying translator. |
Well, I am not able to reproduce your issue using a form. Do you have a custom form theme? |
Symfony's theme works around this issue by wrapping all calls to {{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }} This logic exists 9 times in the theme. Remembering to add it to custom form themes can be a challenge, and some third party or legacy themes might not apply the logic correctly. However, the logic could be removed entirely by applying my proposed changes. Would you be more open to this change if the issue was labeled a DX improvement rather than a bug? |
Even then, we couldn't make the change to the interface as that would mean a BC break. So, no, I do not see another solution than using form themes for this. |
How exactly is it a BC break? |
Because all implementations of the interface would need to be updated to still work even when they get passed a boolean value instead of a string. |
This wouldn't break any Symfony implementations that I'm aware of. If you're concerned about breaking third party implementations, would you like me to create a different issue about how there currently is not any logic to prevent users from using non-string values for domains when adding translations resources? The translation ID is cast to a string in some places, but aside from checking for a |
The |
Which is why my request was to modify I just want to improve the developer experience. |
But being able to pass |
Since the |
The |
Then shouldn't any implementations of Right now it seems like using a |
Well, we could avoid logging if the domain is |
I agree with @tonynelson19 and I'm trying to fix this in #21726. |
As the proposed fix did not get merged, nor a consensus on that it should be fixed, this issue should likely also be closed. If anything we now do have the option to make the interface "correct" in 4.x (or even 5.x) as we now have a base PHP version supporting nullable type hinting. |
I am closing here as the dicsussion in the related PR didn't reach a consensus. |
If you use a
false
translation domain to disable a translation, the web profiler displays the string as missing a translation. This commonly happens inside forms when using thetranslation_domain
andchoices_translation_domain
options, but can also happen when translating directly inside Twig.The following can recreate the issue on a new Symfony project.
This can be fixed by adding the following condition to the top of
DataCollectorTranslator::collectMessage
to prevent the web profiler from collecting the disabled translation.The same fix can be added to the top of
LoggingTranslator::log
to prevent a "Translation not found." warning from be logged.The text was updated successfully, but these errors were encountered: