diff --git a/core/includes/common.inc b/core/includes/common.inc index ece80d1..ceb0f80 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -25,7 +25,7 @@ use Drupal\Core\Render\SafeString; use Drupal\Core\Render\Renderer; use Drupal\Core\Site\Settings; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\Url; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Request; @@ -261,7 +261,7 @@ function check_url($uri) { * Optional language code to translate to a language other than what is used * to display the page. * - * @return \Drupal\Core\StringTranslation\TranslationWrapper + * @return \Drupal\Core\StringTranslation\TranslatedString * A translated string representation of the size. */ function format_size($size, $langcode = NULL) { @@ -283,21 +283,21 @@ function format_size($size, $langcode = NULL) { $options = ['langcode' => $langcode]; switch ($unit) { case 'KB': - return new TranslationWrapper('@size KB', $args, $options); + return new TranslatedString('@size KB', $args, $options); case 'MB': - return new TranslationWrapper('@size MB', $args, $options); + return new TranslatedString('@size MB', $args, $options); case 'GB': - return new TranslationWrapper('@size GB', $args, $options); + return new TranslatedString('@size GB', $args, $options); case 'TB': - return new TranslationWrapper('@size TB', $args, $options); + return new TranslatedString('@size TB', $args, $options); case 'PB': - return new TranslationWrapper('@size PB', $args, $options); + return new TranslatedString('@size PB', $args, $options); case 'EB': - return new TranslationWrapper('@size EB', $args, $options); + return new TranslatedString('@size EB', $args, $options); case 'ZB': - return new TranslationWrapper('@size ZB', $args, $options); + return new TranslatedString('@size ZB', $args, $options); case 'YB': - return new TranslationWrapper('@size YB', $args, $options); + return new TranslatedString('@size YB', $args, $options); } } } diff --git a/core/lib/Drupal/Component/Utility/PlaceholderTrait.php b/core/lib/Drupal/Component/Utility/PlaceholderTrait.php index 0592c37..c61b0e4 100644 --- a/core/lib/Drupal/Component/Utility/PlaceholderTrait.php +++ b/core/lib/Drupal/Component/Utility/PlaceholderTrait.php @@ -26,7 +26,7 @@ * The string with the placeholders replaced. * * @see \Drupal\Component\Utility\SafeMarkup::format() - * @see \Drupal\Core\StringTranslation\TranslationWrapper::render() + * @see \Drupal\Core\StringTranslation\TranslatedString::render() */ protected static function placeholderFormat($string, array $args, &$safe = TRUE) { // Transform arguments before inserting them. diff --git a/core/lib/Drupal/Core/Annotation/ContextDefinition.php b/core/lib/Drupal/Core/Annotation/ContextDefinition.php index e820f0c..36d4879 100644 --- a/core/lib/Drupal/Core/Annotation/ContextDefinition.php +++ b/core/lib/Drupal/Core/Annotation/ContextDefinition.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Annotation; use Drupal\Component\Annotation\Plugin; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * @defgroup plugin_context Annotation for context definition @@ -113,7 +113,7 @@ public function __construct(array $values) { // used in the classes they pass to. foreach (['label', 'description'] as $key) { // @todo Remove this workaround in https://www.drupal.org/node/2362727. - if (isset($values[$key]) && $values[$key] instanceof TranslationWrapper) { + if (isset($values[$key]) && $values[$key] instanceof TranslatedString) { $values[$key] = (string) $values[$key]->get(); } else { diff --git a/core/lib/Drupal/Core/Annotation/Translation.php b/core/lib/Drupal/Core/Annotation/Translation.php index e1cc845..73ba367 100644 --- a/core/lib/Drupal/Core/Annotation/Translation.php +++ b/core/lib/Drupal/Core/Annotation/Translation.php @@ -8,7 +8,7 @@ namespace Drupal\Core\Annotation; use Drupal\Component\Annotation\AnnotationBase; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * @defgroup plugin_translatable Annotation for translatable text @@ -60,7 +60,7 @@ class Translation extends AnnotationBase { /** * The string translation object. * - * @var \Drupal\Core\StringTranslation\TranslationWrapper + * @var \Drupal\Core\StringTranslation\TranslatedString */ protected $translation; @@ -86,7 +86,7 @@ public function __construct(array $values) { 'context' => $values['context'], ); } - $this->translation = new TranslationWrapper($string, $arguments, $options); + $this->translation = new TranslatedString($string, $arguments, $options); } /** diff --git a/core/lib/Drupal/Core/Block/BlockBase.php b/core/lib/Drupal/Core/Block/BlockBase.php index 8c97809..66cfba8 100644 --- a/core/lib/Drupal/Core/Block/BlockBase.php +++ b/core/lib/Drupal/Core/Block/BlockBase.php @@ -47,7 +47,7 @@ public function label() { $definition = $this->getPluginDefinition(); // Cast the admin label to a string since it is an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper + // @see \Drupal\Core\StringTranslation\TranslatedString return (string) $definition['admin_label']; } diff --git a/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php index 4720b35..6fa6df5 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/ConfigEntityType.php @@ -6,7 +6,7 @@ */ namespace Drupal\Core\Entity\Annotation; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Defines a config entity type annotation object. @@ -37,7 +37,7 @@ class ConfigEntityType extends EntityType { * {@inheritdoc} */ public function get() { - $this->definition['group_label'] = new TranslationWrapper('Configuration', array(), array('context' => 'Entity type group')); + $this->definition['group_label'] = new TranslatedString('Configuration', array(), array('context' => 'Entity type group')); return parent::get(); } diff --git a/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php b/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php index 34363a5..b92d736 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php @@ -6,7 +6,7 @@ */ namespace Drupal\Core\Entity\Annotation; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Defines a content entity type annotation object. @@ -37,7 +37,7 @@ class ContentEntityType extends EntityType { * {@inheritdoc} */ public function get() { - $this->definition['group_label'] = new TranslationWrapper('Content', array(), array('context' => 'Entity type group')); + $this->definition['group_label'] = new TranslatedString('Content', array(), array('context' => 'Entity type group')); return parent::get(); } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php index 34ebe4a..6a7e690 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php @@ -12,7 +12,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\OptionsProviderInterface; use Drupal\Core\TypedData\DataDefinition; @@ -34,8 +34,8 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface { */ public static function defaultFieldSettings() { return array( - 'on_label' => new TranslationWrapper('On'), - 'off_label' => new TranslationWrapper('Off'), + 'on_label' => new TranslatedString('On'), + 'off_label' => new TranslatedString('Off'), ) + parent::defaultFieldSettings(); } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php index 29e00a3..674c430 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -13,7 +13,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataReferenceDefinition; @@ -83,19 +83,19 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel if ($target_id_data_type === 'integer') { $target_id_definition = DataDefinition::create('integer') - ->setLabel(new TranslationWrapper('@label ID', ['@label' => $target_type_info->getLabel()])) + ->setLabel(new TranslatedString('@label ID', ['@label' => $target_type_info->getLabel()])) ->setSetting('unsigned', TRUE); } else { $target_id_definition = DataDefinition::create('string') - ->setLabel(new TranslationWrapper('@label ID', ['@label' => $target_type_info->getLabel()])); + ->setLabel(new TranslatedString('@label ID', ['@label' => $target_type_info->getLabel()])); } $target_id_definition->setRequired(TRUE); $properties['target_id'] = $target_id_definition; $properties['entity'] = DataReferenceDefinition::create('entity') ->setLabel($target_type_info->getLabel()) - ->setDescription(new TranslationWrapper('The referenced entity')) + ->setDescription(new TranslatedString('The referenced entity')) // The entity object is computed out of the entity ID. ->setComputed(TRUE) ->setReadOnly(FALSE) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php index 621bb63..52290ae 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/PasswordItem.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityMalformedException; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\DataDefinition; /** @@ -29,10 +29,10 @@ class PasswordItem extends StringItem { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') - ->setLabel(new TranslationWrapper('The hashed password')) + ->setLabel(new TranslatedString('The hashed password')) ->setSetting('case_sensitive', TRUE); $properties['existing'] = DataDefinition::create('string') - ->setLabel(new TranslationWrapper('Existing password')); + ->setLabel(new TranslatedString('Existing password')); return $properties; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php index 065310c..8cc47e5 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php @@ -9,7 +9,7 @@ use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\DataDefinition; /** @@ -31,9 +31,9 @@ public static function defaultStorageSettings() { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { // This is called very early by the user entity roles field. Prevent - // early t() calls by using the TranslationWrapper. + // early t() calls by using the TranslatedString. $properties['value'] = DataDefinition::create('string') - ->setLabel(new TranslationWrapper('Text value')) + ->setLabel(new TranslatedString('Text value')) ->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive')) ->setRequired(TRUE); diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index 2fd1597..773290e 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\Url; /** @@ -109,13 +109,13 @@ public function getLanguageTypes() { public function getDefinedLanguageTypesInfo() { $this->definedLanguageTypesInfo = array( LanguageInterface::TYPE_INTERFACE => array( - 'name' => new TranslationWrapper('Interface text'), - 'description' => new TranslationWrapper('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), + 'name' => new TranslatedString('Interface text'), + 'description' => new TranslatedString('Order of language detection methods for interface text. If a translation of interface text is available in the detected language, it will be displayed.'), 'locked' => TRUE, ), LanguageInterface::TYPE_CONTENT => array( - 'name' => new TranslationWrapper('Content'), - 'description' => new TranslationWrapper('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), + 'name' => new TranslatedString('Content'), + 'description' => new TranslatedString('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), 'locked' => TRUE, ), LanguageInterface::TYPE_URL => array( @@ -210,16 +210,16 @@ public function getDefaultLockedLanguages($weight = 0) { 'direction' => LanguageInterface::DIRECTION_LTR, ); // This is called very early while initializing the language system. Prevent - // early t() calls by using the TranslationWrapper. + // early t() calls by using the TranslatedString. $languages[LanguageInterface::LANGCODE_NOT_SPECIFIED] = new Language(array( 'id' => LanguageInterface::LANGCODE_NOT_SPECIFIED, - 'name' => new TranslationWrapper('Not specified'), + 'name' => new TranslatedString('Not specified'), 'weight' => ++$weight, ) + $locked_language); $languages[LanguageInterface::LANGCODE_NOT_APPLICABLE] = new Language(array( 'id' => LanguageInterface::LANGCODE_NOT_APPLICABLE, - 'name' => new TranslationWrapper('Not applicable'), + 'name' => new TranslatedString('Not applicable'), 'weight' => ++$weight, ) + $locked_language); diff --git a/core/lib/Drupal/Core/Logger/RfcLogLevel.php b/core/lib/Drupal/Core/Logger/RfcLogLevel.php index c298225..2d70500 100644 --- a/core/lib/Drupal/Core/Logger/RfcLogLevel.php +++ b/core/lib/Drupal/Core/Logger/RfcLogLevel.php @@ -7,7 +7,7 @@ namespace Drupal\Core\Logger; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * @defgroup logging_severity_levels Logging severity levels @@ -96,14 +96,14 @@ class RfcLogLevel { public static function getLevels() { if (!static::$levels) { static::$levels = [ - static::EMERGENCY => new TranslationWrapper('Emergency'), - static::ALERT => new TranslationWrapper('Alert'), - static::CRITICAL => new TranslationWrapper('Critical'), - static::ERROR => new TranslationWrapper('Error'), - static::WARNING => new TranslationWrapper('Warning'), - static::NOTICE => new TranslationWrapper('Notice'), - static::INFO => new TranslationWrapper('Info'), - static::DEBUG => new TranslationWrapper('Debug'), + static::EMERGENCY => new TranslatedString('Emergency'), + static::ALERT => new TranslatedString('Alert'), + static::CRITICAL => new TranslatedString('Critical'), + static::ERROR => new TranslatedString('Error'), + static::WARNING => new TranslatedString('Warning'), + static::NOTICE => new TranslatedString('Notice'), + static::INFO => new TranslatedString('Info'), + static::DEBUG => new TranslatedString('Debug'), ]; } diff --git a/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php b/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php index 19671fe..7771bef 100644 --- a/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php +++ b/core/lib/Drupal/Core/Menu/ContextualLinkDefault.php @@ -19,7 +19,7 @@ class ContextualLinkDefault extends PluginBase implements ContextualLinkInterfac * {@inheritdoc} */ public function getTitle(Request $request = NULL) { - // The title from YAML file discovery may be a TranslationWrapper object. + // The title from YAML file discovery may be a TranslatedString object. return (string) $this->pluginDefinition['title']; } diff --git a/core/lib/Drupal/Core/Menu/LocalActionDefault.php b/core/lib/Drupal/Core/Menu/LocalActionDefault.php index b0109a9..55ff28a 100644 --- a/core/lib/Drupal/Core/Menu/LocalActionDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalActionDefault.php @@ -71,7 +71,7 @@ public function getRouteName() { */ public function getTitle(Request $request = NULL) { // Subclasses may pull in the request or specific attributes as parameters. - // The title from YAML file discovery may be a TranslationWrapper object. + // The title from YAML file discovery may be a TranslatedString object. return (string) $this->pluginDefinition['title']; } diff --git a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php index dd41d87..afc8200 100644 --- a/core/lib/Drupal/Core/Menu/LocalTaskDefault.php +++ b/core/lib/Drupal/Core/Menu/LocalTaskDefault.php @@ -80,7 +80,7 @@ public function getRouteParameters(RouteMatchInterface $route_match) { * {@inheritdoc} */ public function getTitle(Request $request = NULL) { - // The title from YAML file discovery may be a TranslationWrapper object. + // The title from YAML file discovery may be a TranslatedString object. return (string) $this->pluginDefinition['title']; } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkManager.php b/core/lib/Drupal/Core/Menu/MenuLinkManager.php index 6a4a510..31d5b8b 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkManager.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkManager.php @@ -41,10 +41,10 @@ class MenuLinkManager implements MenuLinkManagerInterface { // The external URL if this link has one (required if route_name is empty). 'url' => '', // The static title for the menu link. If this came from a YAML definition - // or other safe source this may be a TranslationWrapper object. + // or other safe source this may be a TranslatedString object. 'title' => '', // The description. If this came from a YAML definition or other safe source - // this may be be a TranslationWrapper object. + // this may be be a TranslatedString object. 'description' => '', // The plugin ID of the parent link (or NULL for a top-level link). 'parent' => '', diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 277ab4d..123f945 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -1262,14 +1262,14 @@ protected static function schemaDefinition() { 'default' => '', ), 'title' => array( - 'description' => 'The serialized title for the link. May be a TranslationWrapper.', + 'description' => 'The serialized title for the link. May be a TranslatedString.', 'type' => 'blob', 'size' => 'big', 'not null' => FALSE, 'serialize' => TRUE, ), 'description' => array( - 'description' => 'The serialized description of this link - used for admin pages and title attribute. May be a TranslationWrapper.', + 'description' => 'The serialized description of this link - used for admin pages and title attribute. May be a TranslatedString.', 'type' => 'blob', 'size' => 'big', 'not null' => FALSE, diff --git a/core/lib/Drupal/Core/Menu/menu.api.php b/core/lib/Drupal/Core/Menu/menu.api.php index 0ae528f..4faa48f 100644 --- a/core/lib/Drupal/Core/Menu/menu.api.php +++ b/core/lib/Drupal/Core/Menu/menu.api.php @@ -235,10 +235,10 @@ * The value corresponding to each machine name key is an associative array * that may contain the following key-value pairs: * - title: (required) The title of the menu link. If this should be - * translated, create a \Drupal\Core\StringTranslation\TranslationWrapper + * translated, create a \Drupal\Core\StringTranslation\TranslatedString * object. * - description: The description of the link. If this should be - * translated, create a \Drupal\Core\StringTranslation\TranslationWrapper + * translated, create a \Drupal\Core\StringTranslation\TranslatedString * object. * - route_name: (optional) The route name to be used to build the path. * Either the route_name or url element must be provided. @@ -264,13 +264,13 @@ function hook_menu_links_discovered_alter(&$links) { // Change the weight and title of the user.logout link. $links['user.logout']['weight'] = -10; - $links['user.logout']['title'] = new \Drupal\Core\StringTranslation\TranslationWrapper('Logout'); + $links['user.logout']['title'] = new \Drupal\Core\StringTranslation\TranslatedString('Logout'); // Conditionally add an additional link with a title that's not translated. if (\Drupal::moduleHandler()->moduleExists('search')) { $links['menu.api.search'] = array( 'title' => \Drupal::config('system.site')->get('name'), 'route_name' => 'menu.api.search', - 'description' => new \Drupal\Core\StringTranslation\TranslationWrapper('View popular search phrases for this site.'), + 'description' => new \Drupal\Core\StringTranslation\TranslatedString('View popular search phrases for this site.'), 'parent' => 'system.admin_reports', ); } diff --git a/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php index 0d519f4..f347555 100644 --- a/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php +++ b/core/lib/Drupal/Core/Plugin/Discovery/YamlDiscovery.php @@ -10,7 +10,7 @@ use Drupal\Component\Plugin\Discovery\DiscoveryInterface; use Drupal\Component\Discovery\YamlDiscovery as ComponentYamlDiscovery; use Drupal\Component\Plugin\Discovery\DiscoveryTrait; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Allows YAML files to define plugin definitions. @@ -18,7 +18,7 @@ * If the value of a key (like title) in the definition is translatable then * the addTranslatableProperty() method can be used to mark it as such and also * to add translation context. Then - * \Drupal\Core\StringTranslation\TranslationWrapper will be used to translate + * \Drupal\Core\StringTranslation\TranslatedString will be used to translate * the string and also to mark it safe. Only strings written in the YAML files * should be marked as safe, strings coming from dynamic plugin definitions * potentially containing user input should not. @@ -93,7 +93,7 @@ public function getDefinitions() { $options['context'] = $definition[$context_key]; unset($definition[$context_key]); } - $definition[$property] = new TranslationWrapper($definition[$property], [], $options); + $definition[$property] = new TranslatedString($definition[$property], [], $options); } } // Add ID and provider. diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php b/core/lib/Drupal/Core/StringTranslation/TranslatedString.php similarity index 97% copy from core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php copy to core/lib/Drupal/Core/StringTranslation/TranslatedString.php index 7b4abfc..98a9d2f 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslatedString.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\StringTranslation\TranslationWrapper. + * Contains \Drupal\Core\StringTranslation\TranslatedString. */ namespace Drupal\Core\StringTranslation; @@ -23,7 +23,7 @@ * @see \Drupal\Core\StringTranslation\TranslationManager::translateString() * @see \Drupal\Core\Annotation\Translation */ -class TranslationWrapper implements SafeStringInterface { +class TranslatedString implements SafeStringInterface { use PlaceholderTrait; use ToStringTrait; diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php index 836ad0b..6f77151 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php @@ -33,7 +33,7 @@ * what is used to display the page. * - 'context': The context the source string belongs to. * - * @return string|\Drupal\Core\StringTranslation\TranslationWrapper + * @return string|\Drupal\Core\StringTranslation\TranslatedString * The translated string. * * @see \Drupal\Component\Utility\SafeMarkup::format() @@ -41,15 +41,15 @@ public function translate($string, array $args = array(), array $options = array()); /** - * Translates a TranslationWrapper object to a string. + * Translates a TranslatedString object to a string. * - * @param \Drupal\Core\StringTranslation\TranslationWrapper $translated_string - * A TranslationWrapper object. + * @param \Drupal\Core\StringTranslation\TranslatedString $translated_string + * A TranslatedString object. * * @return string * The translated string. */ - public function translateString(TranslationWrapper $translated_string); + public function translateString(TranslatedString $translated_string); /** * Formats a string containing a count of items. diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php index 5bf6a9d..eb50d2d 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationManager.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationManager.php @@ -152,14 +152,14 @@ public function translate($string, array $args = array(), array $options = array break; } } - $wrapper = new TranslationWrapper($string, $args, $options, $this); + $wrapper = new TranslatedString($string, $args, $options, $this); return $safe ? $wrapper : (string) $wrapper; } /** * {@inheritdoc} */ - public function translateString(TranslationWrapper $translated_string) { + public function translateString(TranslatedString $translated_string) { return $this->doTranslate($translated_string->getUntranslatedString(), $translated_string->getOptions()); } diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php index 7b4abfc..e03848e 100644 --- a/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php +++ b/core/lib/Drupal/Core/StringTranslation/TranslationWrapper.php @@ -7,177 +7,10 @@ namespace Drupal\Core\StringTranslation; -use Drupal\Component\Utility\PlaceholderTrait; -use Drupal\Component\Utility\SafeStringInterface; -use Drupal\Component\Utility\ToStringTrait; - /** * Provides translatable string class. * - * This class delays translating strings until rendering them. - * - * This is useful for using translation in very low level subsystems like entity - * definition and stream wrappers. - * - * @see \Drupal\Core\StringTranslation\TranslationManager::translate() - * @see \Drupal\Core\StringTranslation\TranslationManager::translateString() - * @see \Drupal\Core\Annotation\Translation + * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. + * Use the \Drupal\Core\StringTranslation\TranslatedString class instead. */ -class TranslationWrapper implements SafeStringInterface { - - use PlaceholderTrait; - use ToStringTrait; - - /** - * The string to be translated. - * - * @var string - */ - protected $string; - - /** - * The translated string without placeholder replacements. - * - * @var string - */ - protected $translatedString; - - /** - * The translation arguments. - * - * @var array - */ - protected $arguments; - - /** - * The translation options. - * - * @var array - */ - protected $options; - - /** - * The string translation service. - * - * @var \Drupal\Core\StringTranslation\TranslationInterface - */ - protected $stringTranslation; - - /** - * Constructs a new class instance. - * - * Parses values passed into this class through the t() function in Drupal and - * handles an optional context for the string. - * - * @param string $string - * The string that is to be translated. - * @param array $arguments - * (optional) An array with placeholder replacements, keyed by placeholder. - * @param array $options - * (optional) An array of additional options. - * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation - * (optional) The string translation service. - */ - public function __construct($string, array $arguments = array(), array $options = array(), TranslationInterface $string_translation = NULL) { - $this->string = $string; - $this->arguments = $arguments; - $this->options = $options; - $this->stringTranslation = $string_translation; - } - - /** - * Gets the untranslated string value stored in this translation wrapper. - * - * @return string - * The string stored in this wrapper. - */ - public function getUntranslatedString() { - return $this->string; - } - - /** - * Gets a specific option from this translation wrapper. - * - * @param $name - * Option name. - * - * @return mixed - * The value of this option or empty string of option is not set. - */ - public function getOption($name) { - return isset($this->options[$name]) ? $this->options[$name] : ''; - } - - /** - * Gets all options from this translation wrapper. - * - * @return mixed[] - * The array of options. - */ - public function getOptions() { - return $this->options; - } - - /** - * Gets all argments from this translation wrapper. - * - * @return mixed[] - * The array of arguments. - */ - public function getArguments() { - return $this->arguments; - } - - /** - * Renders the object as a string. - * - * @return string - * The translated string. - */ - public function render() { - if (!isset($this->translatedString)) { - $this->translatedString = $this->getStringTranslation()->translateString($this); - } - - // Handle any replacements. - // @todo https://www.drupal.org/node/2509218 Note that the argument - // replacement is not stored so that different sanitization strategies can - // be used in different contexts. - if ($args = $this->getArguments()) { - return $this->placeholderFormat($this->translatedString, $args); - } - return $this->translatedString; - } - - /** - * Magic __sleep() method to avoid serializing the string translator. - */ - public function __sleep() { - return array('string', 'arguments', 'options'); - } - - /** - * Returns a representation of the object for use in JSON serialization. - * - * @return string - * The safe string content. - */ - public function jsonSerialize() { - return $this->__toString(); - } - - /** - * Gets the string translation service. - * - * @return \Drupal\Core\StringTranslation\TranslationInterface - * The string translation service. - */ - protected function getStringTranslation() { - if (!$this->stringTranslation) { - $this->stringTranslation = \Drupal::service('string_translation'); - } - - return $this->stringTranslation; - } - -} +class TranslationWrapper extends TranslatedString {} diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index e8b276f..8863926 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -11,7 +11,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Constraint plugin manager. @@ -91,22 +91,22 @@ public function create($name, $options) { */ public function registerDefinitions() { $this->getDiscovery()->setDefinition('Callback', array( - 'label' => new TranslationWrapper('Callback'), + 'label' => new TranslatedString('Callback'), 'class' => '\Symfony\Component\Validator\Constraints\Callback', 'type' => FALSE, )); $this->getDiscovery()->setDefinition('Blank', array( - 'label' => new TranslationWrapper('Blank'), + 'label' => new TranslatedString('Blank'), 'class' => '\Symfony\Component\Validator\Constraints\Blank', 'type' => FALSE, )); $this->getDiscovery()->setDefinition('NotBlank', array( - 'label' => new TranslationWrapper('Not blank'), + 'label' => new TranslatedString('Not blank'), 'class' => '\Symfony\Component\Validator\Constraints\NotBlank', 'type' => FALSE, )); $this->getDiscovery()->setDefinition('Email', array( - 'label' => new TranslationWrapper('Email'), + 'label' => new TranslatedString('Email'), 'class' => '\Drupal\Core\Validation\Plugin\Validation\Constraint\EmailConstraint', 'type' => array('string'), )); diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php index ba1a1f9..2f9c515 100644 --- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php +++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php @@ -77,7 +77,7 @@ protected function processParameters(array $parameters) { foreach ($parameters as $key => $value) { // We allow the values in the parameters to be safe string objects. This // can be useful when we want to use parameter values that are - // TranslationWrappers. + // TranslatedStrings. if ($value instanceof SafeStringInterface) { $value = (string) $value; } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 8449c9d..18a80bf 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -13,7 +13,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Implements hook_help(). @@ -252,8 +252,8 @@ function content_translation_views_data_alter(array &$data) { */ function content_translation_menu_links_discovered_alter(array &$links) { // Clarify where translation settings are located. - $links['language.content_settings_page']['title'] = new TranslationWrapper('Content language and translation'); - $links['language.content_settings_page']['description'] = new TranslationWrapper('Configure language and translation support for content.'); + $links['language.content_settings_page']['title'] = new TranslatedString('Content language and translation'); + $links['language.content_settings_page']['description'] = new TranslatedString('Configure language and translation support for content.'); } /** diff --git a/core/modules/dblog/dblog.module b/core/modules/dblog/dblog.module index 91c6038..d5cca32 100644 --- a/core/modules/dblog/dblog.module +++ b/core/modules/dblog/dblog.module @@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Implements hook_help(). @@ -42,9 +42,9 @@ function dblog_help($route_name, RouteMatchInterface $route_match) { function dblog_menu_links_discovered_alter(&$links) { if (\Drupal::moduleHandler()->moduleExists('search')) { $links['dblog.search'] = array( - 'title' => new TranslationWrapper('Top search phrases'), + 'title' => new TranslatedString('Top search phrases'), 'route_name' => 'dblog.search', - 'description' => new TranslationWrapper('View most popular search phrases.'), + 'description' => new TranslatedString('View most popular search phrases.'), 'parent' => 'system.admin_reports', ); } diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 18d0fb8..cad4c21 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -11,7 +11,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\Entity\EntityInterface; use Drupal\filter\FilterFormatInterface; use Drupal\filter\Plugin\FilterInterface; @@ -47,8 +47,8 @@ function editor_help($route_name, RouteMatchInterface $route_match) { * of text editors. */ function editor_menu_links_discovered_alter(array &$links) { - $links['filter.admin_overview']['title'] = new TranslationWrapper('Text formats and editors'); - $links['filter.admin_overview']['description'] = new TranslationWrapper('Configure how user-contributed content is filtered and formatted, as well as the text editor user interface (WYSIWYGs or toolbars).'); + $links['filter.admin_overview']['title'] = new TranslatedString('Text formats and editors'); + $links['filter.admin_overview']['description'] = new TranslatedString('Configure how user-contributed content is filtered and formatted, as well as the text editor user interface (WYSIWYGs or toolbars).'); } /** diff --git a/core/modules/field/src/Tests/EntityReference/EntityReferenceItemTest.php b/core/modules/field/src/Tests/EntityReference/EntityReferenceItemTest.php index 497b2bd..c51f099 100644 --- a/core/modules/field/src/Tests/EntityReference/EntityReferenceItemTest.php +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceItemTest.php @@ -10,7 +10,7 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\Language\LanguageInterface; use Drupal\entity_reference\Tests\EntityReferenceTestTrait; use Drupal\entity_test\Entity\EntityTest; @@ -114,7 +114,7 @@ public function testContentEntityReferenceItem() { $this->assertEqual($entity->field_test_taxonomy_term->entity->uuid(), $this->term->uuid()); // Verify that the label for the target ID property definition is correct. $label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel(); - $this->assertTrue($label instanceof TranslationWrapper); + $this->assertTrue($label instanceof TranslatedString); $this->assertEqual($label->render(), 'Taxonomy term ID'); // Change the name of the term via the reference. @@ -185,7 +185,7 @@ public function testContentEntityReferenceItemWithStringId() { $this->assertEqual($this->entityStringId->id(), $storage->load($entity->id())->field_test_entity_test_string_id->target_id); // Verify that the label for the target ID property definition is correct. $label = $entity->field_test_taxonomy_term->getFieldDefinition()->getFieldStorageDefinition()->getPropertyDefinition('target_id')->getLabel(); - $this->assertTrue($label instanceof TranslationWrapper); + $this->assertTrue($label instanceof TranslatedString); $this->assertEqual($label->render(), 'Taxonomy term ID'); } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 7259d35..d9f6e2d 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -20,7 +20,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\Language; use Drupal\Core\Routing\RouteMatchInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\Language\LanguageInterface; use Drupal\language\ConfigurableLanguageInterface; use Drupal\Component\Utility\Crypt; diff --git a/core/modules/locale/src/LocaleConfigManager.php b/core/modules/locale/src/LocaleConfigManager.php index d96c758..3fa0a9b 100644 --- a/core/modules/locale/src/LocaleConfigManager.php +++ b/core/modules/locale/src/LocaleConfigManager.php @@ -12,7 +12,7 @@ use Drupal\Core\Config\InstallStorage; use Drupal\Core\Config\StorageInterface; use Drupal\Core\Config\TypedConfigManagerInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\TraversableTypedDataInterface; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\language\ConfigurableLanguageManagerInterface; @@ -150,11 +150,11 @@ public function getTranslatableDefaultConfig($name) { * @param \Drupal\Core\TypedData\TypedDataInterface $element * Typed configuration element. * - * @return array|\Drupal\Core\StringTranslation\TranslationWrapper + * @return array|\Drupal\Core\StringTranslation\TranslatedString * A nested array matching the exact structure under $element with only the - * elements that are translatable wrapped into a TranslationWrapper. If the + * elements that are translatable wrapped into a TranslatedString. If the * provided $element is not traversable, the return value is a single - * TranslationWrapper. + * TranslatedString. */ protected function getTranslatableData(TypedDataInterface $element) { $translatable = array(); @@ -173,7 +173,7 @@ protected function getTranslatableData(TypedDataInterface $element) { if (isset($definition['translation context'])) { $options['context'] = $definition['translation context']; } - return new TranslationWrapper($element->getValue(), array(), $options); + return new TranslatedString($element->getValue(), array(), $options); } } return $translatable; @@ -191,10 +191,10 @@ protected function getTranslatableData(TypedDataInterface $element) { * The configuration name. * @param array $active * The active configuration data. - * @param array|\Drupal\Core\StringTranslation\TranslationWrapper[] $translatable + * @param array|\Drupal\Core\StringTranslation\TranslatedString[] $translatable * The translatable array structure. A nested array matching the exact * structure under of the default configuration for $name with only the - * elements that are translatable wrapped into a TranslationWrapper. + * elements that are translatable wrapped into a TranslatedString. * @see self::getTranslatableData(). * @param string $langcode * The language code to process the array with. diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php index 8a23ea1..746e031 100644 --- a/core/modules/locale/src/LocaleConfigSubscriber.php +++ b/core/modules/locale/src/LocaleConfigSubscriber.php @@ -133,7 +133,7 @@ protected function updateLocaleStorage(StorableConfigBase $config, $langcode, ar * The configuration name. * @param array $config * The active configuration data or override data. - * @param array|\Drupal\Core\StringTranslation\TranslationWrapper[] $translatable + * @param array|\Drupal\Core\StringTranslation\TranslatedString[] $translatable * The translatable array structure. * @see \Drupal\locale\LocaleConfigManager::getTranslatableData() * @param string $langcode @@ -169,9 +169,9 @@ protected function processTranslatableData($name, array $config, array $translat * * @param string $name * The configuration name. - * @param array|\Drupal\Core\StringTranslation\TranslationWrapper $translatable - * Either a possibly nested array with TranslationWrapper objects at the - * leaf items or a TranslationWrapper object directly. + * @param array|\Drupal\Core\StringTranslation\TranslatedString $translatable + * Either a possibly nested array with TranslatedString objects at the + * leaf items or a TranslatedString object directly. * @param array|string $reference_config * Either a possibly nested array with strings at the leaf items or a string * directly. Only those $translatable items that are also present in diff --git a/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php b/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php index 5cd5108..68326a6 100644 --- a/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php +++ b/core/modules/menu_link_content/src/Tests/MenuLinkContentDeriverTest.php @@ -9,7 +9,7 @@ use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Menu\MenuTreeParameters; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\simpletest\KernelTestBase; use Symfony\Component\Routing\Route; @@ -71,7 +71,7 @@ public function testRediscover() { $tree_element = reset($menu_tree); $this->assertEqual('route_name_2', $tree_element->link->getRouteName()); $title = $tree_element->link->getTitle(); - $this->assertFalse($title instanceof TranslationWrapper); + $this->assertFalse($title instanceof TranslatedString); $this->assertIdentical('', $title); $this->assertFalse(SafeMarkup::isSafe($title)); diff --git a/core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php b/core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php index 6313ce1..af35ccb 100644 --- a/core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php +++ b/core/modules/system/src/Tests/Plugin/Discovery/DiscoveryTestBase.php @@ -7,7 +7,7 @@ namespace Drupal\system\Tests\Plugin\Discovery; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\simpletest\KernelTestBase; /** @@ -77,7 +77,7 @@ function testDiscoveryInterface() { */ protected function assertDefinitionIdentical(array $definition, array $expected_definition) { $func = function (&$item){ - if ($item instanceof TranslationWrapper) { + if ($item instanceof TranslatedString) { $item = (string) $item; } }; diff --git a/core/modules/system/src/Tests/Update/MenuTreeSerializationTitleTest.php b/core/modules/system/src/Tests/Update/MenuTreeSerializationTitleTest.php index 6c382f5..fd09d0c 100644 --- a/core/modules/system/src/Tests/Update/MenuTreeSerializationTitleTest.php +++ b/core/modules/system/src/Tests/Update/MenuTreeSerializationTitleTest.php @@ -7,7 +7,7 @@ namespace Drupal\system\Tests\Update; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Tests system_update_8001(). @@ -54,11 +54,11 @@ public function testUpdate() { $title = unserialize($link->title); $description = unserialize($link->description); // Verify that all the links from system module have a been updated with - // a TranslationWrapper as title and description due to the rebuild. + // a TranslatedString as title and description due to the rebuild. if (strpos($link->id, 'system.') === 0) { - $this->assertTrue($title instanceof TranslationWrapper, get_class($title)); + $this->assertTrue($title instanceof TranslatedString, get_class($title)); if ($description) { - $this->assertTrue($description instanceof TranslationWrapper, get_class($description)); + $this->assertTrue($description instanceof TranslatedString, get_class($description)); } } } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index c168b24..6d9df5f 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1234,7 +1234,7 @@ function system_update_8001(&$sandbox = NULL) { $schema->changeField('menu_tree', $name, 'system_update_8001_' . $name, $spec); } $spec = array( - 'description' => 'The title for the link. May be a serialized TranslationWrapper.', + 'description' => 'The title for the link. May be a serialized TranslatedString.', 'type' => 'blob', 'size' => 'big', 'not null' => FALSE, diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php index 582ea94..3c1621c 100644 --- a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php +++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php @@ -9,7 +9,7 @@ use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataDefinitionInterface; use Drupal\Core\TypedData\TypedDataInterface; @@ -39,9 +39,9 @@ class FieldTestItem extends FieldItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { // This is called very early by the user entity roles field. Prevent - // early t() calls by using the TranslationWrapper. + // early t() calls by using the TranslatedString. $properties['value'] = DataDefinition::create('string') - ->setLabel(new TranslationWrapper('Test value')) + ->setLabel(new TranslatedString('Test value')) ->setRequired(TRUE); return $properties; diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php index f079785..ae1f78a 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/MockBlockManager.php @@ -133,9 +133,9 @@ public function __construct() { */ protected function createContextDefinition($data_type, $label, $required = TRUE) { // We cast the label to string for testing purposes only, as it may be - // a TranslationWrapper and we will do assertEqual() checks on arrays that + // a TranslatedString and we will do assertEqual() checks on arrays that // include ContextDefinition objects, and var_export() has problems - // printing TranslationWrapper objects. + // printing TranslatedString objects. return new ContextDefinition($data_type, (string) $label, $required); } } diff --git a/core/modules/views/src/Entity/View.php b/core/modules/views/src/Entity/View.php index de736ec..449d01d 100644 --- a/core/modules/views/src/Entity/View.php +++ b/core/modules/views/src/Entity/View.php @@ -191,7 +191,7 @@ public function addDisplay($plugin_id = 'page', $title = NULL, $id = NULL) { 'display_plugin' => $plugin_id, 'id' => $id, // Cast the display title to a string since it is an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper + // @see \Drupal\Core\StringTranslation\TranslatedString 'display_title' => (string) $title, 'position' => $id === 'default' ? 0 : count($this->display), 'display_options' => array(), diff --git a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php index e862fb3..07316d0 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php @@ -9,7 +9,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -98,10 +98,10 @@ public function getDerivativeDefinitions($base_plugin_definition) { } else { // Allow translators to control the punctuation. Plugin - // definitions get cached, so use TranslationWrapper() instead of + // definitions get cached, so use TranslatedString() instead of // t() to avoid double escaping when $admin_label is rendered // during requests that use the cached definition. - $admin_label = new TranslationWrapper('@view: @display', ['@view' => $view->label(), '@display' => $display->display['display_title']]); + $admin_label = new TranslatedString('@view: @display', ['@view' => $view->label(), '@display' => $display->display['display_title']]); } } diff --git a/core/modules/views/src/Plugin/views/PluginBase.php b/core/modules/views/src/Plugin/views/PluginBase.php index cbe7526..c2bea1f 100644 --- a/core/modules/views/src/Plugin/views/PluginBase.php +++ b/core/modules/views/src/Plugin/views/PluginBase.php @@ -14,7 +14,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\PluginBase as ComponentPluginBase; use Drupal\Core\Render\Element; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -566,7 +566,7 @@ protected function listLanguages($flags = LanguageInterface::STATE_ALL, array $c // The language name may have already been translated, no need to // translate it again. // @see Drupal\Core\Language::filterLanguages(). - if (!$name instanceof TranslationWrapper) { + if (!$name instanceof TranslatedString) { $name = $this->t($name); } $list[PluginBase::VIEWS_QUERY_LANGUAGE_SITE_DEFAULT] = $name; diff --git a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php index e398823..3ca1919 100644 --- a/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php +++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php @@ -1179,7 +1179,7 @@ protected function prepareFilterSelectOptions(&$options) { } else { // Cast the label to a string since it can be an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper + // @see \Drupal\Core\StringTranslation\TranslatedString $options[$value] = strip_tags(Html::decodeEntities((string) $label)); } } diff --git a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php index 34a2a9a..a9a2e78 100644 --- a/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php +++ b/core/modules/views/src/Plugin/views/relationship/RelationshipPluginBase.php @@ -97,7 +97,7 @@ protected function defineOptions() { // aren't get another default value. if (!empty($this->definition['label'])) { // Cast the label to a string since it is an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper + // @see \Drupal\Core\StringTranslation\TranslatedString $label = (string) $this->definition['label']; } else { diff --git a/core/modules/views_ui/admin.inc b/core/modules/views_ui/admin.inc index cbb0782..a98532c 100644 --- a/core/modules/views_ui/admin.inc +++ b/core/modules/views_ui/admin.inc @@ -93,7 +93,7 @@ function views_ui_add_ajax_trigger(&$wrapping_element, $trigger_key, $refresh_pa // For easiest integration with the form API and the testing framework, we // always give the button a unique #value, rather than playing around with // #name. We also cast the #title to string as we will use it as an array - // key and it may be a TranslationWrapper. + // key and it may be a TranslatedString. $button_title = !empty($triggering_element['#title']) ? (string) $triggering_element['#title'] : $trigger_key; if (empty($seen_buttons[$button_title])) { $wrapping_element[$button_key]['#value'] = t('Update "@title" choice', array( diff --git a/core/modules/views_ui/src/ViewListBuilder.php b/core/modules/views_ui/src/ViewListBuilder.php index 0d8125b..1243568 100644 --- a/core/modules/views_ui/src/ViewListBuilder.php +++ b/core/modules/views_ui/src/ViewListBuilder.php @@ -246,7 +246,7 @@ protected function getDisplaysList(EntityInterface $view) { $definition = $this->displayManager->getDefinition($display['display_plugin']); if (!empty($definition['admin'])) { // Cast the admin label to a string since it is an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper + // @see \Drupal\Core\StringTranslation\TranslatedString $displays[] = (string) $definition['admin']; } } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php index 15991a5..76300f9 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkDefaultTest.php @@ -8,7 +8,7 @@ namespace Drupal\Tests\Core\Menu; use Drupal\Core\Menu\ContextualLinkDefault; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; @@ -71,7 +71,7 @@ protected function setupContextualLinkDefault() { */ public function testGetTitle() { $title = 'Example'; - $this->pluginDefinition['title'] = (new TranslationWrapper($title, [], [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString($title, [], [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -86,7 +86,7 @@ public function testGetTitle() { */ public function testGetTitleWithContext() { $title = 'Example'; - $this->pluginDefinition['title'] = (new TranslationWrapper($title, array(), array('context' => 'context'), $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString($title, array(), array('context' => 'context'), $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -101,7 +101,7 @@ public function testGetTitleWithContext() { */ public function testGetTitleWithTitleArguments() { $title = 'Example @test'; - $this->pluginDefinition['title'] = (new TranslationWrapper($title, array('@test' => 'value'), [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString($title, array('@test' => 'value'), [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php index 3de7774..c7c8296 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalActionDefaultTest.php @@ -8,7 +8,7 @@ namespace Drupal\Tests\Core\Menu; use Drupal\Core\Menu\LocalActionDefault; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; @@ -83,7 +83,7 @@ protected function setupLocalActionDefault() { * @see \Drupal\Core\Menu\LocalTaskDefault::getTitle() */ public function testGetTitle() { - $this->pluginDefinition['title'] = (new TranslationWrapper('Example', [], [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString('Example', [], [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -99,7 +99,7 @@ public function testGetTitle() { * @see \Drupal\Core\Menu\LocalTaskDefault::getTitle() */ public function testGetTitleWithContext() { - $this->pluginDefinition['title'] = (new TranslationWrapper('Example', array(), array('context' => 'context'), $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString('Example', array(), array('context' => 'context'), $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -113,7 +113,7 @@ public function testGetTitleWithContext() { * Tests the getTitle method with title arguments. */ public function testGetTitleWithTitleArguments() { - $this->pluginDefinition['title'] = (new TranslationWrapper('Example @test', array('@test' => 'value'), [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString('Example @test', array('@test' => 'value'), [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php index 7c9dc58..651326f 100644 --- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskDefaultTest.php @@ -10,7 +10,7 @@ use Drupal\Core\Menu\LocalTaskDefault; use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Routing\RouteProviderInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; use Symfony\Component\Routing\Route; @@ -233,7 +233,7 @@ public function testActive() { * @covers ::getTitle */ public function testGetTitle() { - $this->pluginDefinition['title'] = (new TranslationWrapper('Example', [], [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString('Example', [], [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -248,7 +248,7 @@ public function testGetTitle() { */ public function testGetTitleWithContext() { $title = 'Example'; - $this->pluginDefinition['title'] = (new TranslationWrapper($title, array(), array('context' => 'context'), $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString($title, array(), array('context' => 'context'), $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) @@ -262,7 +262,7 @@ public function testGetTitleWithContext() { * @covers ::getTitle */ public function testGetTitleWithTitleArguments() { - $this->pluginDefinition['title'] = (new TranslationWrapper('Example @test', array('@test' => 'value'), [], $this->stringTranslation)); + $this->pluginDefinition['title'] = (new TranslatedString('Example @test', array('@test' => 'value'), [], $this->stringTranslation)); $this->stringTranslation->expects($this->once()) ->method('translateString') ->with($this->pluginDefinition['title']) diff --git a/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php b/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php index 22aacc4..900544f 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDiscoveryTest.php @@ -7,7 +7,7 @@ namespace Drupal\Tests\Core\Plugin\Discovery; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; use Drupal\Core\Plugin\Discovery\YamlDiscovery; use org\bovigo\vfs\vfsStream; @@ -104,9 +104,9 @@ public function testGetDefinitionsWithTranslatableDefinitions() { $plugin_1 = $definitions['test_plugin']; $plugin_2 = $definitions['test_plugin2']; - $this->assertInstanceOf(TranslationWrapper::class, $plugin_1['title']); + $this->assertInstanceOf(TranslatedString::class, $plugin_1['title']); $this->assertEquals([], $plugin_1['title']->getOptions()); - $this->assertInstanceOf(TranslationWrapper::class, $plugin_2['title']); + $this->assertInstanceOf(TranslatedString::class, $plugin_2['title']); $this->assertEquals(['context' => 'test-context'], $plugin_2['title']->getOptions()); } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatedStringTest.php similarity index 80% rename from core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php rename to core/tests/Drupal/Tests/Core/StringTranslation/TranslatedStringTest.php index af5dce8..d6dc053 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationWrapperTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslatedStringTest.php @@ -2,22 +2,22 @@ /** * @file - * Contains \Drupal\Tests\Core\StringTranslation\TranslationWrapperTest. + * Contains \Drupal\Tests\Core\StringTranslation\TranslatedStringTest. */ namespace Drupal\Tests\Core\StringTranslation; use Drupal\Core\StringTranslation\TranslationInterface; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; /** - * Tests the TranslationWrapper class. + * Tests the TranslatedString class. * - * @coversDefaultClass \Drupal\Core\StringTranslation\TranslationWrapper + * @coversDefaultClass \Drupal\Core\StringTranslation\TranslatedString * @group StringTranslation */ -class TranslationWrapperTest extends UnitTestCase { +class TranslatedStringTest extends UnitTestCase { /** * The error message of the last error in the error handler. @@ -59,7 +59,7 @@ public function testToString() { $translation = $this->getMock(TranslationInterface::class); $string = 'May I have an exception please?'; - $text = $this->getMockBuilder(TranslationWrapper::class) + $text = $this->getMockBuilder(TranslatedString::class) ->setConstructorArgs([$string, [], [], $translation]) ->setMethods(['_die']) ->getMock(); @@ -82,7 +82,7 @@ public function testToString() { restore_error_handler(); $this->assertEquals(E_USER_ERROR, $this->lastErrorNumber); - $this->assertRegExp('/Exception thrown while calling __toString on a .*Mock_TranslationWrapper_.* object in .*TranslationWrapperTest.php on line [0-9]+: Yes you may./', $this->lastErrorMessage); + $this->assertRegExp('/Exception thrown while calling __toString on a .*Mock_TranslatedString_.* object in .*TranslatedStringTest.php on line [0-9]+: Yes you may./', $this->lastErrorMessage); } } diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php index 4efd701..a58e44a 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/TranslationManagerTest.php @@ -70,7 +70,7 @@ public function testFormatPlural($count, $singular, $plural, array $args = array * @param string $expected_string * The expected translated string value. * @param bool $returns_translation_wrapper - * Whether we are expecting a TranslationWrapper object to be returned. + * Whether we are expecting a TranslatedString object to be returned. * * @dataProvider providerTestTranslatePlaceholder */ diff --git a/core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php b/core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php index 0707fa3..060bd8d 100644 --- a/core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Validation/Plugin/Validation/Constraint/PrimitiveTypeConstraintValidatorTest.php @@ -16,7 +16,7 @@ use Drupal\Core\TypedData\PrimitiveInterface; use Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraint; use Drupal\Core\Validation\Plugin\Validation\Constraint\PrimitiveTypeConstraintValidator; -use Drupal\Core\StringTranslation\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; use Drupal\Tests\UnitTestCase; /** @@ -64,7 +64,7 @@ public function provideTestValidate() { $data[] = [new IntegerData(DataDefinition::create('integer')), 1.5, FALSE]; $data[] = [new IntegerData(DataDefinition::create('integer')), 'test', FALSE]; $data[] = [new StringData(DataDefinition::create('string')), 'test', TRUE]; - $data[] = [new StringData(DataDefinition::create('string')), new TranslationWrapper('test'), TRUE]; + $data[] = [new StringData(DataDefinition::create('string')), new TranslatedString('test'), TRUE]; // It is odd that 1 is a valid string. // $data[] = [$this->getMock('Drupal\Core\TypedData\Type\StringInterface'), 1, FALSE]; $data[] = [new StringData(DataDefinition::create('string')), [], FALSE]; diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index e327a84..31656a4 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\TranslationWrapper; +use Drupal\Core\StringTranslation\TranslatedString; /** * Provides a base class and helpers for Drupal unit tests. @@ -219,14 +219,14 @@ public function getStringTranslationStub() { $translation->expects($this->any()) ->method('translate') ->willReturnCallback(function ($string, array $args = array(), array $options = array()) use ($translation) { - $wrapper = new TranslationWrapper($string, $args, $options, $translation); + $wrapper = new TranslatedString($string, $args, $options, $translation); // Pretend everything is not safe. // @todo https://www.drupal.org/node/2570037 return the wrapper instead. return (string) $wrapper; }); $translation->expects($this->any()) ->method('translateString') - ->willReturnCallback(function (TranslationWrapper $wrapper) { + ->willReturnCallback(function (TranslatedString $wrapper) { return $wrapper->getUntranslatedString(); }); $translation->expects($this->any())