W3cubDocs

/Drupal 8

public function PluralTranslatableMarkup::render

public PluralTranslatableMarkup::render()

Renders the object as a string.

Return value

string The translated string.

Overrides TranslatableMarkup::render

File

core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php, line 105

Class

PluralTranslatableMarkup
A class to hold plural translatable markup.

Namespace

Drupal\Core\StringTranslation

Code

public function render() {
  if (!$this->translatedString) {
    $this->translatedString = $this->getStringTranslation()->translateString($this);
  }
  if ($this->translatedString === '') {
    return '';
  }

  $arguments = $this->getArguments();
  $arguments['@count'] = $this->count;
  $translated_array = explode(static::DELIMITER, $this->translatedString);

  if ($this->count == 1) {
    return $this->placeholderFormat($translated_array[0], $arguments);
  }

  $index = $this->getPluralIndex();
  if ($index == 0) {
    // Singular form.
    $return = $translated_array[0];
  }
  else {
    if (isset($translated_array[$index])) {
      // N-th plural form.
      $return = $translated_array[$index];
    }
    else {
      // If the index cannot be computed or there's no translation, use the
      // second plural form as a fallback (which allows for most flexibility
      // with the replaceable @count value).
      $return = $translated_array[1];
    }
  }

  return $this->placeholderFormat($return, $arguments);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!StringTranslation!PluralTranslatableMarkup.php/function/PluralTranslatableMarkup::render/8.1.x