From 49a45db6f876bd8078f8ad804244c63e4e31df75 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Tue, 19 Jun 2018 11:37:56 +0100
Subject: [PATCH] Issue #2979944 by alexpott: Remove t() usage in
 Drupal\Core\Validation

---
 .../Drupal/Core/Validation/DrupalTranslator.php   | 15 ++++++++++-----
 .../Context/ContextDefinitionIsSatisfiedTest.php  | 10 ----------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php
index 505decaff2ca..12b9594c4a6e 100644
--- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php
+++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php
@@ -25,7 +25,10 @@ class DrupalTranslator implements TranslatorInterface {
   public function trans($id, array $parameters = [], $domain = NULL, $locale = NULL) {
     // If a TranslatableMarkup object is passed in as $id, return it since the
     // message has already been translated.
-    return $id instanceof TranslatableMarkup ? $id : t($id, $this->processParameters($parameters), $this->getOptions($domain, $locale));
+    if ($id instanceof TranslatableMarkup) {
+      return $id;
+    }
+    return new TranslatableMarkup($id, $this->processParameters($parameters), $this->getOptions($domain, $locale));
   }
 
   /**
@@ -67,7 +70,7 @@ public function getLocale() {
   }
 
   /**
-   * Processes the parameters array for use with t().
+   * Processes the parameters array for use with TranslatableMarkup.
    */
   protected function processParameters(array $parameters) {
     $return = [];
@@ -79,7 +82,8 @@ protected function processParameters(array $parameters) {
         $value = (string) $value;
       }
       if (is_object($value)) {
-        // t() does not work with objects being passed as replacement strings.
+        // TranslatableMarkup does not work with objects being passed as
+        // replacement strings.
       }
       // Check for symfony replacement patterns in the form "{{ name }}".
       elseif (strpos($key, '{{ ') === 0 && strrpos($key, ' }}') == strlen($key) - 3) {
@@ -95,11 +99,12 @@ protected function processParameters(array $parameters) {
   }
 
   /**
-   * Returns options suitable for use with t().
+   * Returns options suitable for use with TranslatableMarkup.
    */
   protected function getOptions($domain = NULL, $locale = NULL) {
     // We do not support domains, so we ignore this parameter.
-    // If locale is left NULL, t() will default to the interface language.
+    // If locale is left NULL, TranslatableMarkup will default to the interface
+    // language.
     $locale = isset($locale) ? $locale : $this->locale;
     return ['langcode' => $locale];
   }
diff --git a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
index 53d16ffe2187..ce33d7fe54a9 100644
--- a/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
+++ b/core/tests/Drupal/Tests/Core/Plugin/Context/ContextDefinitionIsSatisfiedTest.php
@@ -342,13 +342,3 @@ public function providerTestIsSatisfiedByPassBundledEntity() {
   }
 
 }
-
-namespace Drupal\Core\Validation;
-
-if (!function_exists('t')) {
-
-  function t($string, array $args = []) {
-    return strtr($string, $args);
-  }
-
-}
-- 
GitLab