You are here

protected function DrupalTranslator::processParameters in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Validation/DrupalTranslator.php \Drupal\Core\Validation\DrupalTranslator::processParameters()

Processes the parameters array for use with t().

2 calls to DrupalTranslator::processParameters()
DrupalTranslator::trans in core/lib/Drupal/Core/Validation/DrupalTranslator.php
Translates the given message.
DrupalTranslator::transChoice in core/lib/Drupal/Core/Validation/DrupalTranslator.php
Translates the given choice message by choosing a translation according to a number.

File

core/lib/Drupal/Core/Validation/DrupalTranslator.php, line 77
Contains \Drupal\Core\Validation\DrupalTranslator.

Class

DrupalTranslator
Translates strings using Drupal's translation system.

Namespace

Drupal\Core\Validation

Code

protected function processParameters(array $parameters) {
  $return = array();
  foreach ($parameters as $key => $value) {

    // 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)) {

      // t() does not work with objects being passed as replacement strings.
    }
    elseif (strpos($key, '{{ ') === 0 && strrpos($key, ' }}') == strlen($key) - 3) {

      // Transform it into a Drupal pattern using the format %name.
      $key = '%' . substr($key, 3, strlen($key) - 6);
      $return[$key] = $value;
    }
    else {
      $return[$key] = $value;
    }
  }
  return $return;
}