'hu' =>
[ 1 => -1,
21 => -1,
0 => -1,
],
];
foreach ($plural_tests as $langcode =>
$tests) { foreach ($tests as $count =>
$expected_plural_index) { // Assert that the we get the right plural index.
$this->
assertSame($expected_plural_index,
locale_get_plural($count,
$langcode), 'Computed plural index for ' .
$langcode . ' for count ' .
$count . ' is ' .
$expected_plural_index);
// 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]);