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

Comments

catch created an issue. See original summary.

alexpott’s picture

I'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

      // We allow the values in the parameters to be safe string objects. This
      // can be useful when we want to use parameter values that are
      // TranslatableMarkup.
      if ($value instanceof MarkupInterface) {
        $value = (string) $value;
      }
      if (is_object($value)) {
        // TranslatableMarkup does not work with objects being passed as
        // replacement strings.
      }

This does not do what we want really.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mikelutz’s picture

Also, 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()

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kim.pepper’s picture

Status: Active » Needs review
StatusFileSize
new18.56 KB

Found this issue when looking to use Symfony Validator for UploadedFile objects 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\TranslatorInterface to just using \Drupal\Core\StringTranslation\TranslationInterface.

Let's see how much breaks.

Status: Needs review » Needs work

The last submitted patch, 13: 3035839-13.patch, failed testing. View results

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new25.5 KB
new8.63 KB

Fix a few more test fails.

Status: Needs review » Needs work

The last submitted patch, 15: 3035839-15.patch, failed testing. View results

webflo’s picture

StatusFileSize
new1.67 KB

This is a small patch to address the double escaping from comment #2. Without getting rid of the DrupalTranslator class.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.