// Assert that the we get the right translation for that. Change the
// expected index as per the logic for translation lookups.
$expected_plural_index =
($count == 1
) ? 0 :
$expected_plural_index;
$expected_plural_string =
str_replace('@count',
$count,
$plural_strings[$langcode][$expected_plural_index]);
$this->
assertSame($expected_plural_string, \Drupal::
translation()->
formatPlural($count, '1 hour', '@count hours',
[],
['langcode' =>
$langcode])->
render(), 'Plural translation of 1 hours / @count hours for count ' .
$count . ' in ' .
$langcode . ' is ' .
$expected_plural_string);
// DO NOT use translation to pass translated strings into
// PluralTranslatableMarkup::createFromTranslatedString() this way. It
// is designed to be used with *already* translated text like settings
// from configuration. We use PHP translation here just because we have
// the expected result data in that format.
$translated_string = \Drupal::
translation()->
translate('1 hour' . PoItem::DELIMITER . '@count hours',
[],
['langcode' =>
$langcode]);
$plural = PluralTranslatableMarkup::
createFromTranslatedString($count,
$translated_string,
[],
['langcode' =>
$langcode]);
$this->
assertSame($expected_plural_string,
$plural->
render());
} } } /**
* Tests plural editing of DateFormatter strings.
*/
public function testPluralEditDateFormatter() { // Import some .po files with formulas to set up the environment.