Problem/Motivation
DrupalTranslator was added as a bridge to the Symfony Translation component - because when we added the Validation component it required the Translation component in order to use TranslatorInterface.
However, we don't actually use any Symfony code that directly relies on TranslatorInterface at all, so DrupalTranslation is a bridge to nothing, consumed only by Drupal code.
Symfony has moved TranslatorInterface to Symfony/Contracts per #3030485: [Symfony 5] The "Drupal\Core\Validation\TranslatorInterface" interface extends "Symfony\Component\Translation\TranslatorInterface" that is deprecated since Symfony 4.2, use Symfony\Contracts\Translation\TranslatorInterface instead., but as shown in that issue, we can probably live with out it.
Proposed resolution
See if we can deprecate DrupalTranslator entirely, rework any code relying on it to use TranslatableMarkup directly.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 3035839-17.patch | 1.67 KB | webflo |
| #15 | 3035839-15-interdiff.txt | 8.63 KB | kim.pepper |
| #15 | 3035839-15.patch | 25.5 KB | kim.pepper |
Comments
Comment #2
alexpottI've also noticed that in the current implementation we're incorrectly casting MarkupInterface objects before doing parameter replacement. This could result in double escaped html. In \Drupal\Core\Validation\DrupalTranslator::processParameters() we do
This does not do what we want really.
Comment #4
mikelutzAlso, DrupalTranslator::trans() is in violation of its own interface, by returning a TranslatableMarkup Object when the interface declares the return value to be a string. This is one of the roots of the interface violations causing us such headache in #3029540: [Symfony 4] Sub class \Symfony\Component\Validator\ConstraintViolation and use that in \Drupal\Core\TypedData\Validation\ExecutionContext::addViolation()
Comment #13
kim.pepperFound this issue when looking to use Symfony Validator for
UploadedFileobjects in #3375447: Create an UploadedFile validator and deprecate error checking methods on UploadedFileInterface.As far as I can see, we need to swap out our ExecutionContext implementation from using
\Drupal\Core\Validation\TranslatorInterfaceto just using\Drupal\Core\StringTranslation\TranslationInterface.Let's see how much breaks.
Comment #15
kim.pepperFix a few more test fails.
Comment #17
webflo commentedThis is a small patch to address the double escaping from comment #2. Without getting rid of the DrupalTranslator class.