SYMFONY VALIDATION TRANSLATOR

The Symfony validation translator module translates strings
from the Symfony validation constraint messages.

REQUIREMENTS
The module requires the Symfony component to be installed:
"symfony/translation": "~3.4.0"
The component should have been installed if you used composer
to install and add the module to your project.

CONFIGURATION
The module has no menu or modifiable settings. There is no configuration. When enabled.

Overriding Symfony translations
Sometimes you may need to override the Symfony translation.
In that case, just copy the original message from the Symfony
class and add it to your translation file as the `"msgid"`
for that particular language whose translation you are overriding into your custom module.

Import the new translation into Drupal.
Example:
Let's assume you want to override the original translated
string of the Dutch language. The original translated
Dutch string is

Dit is geen geldig internationaal bankrekeningnummer (IBAN).

"msgid" This is not a valid International Bank Account Number (IBAN).
"msgstr" Dit is geen valid IBAN nummer" 

Now the error message that will be shown will be coming from your custom module. To revert back to the Symfony translation,
just delete the custom translation, update the Drupal translations
and you will then see the original Symfony translation.

TROUBLESHOOTING
There are modules that will make your application break once you enable this module. This is because those modules are type coupling their dependencies. That type of programming approach leads to the application breaking when one of there dependencies is decorated.

Below are some of the known modules that are type coupling their dependencies.
- Entity clone: https://www.drupal.org/project/entity_clone
- Entity Browser: https://www.drupal.org/project/entity_browser
patch: https://www.drupal.org/project/entity_browser/issues/3100254#comment-133...

Solution:
You will need to patch those modules by changing their dependencies to type hint
an interface instead of a concrete implementation. In this case the above
modules make PHP throw a TypeError caused by one of there higher-level classes injecting concrete classes in their constructors i.e "Drupal\Core\StringTranslation\TranslationManager"
instead of injecting the interface :
"Drupal\Core\StringTranslation\TranslationInterface"
in their constructors.

Please do patch them by injecting the above interface in their constructors
instead of them injecting the implemented class.

Example:
In

Drupal\entity_browser\Permissions

The constructor is like below:

  /**
   * Constructs Permissions object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity manager service.
   * @param \Drupal\Core\StringTranslation\TranslationManager $translation
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, 
TranslationManager $translation) {

Please do change it to

  /**
   * Constructs Permissions object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity manager service.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $translation
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, 
TranslationInterface $translation) {

Take note of the

TranslationManager

changing to TranslationInterface.

Note
There are more contributed modules you may be using that are violating the D (dependency inversion) principle than the ones mentioned above. So take note of the errors you get when your application breaks.
In that case, you must patch them as described above.

Project information

  • caution Seeking new maintainer
    The current maintainers are looking for new people to take ownership.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Module categories: Multilingual
  • Created by bonrita on , updated
  • shieldStable releases for this project are covered by the security advisory policy.
    There are currently no supported stable releases.

Releases