function PluralTranslatableMarkup::render

Same name in other branches
  1. 9 core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\PluralTranslatableMarkup::render()
  2. 8.9.x core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\PluralTranslatableMarkup::render()
  3. 11.x core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\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 98

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(PoItem::DELIMITER, $this->translatedString);
    $index = $this->getPluralIndex();
    if ($this->count == 1 || $index == 0 || count($translated_array) == 1) {
        // Singular form.
        $return = $translated_array[0];
    }
    else {
        // Nth plural form, fallback to second plural form.
        $return = $translated_array[$index] ?? $translated_array[1];
    }
    return $this->placeholderFormat($return, $arguments);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.