diff --git a/core/lib/Drupal/Core/StringTranslation/PluralTranslatedString.php b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php similarity index 93% rename from core/lib/Drupal/Core/StringTranslation/PluralTranslatedString.php rename to core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php index 523fc4a..efbe1cd 100644 --- a/core/lib/Drupal/Core/StringTranslation/PluralTranslatedString.php +++ b/core/lib/Drupal/Core/StringTranslation/PluralTranslatableString.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\StringTranslation\PluralTranslatedString. + * Contains \Drupal\Core\StringTranslation\PluralTranslatableString. */ namespace Drupal\Core\StringTranslation; @@ -10,9 +10,9 @@ use Drupal\Component\Utility\PlaceholderTrait; /** - * A class to hold plural translated strings. + * A class to hold plural translatable strings. */ -class PluralTranslatedString extends TranslationWrapper { +class PluralTranslatableString extends TranslationWrapper { use PlaceholderTrait; /** @@ -81,7 +81,7 @@ public function __construct($count, $singular, $plural, array $args = array(), a * * @param int $count * The item count to display. - * @param string $translation + * @param string $translated_string * The already translated string. * @param array $args * An associative array of replacements to make after translation. Instances @@ -93,9 +93,9 @@ public function __construct($count, $singular, $plural, array $args = array(), a * @param array $options * An associative array of additional options. See t() for allowed keys. */ - public static function createFromTranslatedString($count, $translation, array $args = array(), array $options = array()) { + public static function createFromTranslatedString($count, $translated_string, array $args = array(), array $options = array()) { $new = new static($count, '', '', $args, $options); - $new->translatedString = $translation; + $new->translatedString = $translated_string; return $new; } diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php index e47dc9f..e5a5861 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php @@ -54,9 +54,10 @@ public function translateString(TranslationWrapper $translated_string); /** * Formats a string containing a count of items. * - * This function ensures that the string is pluralized correctly. Since t() is - * called by this function, make sure not to pass already-localized strings to - * it. See PluralTranslatedString::createFromTranslatedString() for that. + * This function ensures that the string is pluralized correctly. Since + * TranslationInterface::translate() is called by this function, make sure not + * to pass already-localized strings to it. See + * PluralTranslatableString::createFromTranslatedString() for that. * * For example: * @code @@ -91,13 +92,13 @@ public function translateString(TranslationWrapper $translated_string); * @param array $options * An associative array of additional options. See t() for allowed keys. * - * @return \Drupal\Core\StringTranslation\PluralTranslatedString + * @return \Drupal\Core\StringTranslation\PluralTranslatableString * A translated string. * - * @see self::translate() + * @see \Drupal\Core\StringTranslation\TranslationInterface::translate() * @see t() * @see \Drupal\Component\Utility\SafeMarkup::format() - * @see \Drupal\Core\StringTranslation\PluralTranslatedString::createFromTranslatedString() + * @see \Drupal\Core\StringTranslation\PluralTranslatableString::createFromTranslatedString() */ public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()); diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index 286e44e..ea55c4d 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -191,7 +191,7 @@ protected function doTranslate($string, array $options = array()) { * {@inheritdoc} */ public function formatPlural($count, $singular, $plural, array $args = array(), array $options = array()) { - $plural = new PluralTranslatedString($count, $singular, $plural, $args, $options, $this); + $plural = new PluralTranslatableString($count, $singular, $plural, $args, $options, $this); return $plural; } diff --git a/core/modules/locale/src/Tests/LocalePluralFormatTest.php b/core/modules/locale/src/Tests/LocalePluralFormatTest.php index 504cba0..dccdd81 100644 --- a/core/modules/locale/src/Tests/LocalePluralFormatTest.php +++ b/core/modules/locale/src/Tests/LocalePluralFormatTest.php @@ -7,7 +7,7 @@ namespace Drupal\locale\Tests; -use Drupal\Core\StringTranslation\PluralTranslatedString; +use Drupal\Core\StringTranslation\PluralTranslatableString; use Drupal\simpletest\WebTestBase; /** @@ -133,12 +133,12 @@ public function testGetPluralFormat() { $expected_plural_string = str_replace('@count', $count, $plural_strings[$langcode][$expected_plural_index]); $this->assertIdentical(\Drupal::translation()->formatPlural($count, '1 hour', '@count hours', array(), array('langcode' => $langcode))->render(), $expected_plural_string, '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 - // PluralTranslatedString::createFromTranslatedString() this way. It is + // PluralTranslatableString::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' . LOCALE_PLURAL_DELIMITER . '@count hours', array(), array('langcode' => $langcode)); - $plural = PluralTranslatedString::createFromTranslatedString($count, $translated_string, array(), array('langcode' => $langcode)); + $plural = PluralTranslatableString::createFromTranslatedString($count, $translated_string, array(), array('langcode' => $langcode)); $this->assertIdentical($plural->render(), $expected_plural_string); } } diff --git a/core/modules/views/src/Plugin/views/field/NumericField.php b/core/modules/views/src/Plugin/views/field/NumericField.php index c7fd024..e558de3 100644 --- a/core/modules/views/src/Plugin/views/field/NumericField.php +++ b/core/modules/views/src/Plugin/views/field/NumericField.php @@ -8,7 +8,7 @@ namespace Drupal\views\Plugin\views\field; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\StringTranslation\PluralTranslatedString; +use Drupal\Core\StringTranslation\PluralTranslatableString; use Drupal\views\ResultRow; /** @@ -175,7 +175,7 @@ public function render(ResultRow $values) { // If we should format as plural, take the (possibly) translated plural // setting and format with the current language. if (!empty($this->options['format_plural'])) { - $value = PluralTranslatedString::createFromTranslatedString($value, $this->options['format_plural_string']); + $value = PluralTranslatableString::createFromTranslatedString($value, $this->options['format_plural_string']); } return $this->sanitizeValue($this->options['prefix'], 'xss') diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 4413e58..ecb9c7f 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -13,7 +13,7 @@ use Drupal\Core\Cache\CacheTagsInvalidatorInterface; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Component\Utility\PlaceholderTrait; -use Drupal\Core\StringTranslation\PluralTranslatedString; +use Drupal\Core\StringTranslation\PluralTranslatableString; use Drupal\Core\StringTranslation\TranslationWrapper; /** @@ -233,7 +233,7 @@ public function getStringTranslationStub() { $translation->expects($this->any()) ->method('formatPlural') ->willReturnCallback(function ($count, $singular, $plural, array $args = [], array $options = []) use ($translation) { - $wrapper = new PluralTranslatedString($count, $singular, $plural, $args, $options, $translation); + $wrapper = new PluralTranslatableString($count, $singular, $plural, $args, $options, $translation); return $wrapper; }); return $translation;