function PluralTranslatableMarkup::createFromTranslatedString

Same name in other branches
  1. 9 core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\PluralTranslatableMarkup::createFromTranslatedString()
  2. 8.9.x core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\PluralTranslatableMarkup::createFromTranslatedString()
  3. 11.x core/lib/Drupal/Core/StringTranslation/PluralTranslatableMarkup.php \Drupal\Core\StringTranslation\PluralTranslatableMarkup::createFromTranslatedString()

Constructs a new class instance from already translated markup.

This method ensures that the string is pluralized correctly. As opposed to the __construct() method, this method is designed to be invoked with a string already translated (such as with configuration translation).

Parameters

int $count: The item count to display.

string $translated_string: The already translated string.

array $args: An associative array of replacements to make after translation. Instances of any key in this array are replaced with the corresponding value. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup. Note that you do not need to include @count in this array; this replacement is done automatically for the plural cases.

array $options: An associative array of additional options. See t() for allowed keys.

Return value

static A PluralTranslatableMarkup object.

3 calls to PluralTranslatableMarkup::createFromTranslatedString()
LocalePluralFormatTest::testGetPluralFormat in core/modules/locale/tests/src/Functional/LocalePluralFormatTest.php
Tests locale_get_plural() and \Drupal::translation()->formatPlural().
NumericField::render in core/modules/views/src/Plugin/views/field/NumericField.php
Renders the field.
PluralTranslatableMarkupTest::testMissingPluralTranslation in core/tests/Drupal/Tests/Core/StringTranslation/PluralTranslatableMarkupTest.php
Tests when the plural translation is missing.

File

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

Class

PluralTranslatableMarkup
A class to hold plural translatable markup.

Namespace

Drupal\Core\StringTranslation

Code

public static function createFromTranslatedString($count, $translated_string, array $args = [], array $options = []) {
    $plural = new static($count, '', '', $args, $options);
    $plural->translatedString = $translated_string;
    return $plural;
}

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