diff --git a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php index efbe1cd..cc97fe4 100644 --- a/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php +++ b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php @@ -94,9 +94,21 @@ public function __construct($count, $singular, $plural, array $args = array(), a * An associative array of additional options. See t() for allowed keys. */ public static function createFromTranslatedString($count, $translated_string, array $args = array(), array $options = array()) { - $new = new static($count, '', '', $args, $options); - $new->translatedString = $translated_string; - return $new; + $safe = TRUE; + foreach (array_keys($args) as $arg_key) { + // If the string has arguments that start with '!' we consider it unsafe + // and return the translation as a string for backward compatibility + // purposes. + // @todo https://www.drupal.org/node/2570037 remove this temporary + // workaround. + if (0 === strpos($arg_key, '!') && !SafeMarkup::isSafe($args[$arg_key])) { + $safe = FALSE; + break; + } + } + $plural = new static($count, '', '', $args, $options); + $plural->translatedString = $translated_string; + return $safe ? $plural : (string) $plural; } /** diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index ea55c4d..973c465 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -191,8 +191,20 @@ protected function doTranslate($string, array $options = array()) { * {@inheritdoc} */ public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { + $safe = TRUE; + foreach (array_keys($args) as $arg_key) { + // If the string has arguments that start with '!' we consider it unsafe + // and return the translation as a string for backward compatibility + // purposes. + // @todo https://www.drupal.org/node/2570037 remove this temporary + // workaround. + if (0 === strpos($arg_key, '!') && !SafeMarkup::isSafe($args[$arg_key])) { + $safe = FALSE; + break; + } + } $plural = new PluralTranslatableString($count, $singular, $plural, $args, $options, $this); - return $plural; + return $safe ? $plural : (string) $plural; } /**