-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[Validator] Allow to use translation_domain false for validators and to… #18325
Comments
In case this helps: Disabling Translation Domain in Validators
===========================================
As of Symfony 6.3, it is possible to disable the translation domain for validators, allowing you to
control how and when validator messages are translated.
When defining a constraint, you typically provide a message that will be shown when the constraint
fails. By default, this message is translated using the validator's translation domain. However,
you can now disable this behavior if you want to use the message as is.
To disable the translation domain, use the `disableTranslation()` method on the
`ConstraintViolationBuilderInterface` object, like this:
.. code-block:: php
$builder->disableTranslation();
This will prevent the validator from translating the violation message.
When the translation domain is disabled, any parameters in the violation message will still be
replaced with their corresponding values. However, the message itself will not be translated.
You can also set the translation domain to `null` or a string. If it's `null`, the default
translation domain will be used. If it's a string, that string will be used as the translation
domain.
.. note::
Disabling the translation domain is a global setting. It affects all violation messages added
after it's called, not just the next one. To re-enable the default translation behavior, you'll
need to manually set the translation domain back to `null` or a specific domain.
.. code-block:: php
$builder->setTranslationDomain(null);
|
I tried to document this feature with the text given by Nicolas, but it's complicated:
We only mention |
Thank you for this issue. |
Seems like a PR from @alexandre-daubois symfony/symfony#50797 is needed first |
Oh, totally forgot about this one. I rebased the PR on 7.2 |
Would this allow me to disable automatic translations for the validator as well? Would be very convenient if this could disable an API from delivering the translated texts instead of error codes.
|
We created this issue to not forget to document this new feature. We would really appreciate if you can help us with this task. If you are not sure how to do it, please ask us and we will help you.
To fix this issue, please create a PR against the 6.3 branch in the symfony-docs repository.
Thank you! 😃
The text was updated successfully, but these errors were encountered: