From a4c98c94ee1f08bf967df3115fe4edc8103826f3 Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Wed, 28 Sep 2022 09:49:56 +0100 Subject: [PATCH] Issue #3181778 by quietone, longwave, aldairsoares, beatrizrodrigues, Aline Teixeira Ramos, KapilV, raman.b, anushrikumari, CChiste, mallezie, Ratan Priya, rakesh.regar, Kevin.Notari, vicheldt, mauryarahul11, yogeshmpawar, bbrala, alexpott, bruno.bicudo: [w/c September 17th] Replace t() with $this->t() in all plugins (cherry picked from commit 6bbfb0550095e2eaa400ce6d5c1b9d3b9b6cc4e2) --- .../Core/Action/Plugin/Action/EmailAction.php | 14 ++-- .../Core/Action/Plugin/Action/GotoAction.php | 4 +- .../Action/Plugin/Action/MessageAction.php | 4 +- .../Derivative/DefaultSelectionDeriver.php | 4 +- .../EntityReferenceSelection/Broken.php | 2 +- .../Field/FieldFormatter/DecimalFormatter.php | 8 +- .../EntityReferenceEntityFormatter.php | 4 +- .../EntityReferenceLabelFormatter.php | 4 +- .../FieldFormatter/NumericFormatterBase.php | 18 ++--- .../Plugin/Field/FieldType/DecimalItem.php | 11 +-- .../Plugin/Field/FieldType/EmailItem.php | 8 +- .../Field/FieldType/EntityReferenceItem.php | 8 +- .../Plugin/Field/FieldType/IntegerItem.php | 5 +- .../Field/FieldType/NumericItemBase.php | 23 +++--- .../Plugin/Field/FieldType/StringItem.php | 6 +- .../Plugin/Field/FieldType/StringItemBase.php | 2 - .../FieldWidget/BooleanCheckboxWidget.php | 4 +- .../Field/FieldWidget/EmailDefaultWidget.php | 10 +-- .../EntityReferenceAutocompleteWidget.php | 22 +++--- .../Plugin/Field/FieldWidget/NumberWidget.php | 8 +- .../FieldWidget/OptionsButtonsWidget.php | 2 +- .../Field/FieldWidget/OptionsSelectWidget.php | 6 +- .../Field/FieldWidget/OptionsWidgetBase.php | 3 +- .../FieldWidget/StringTextareaWidget.php | 10 +-- .../FieldWidget/StringTextfieldWidget.php | 10 +-- .../ckeditor5/src/Plugin/Editor/CKEditor5.php | 2 +- .../Plugin/Field/FieldType/CommentItem.php | 45 +++++------ .../Field/FieldWidget/CommentWidget.php | 16 ++-- .../ContentTranslationContextualLinks.php | 5 +- .../DateTimeDefaultFormatter.php | 6 +- .../Field/FieldType/DateTimeFieldItemList.php | 14 ++-- .../Plugin/Field/FieldType/DateTimeItem.php | 15 ++-- .../FieldWidget/DateTimeDatelistWidget.php | 30 ++++---- .../modules/src/Plugin/Editor/TRexEditor.php | 2 +- .../src/Plugin/Editor/UnicornEditor.php | 2 +- .../TestFieldDefaultFormatter.php | 4 +- .../TestFieldEmptySettingFormatter.php | 4 +- .../TestFieldMultipleFormatter.php | 4 +- .../TestFieldPrepareViewFormatter.php | 4 +- .../src/Plugin/Field/FieldType/TestItem.php | 13 ++-- .../TestItemWithPreconfiguredOptions.php | 5 +- .../Field/FieldWidget/TestFieldWidget.php | 6 +- .../FieldWidget/TestFieldWidgetMultiple.php | 6 +- .../Field/FieldFormatter/TableFormatter.php | 2 +- .../src/Plugin/Field/FieldType/FileItem.php | 40 +++++----- .../Plugin/Field/FieldWidget/FileWidget.php | 25 +++--- .../Field/FieldFormatter/ImageFormatter.php | 20 ++--- .../src/Plugin/Field/FieldType/ImageItem.php | 77 ++++++++++--------- .../Plugin/Field/FieldWidget/ImageWidget.php | 19 ++--- .../Plugin/ImageEffect/ConvertImageEffect.php | 2 +- .../Plugin/ImageEffect/CropImageEffect.php | 22 +++--- .../Plugin/ImageEffect/ResizeImageEffect.php | 8 +- .../Plugin/ImageEffect/RotateImageEffect.php | 12 +-- .../Plugin/ImageEffect/ScaleImageEffect.php | 4 +- .../FieldFormatter/DummyAjaxFormatter.php | 2 +- .../ImageEffect/AjaxTestImageEffect.php | 2 +- .../src/Plugin/Condition/Language.php | 4 +- .../src/Plugin/Derivative/LanguageBlock.php | 7 +- .../Field/FieldFormatter/LinkFormatter.php | 26 +++---- .../src/Plugin/Field/FieldType/LinkItem.php | 23 +++--- .../Plugin/Field/FieldWidget/LinkWidget.php | 11 +-- .../media/src/Plugin/media/Source/OEmbed.php | 4 +- .../src/Plugin/media/Source/OEmbedDeriver.php | 7 +- .../Field/FieldWidget/MediaLibraryWidget.php | 11 +-- .../src/Plugin/migrate/source/MenuLink.php | 50 ++++++------ .../migrate/src/Plugin/migrate/id_map/Sql.php | 2 +- .../src/Plugin/migrate/source/EmptySource.php | 2 +- .../Plugin/migrate/source/SqlCountCache.php | 2 +- .../src/Plugin/Action/AssignOwnerNode.php | 8 +- .../Plugin/Action/UnpublishByKeywordNode.php | 4 +- .../node/src/Plugin/Search/NodeSearch.php | 24 +++--- .../node/src/Plugin/migrate/D6NodeDeriver.php | 4 +- .../node/src/Plugin/migrate/D7NodeDeriver.php | 4 +- .../Plugin/migrate/source/d6/NodeRevision.php | 2 +- .../Plugin/migrate/source/d7/NodeRevision.php | 2 +- .../Plugin/Field/FieldType/ListFloatItem.php | 15 ++-- .../Field/FieldType/ListIntegerItem.php | 15 ++-- .../Plugin/Field/FieldType/ListItemBase.php | 11 +-- .../Plugin/Field/FieldType/ListStringItem.php | 13 ++-- .../Plugin/Field/FieldWidget/PathWidget.php | 2 +- .../ResponsiveImageFormatter.php | 18 ++--- .../Plugin/Search/SearchExtraTypeSearch.php | 8 +- .../src/Plugin/ImageToolkit/GDToolkit.php | 10 +-- .../Plugin/Field/FieldType/FieldTestItem.php | 2 - .../src/Plugin/MockBlockManager.php | 25 +++--- .../mock_block/MockLayoutBlockDeriver.php | 5 +- .../mock_block/MockMenuBlockDeriver.php | 9 ++- .../Plugin/migrate/D7TaxonomyTermDeriver.php | 4 +- .../Plugin/views/filter/TaxonomyIndexTid.php | 2 +- .../FieldFormatter/TelephoneLinkFormatter.php | 6 +- .../Plugin/Field/FieldType/TelephoneItem.php | 5 +- .../FieldWidget/TelephoneDefaultWidget.php | 8 +- .../FieldFormatter/TextTrimmedFormatter.php | 8 +- .../src/Plugin/Field/FieldType/TextItem.php | 6 +- .../Field/FieldType/TextWithSummaryItem.php | 15 ++-- .../FieldWidget/TextareaWithSummaryWidget.php | 10 +-- .../src/Plugin/Action/ChangeUserRoleBase.php | 2 +- .../src/Plugin/Derivative/ViewsBlock.php | 2 +- .../src/Plugin/Derivative/ViewsEntityRow.php | 5 +- .../Derivative/ViewsExposedFilterBlock.php | 5 +- .../ViewsSelection.php | 3 +- .../src/Plugin/views/BrokenHandlerTrait.php | 6 +- .../src/Plugin/views/area/DisplayLink.php | 8 +- .../views/area/TokenizeAreaPluginBase.php | 4 +- .../views/src/Plugin/views/area/View.php | 2 +- .../views/argument/ArgumentPluginBase.php | 4 +- .../views/display/DisplayPluginBase.php | 2 +- .../views/src/Plugin/views/field/Boolean.php | 10 +-- .../Plugin/views/field/FieldPluginBase.php | 7 +- .../src/Plugin/views/filter/InOperator.php | 2 +- .../views/field/FieldFormButtonTest.php | 2 +- .../Plugin/RelationshipJoinTestBase.php | 5 +- core/phpcs.xml.dist | 3 + .../Discovery/AnnotatedClassDiscoveryTest.php | 3 +- ...omDirectoryAnnotatedClassDiscoveryTest.php | 3 +- 115 files changed, 579 insertions(+), 511 deletions(-) diff --git a/core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php b/core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php index b345418d370..2a675fb9903 100644 --- a/core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php +++ b/core/lib/Drupal/Core/Action/Plugin/Action/EmailAction.php @@ -163,25 +163,25 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['recipient'] = [ '#type' => 'textfield', - '#title' => t('Recipient email address'), + '#title' => $this->t('Recipient email address'), '#default_value' => $this->configuration['recipient'], '#maxlength' => '254', - '#description' => t('You may also use tokens: [node:author:mail], [comment:author:mail], etc. Separate recipients with a comma.'), + '#description' => $this->t('You may also use tokens: [node:author:mail], [comment:author:mail], etc. Separate recipients with a comma.'), ]; $form['subject'] = [ '#type' => 'textfield', - '#title' => t('Subject'), + '#title' => $this->t('Subject'), '#default_value' => $this->configuration['subject'], '#maxlength' => '254', - '#description' => t('The subject of the message.'), + '#description' => $this->t('The subject of the message.'), ]; $form['message'] = [ '#type' => 'textarea', - '#title' => t('Message'), + '#title' => $this->t('Message'), '#default_value' => $this->configuration['message'], '#cols' => '80', '#rows' => '20', - '#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:account-name], [user:display-name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), + '#description' => $this->t('The message that should be sent. You may include placeholders like [node:title], [user:account-name], [user:display-name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), ]; return $form; } @@ -192,7 +192,7 @@ class EmailAction extends ConfigurableActionBase implements ContainerFactoryPlug public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { if (!$this->emailValidator->isValid($form_state->getValue('recipient')) && strpos($form_state->getValue('recipient'), ':mail') === FALSE) { // We want the literal %author placeholder to be emphasized in the error message. - $form_state->setErrorByName('recipient', t('Enter a valid email address or use a token email address such as %author.', ['%author' => '[node:author:mail]'])); + $form_state->setErrorByName('recipient', $this->t('Enter a valid email address or use a token email address such as %author.', ['%author' => '[node:author:mail]'])); } } diff --git a/core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php b/core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php index 9fb6b0b61e8..befc21f6a52 100644 --- a/core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php +++ b/core/lib/Drupal/Core/Action/Plugin/Action/GotoAction.php @@ -114,8 +114,8 @@ class GotoAction extends ConfigurableActionBase implements ContainerFactoryPlugi public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['url'] = [ '#type' => 'textfield', - '#title' => t('URL'), - '#description' => t('The URL to which the user should be redirected. This can be an internal URL like /node/1234 or an external URL like @url.', ['@url' => 'http://example.com']), + '#title' => $this->t('URL'), + '#description' => $this->t('The URL to which the user should be redirected. This can be an internal URL like /node/1234 or an external URL like @url.', ['@url' => 'http://example.com']), '#default_value' => $this->configuration['url'], '#required' => TRUE, ]; diff --git a/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php b/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php index 7c892eeed23..19575278cc1 100644 --- a/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php +++ b/core/lib/Drupal/Core/Action/Plugin/Action/MessageAction.php @@ -106,11 +106,11 @@ class MessageAction extends ConfigurableActionBase implements ContainerFactoryPl public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['message'] = [ '#type' => 'textarea', - '#title' => t('Message'), + '#title' => $this->t('Message'), '#default_value' => $this->configuration['message'], '#required' => TRUE, '#rows' => '8', - '#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:account-name], [user:display-name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), + '#description' => $this->t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:account-name], [user:display-name] and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'), ]; return $form; } diff --git a/core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php b/core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php index d46490a8f6b..086063a3df1 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php +++ b/core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php @@ -5,6 +5,7 @@ namespace Drupal\Core\Entity\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -17,6 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; * @see plugin_api */ class DefaultSelectionDeriver extends DeriverBase implements ContainerDeriverInterface { + use StringTranslationTrait; /** * The entity type manager. @@ -51,7 +53,7 @@ class DefaultSelectionDeriver extends DeriverBase implements ContainerDeriverInt foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) { $this->derivatives[$entity_type_id] = $base_plugin_definition; $this->derivatives[$entity_type_id]['entity_types'] = [$entity_type_id]; - $this->derivatives[$entity_type_id]['label'] = t('@entity_type selection', ['@entity_type' => $entity_type->getLabel()]); + $this->derivatives[$entity_type_id]['label'] = $this->t('@entity_type selection', ['@entity_type' => $entity_type->getLabel()]); $this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label']; // If the entity type doesn't provide a 'label' key in its plugin diff --git a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php index e8251e631f7..aa53c397d30 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php +++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/Broken.php @@ -21,7 +21,7 @@ class Broken extends SelectionPluginBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); $form['selection_handler'] = [ - '#markup' => t('The selected selection handler is broken.'), + '#markup' => $this->t('The selected selection handler is broken.'), ]; return $form; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php index 58e8fffc771..312f846d3d7 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/DecimalFormatter.php @@ -42,18 +42,18 @@ class DecimalFormatter extends NumericFormatterBase { $elements['decimal_separator'] = [ '#type' => 'select', - '#title' => t('Decimal marker'), - '#options' => ['.' => t('Decimal point'), ',' => t('Comma')], + '#title' => $this->t('Decimal marker'), + '#options' => ['.' => $this->t('Decimal point'), ',' => $this->t('Comma')], '#default_value' => $this->getSetting('decimal_separator'), '#weight' => 5, ]; $elements['scale'] = [ '#type' => 'number', - '#title' => t('Scale', [], ['context' => 'decimal places']), + '#title' => $this->t('Scale', [], ['context' => 'decimal places']), '#min' => 0, '#max' => 10, '#default_value' => $this->getSetting('scale'), - '#description' => t('The number of digits to the right of the decimal.'), + '#description' => $this->t('The number of digits to the right of the decimal.'), '#weight' => 6, ]; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php index 1a982bdc214..5dbff76dd88 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceEntityFormatter.php @@ -130,7 +130,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { $elements['view_mode'] = [ '#type' => 'select', '#options' => $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type')), - '#title' => t('View mode'), + '#title' => $this->t('View mode'), '#default_value' => $this->getSetting('view_mode'), '#required' => TRUE, ]; @@ -146,7 +146,7 @@ class EntityReferenceEntityFormatter extends EntityReferenceFormatterBase { $view_modes = $this->entityDisplayRepository->getViewModeOptions($this->getFieldSetting('target_type')); $view_mode = $this->getSetting('view_mode'); - $summary[] = t('Rendered as @mode', ['@mode' => $view_modes[$view_mode] ?? $view_mode]); + $summary[] = $this->t('Rendered as @mode', ['@mode' => $view_modes[$view_mode] ?? $view_mode]); return $summary; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php index ed9a6596d83..5316105a82c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceLabelFormatter.php @@ -35,7 +35,7 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $elements['link'] = [ - '#title' => t('Link label to the referenced entity'), + '#title' => $this->t('Link label to the referenced entity'), '#type' => 'checkbox', '#default_value' => $this->getSetting('link'), ]; @@ -48,7 +48,7 @@ class EntityReferenceLabelFormatter extends EntityReferenceFormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = $this->getSetting('link') ? t('Link to the referenced entity') : t('No link'); + $summary[] = $this->getSetting('link') ? $this->t('Link to the referenced entity') : $this->t('No link'); return $summary; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php index bc3efc75926..2ff9dc02105 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/NumericFormatterBase.php @@ -16,16 +16,16 @@ abstract class NumericFormatterBase extends FormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $options = [ - '' => t('- None -'), - '.' => t('Decimal point'), - ',' => t('Comma'), - ' ' => t('Space'), - chr(8201) => t('Thin space'), - "'" => t('Apostrophe'), + '' => $this->t('- None -'), + '.' => $this->t('Decimal point'), + ',' => $this->t('Comma'), + ' ' => $this->t('Space'), + chr(8201) => $this->t('Thin space'), + "'" => $this->t('Apostrophe'), ]; $elements['thousand_separator'] = [ '#type' => 'select', - '#title' => t('Thousand marker'), + '#title' => $this->t('Thousand marker'), '#options' => $options, '#default_value' => $this->getSetting('thousand_separator'), '#weight' => 0, @@ -33,7 +33,7 @@ abstract class NumericFormatterBase extends FormatterBase { $elements['prefix_suffix'] = [ '#type' => 'checkbox', - '#title' => t('Display prefix and suffix'), + '#title' => $this->t('Display prefix and suffix'), '#default_value' => $this->getSetting('prefix_suffix'), '#weight' => 10, ]; @@ -49,7 +49,7 @@ abstract class NumericFormatterBase extends FormatterBase { $summary[] = $this->numberFormat(1234.1234567890); if ($this->getSetting('prefix_suffix')) { - $summary[] = t('Display with prefix and suffix.'); + $summary[] = $this->t('Display with prefix and suffix.'); } return $summary; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php index 0c9e8195bc1..15b7b65545f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DecimalItem.php @@ -6,6 +6,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Defines the 'decimal' field type. @@ -36,7 +37,7 @@ class DecimalItem extends NumericItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Decimal value')) + ->setLabel(new TranslatableMarkup('Decimal value')) ->setRequired(TRUE); return $properties; @@ -66,21 +67,21 @@ class DecimalItem extends NumericItemBase { $element['precision'] = [ '#type' => 'number', - '#title' => t('Precision'), + '#title' => $this->t('Precision'), '#min' => 10, '#max' => 32, '#default_value' => $settings['precision'], - '#description' => t('The total number of digits to store in the database, including those to the right of the decimal.'), + '#description' => $this->t('The total number of digits to store in the database, including those to the right of the decimal.'), '#disabled' => $has_data, ]; $element['scale'] = [ '#type' => 'number', - '#title' => t('Scale', [], ['context' => 'decimal places']), + '#title' => $this->t('Scale', [], ['context' => 'decimal places']), '#min' => 0, '#max' => 10, '#default_value' => $settings['scale'], - '#description' => t('The number of digits to the right of the decimal.'), + '#description' => $this->t('The number of digits to the right of the decimal.'), '#disabled' => $has_data, ]; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php index a6801fc229f..59e918ae94e 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EmailItem.php @@ -8,6 +8,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Render\Element\Email; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Defines the 'email' field type. @@ -27,7 +28,7 @@ class EmailItem extends FieldItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('email') - ->setLabel(t('Email')) + ->setLabel(new TranslatableMarkup('Email')) ->setRequired(TRUE); return $properties; @@ -58,7 +59,10 @@ class EmailItem extends FieldItemBase { 'value' => [ 'Length' => [ 'max' => Email::EMAIL_MAX_LENGTH, - 'maxMessage' => t('%name: the email address can not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => Email::EMAIL_MAX_LENGTH]), + 'maxMessage' => $this->t('%name: the email address can not be longer than @max characters.', [ + '%name' => $this->getFieldDefinition()->getLabel(), + '@max' => Email::EMAIL_MAX_LENGTH, + ]), ], ], ]); 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 0bf634ea5ea..146b9fd68e3 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php @@ -362,7 +362,7 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { $element['target_type'] = [ '#type' => 'select', - '#title' => t('Type of item to reference'), + '#title' => $this->t('Type of item to reference'), '#default_value' => $this->getSetting('target_type'), '#required' => TRUE, '#disabled' => $has_data, @@ -413,7 +413,7 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf ]; $form['handler'] = [ '#type' => 'details', - '#title' => t('Reference type'), + '#title' => $this->t('Reference type'), '#open' => TRUE, '#tree' => TRUE, '#process' => [[static::class, 'formProcessMergeParent']], @@ -421,7 +421,7 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf $form['handler']['handler'] = [ '#type' => 'select', - '#title' => t('Reference method'), + '#title' => $this->t('Reference method'), '#options' => $handlers_options, '#default_value' => $field->getSetting('handler'), '#required' => TRUE, @@ -430,7 +430,7 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf ]; $form['handler']['handler_submit'] = [ '#type' => 'submit', - '#value' => t('Change handler'), + '#value' => $this->t('Change handler'), '#limit_validation_errors' => [], '#attributes' => [ 'class' => ['js-hide'], diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php index 8469126729a..1ce7a4463f3 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/IntegerItem.php @@ -5,6 +5,7 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Defines the 'integer' field type. @@ -49,7 +50,7 @@ class IntegerItem extends NumericItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') - ->setLabel(t('Integer value')) + ->setLabel(new TranslatableMarkup('Integer value')) ->setRequired(TRUE); return $properties; @@ -69,7 +70,7 @@ class IntegerItem extends NumericItemBase { 'value' => [ 'Range' => [ 'min' => 0, - 'minMessage' => t('%name: The integer must be larger or equal to %min.', [ + 'minMessage' => $this->t('%name: The integer must be larger or equal to %min.', [ '%name' => $this->getFieldDefinition()->getLabel(), '%min' => 0, ]), diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php index a0c2af0e21b..d1f3d644dbc 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/NumericItemBase.php @@ -31,29 +31,29 @@ abstract class NumericItemBase extends FieldItemBase { $element['min'] = [ '#type' => 'number', - '#title' => t('Minimum'), + '#title' => $this->t('Minimum'), '#default_value' => $settings['min'], - '#description' => t('The minimum value that should be allowed in this field. Leave blank for no minimum.'), + '#description' => $this->t('The minimum value that should be allowed in this field. Leave blank for no minimum.'), ]; $element['max'] = [ '#type' => 'number', - '#title' => t('Maximum'), + '#title' => $this->t('Maximum'), '#default_value' => $settings['max'], - '#description' => t('The maximum value that should be allowed in this field. Leave blank for no maximum.'), + '#description' => $this->t('The maximum value that should be allowed in this field. Leave blank for no maximum.'), ]; $element['prefix'] = [ '#type' => 'textfield', - '#title' => t('Prefix'), + '#title' => $this->t('Prefix'), '#default_value' => $settings['prefix'], '#size' => 60, - '#description' => t("Define a string that should be prefixed to the value, like '$ ' or '€ '. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."), + '#description' => $this->t("Define a string that should be prefixed to the value, like '$ ' or '€ '. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."), ]; $element['suffix'] = [ '#type' => 'textfield', - '#title' => t('Suffix'), + '#title' => $this->t('Suffix'), '#default_value' => $settings['suffix'], '#size' => 60, - '#description' => t("Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."), + '#description' => $this->t("Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."), ]; return $element; @@ -85,7 +85,7 @@ abstract class NumericItemBase extends FieldItemBase { 'value' => [ 'Range' => [ 'min' => $min, - 'minMessage' => t('%name: the value may be no less than %min.', ['%name' => $label, '%min' => $min]), + 'minMessage' => $this->t('%name: the value may be no less than %min.', ['%name' => $label, '%min' => $min]), ], ], ]); @@ -97,7 +97,10 @@ abstract class NumericItemBase extends FieldItemBase { 'value' => [ 'Range' => [ 'max' => $max, - 'maxMessage' => t('%name: the value may be no greater than %max.', ['%name' => $label, '%max' => $max]), + 'maxMessage' => $this->t('%name: the value may be no greater than %max.', [ + '%name' => $label, + '%max' => $max, + ]), ], ], ]); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php index b51764c2948..172f904b265 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItem.php @@ -58,7 +58,7 @@ class StringItem extends StringItemBase { 'value' => [ 'Length' => [ 'max' => $max_length, - 'maxMessage' => t('%name: may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), + 'maxMessage' => $this->t('%name: may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), ], ], ]); @@ -84,10 +84,10 @@ class StringItem extends StringItemBase { $element['max_length'] = [ '#type' => 'number', - '#title' => t('Maximum length'), + '#title' => $this->t('Maximum length'), '#default_value' => $this->getSetting('max_length'), '#required' => TRUE, - '#description' => t('The maximum length of the field in characters.'), + '#description' => $this->t('The maximum length of the field in characters.'), '#min' => 1, '#disabled' => $has_data, ]; 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 f59c10c985f..fc08eb5014b 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/StringItemBase.php @@ -25,8 +25,6 @@ abstract class StringItemBase extends FieldItemBase { * {@inheritdoc} */ 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 TranslatableMarkup. $properties['value'] = DataDefinition::create('string') ->setLabel(new TranslatableMarkup('Text value')) ->setSetting('case_sensitive', $field_definition->getSetting('case_sensitive')) diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php index 7991a6f64da..a954dac07d2 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/BooleanCheckboxWidget.php @@ -35,7 +35,7 @@ class BooleanCheckboxWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['display_label'] = [ '#type' => 'checkbox', - '#title' => t('Use field label instead of the "On" label as the label.'), + '#title' => $this->t('Use field label instead of the "On" label as the label.'), '#default_value' => $this->getSetting('display_label'), '#weight' => -1, ]; @@ -49,7 +49,7 @@ class BooleanCheckboxWidget extends WidgetBase { $summary = []; $display_label = $this->getSetting('display_label'); - $summary[] = t('Use field label: @display_label', ['@display_label' => ($display_label ? t('Yes') : t('No'))]); + $summary[] = $this->t('Use field label: @display_label', ['@display_label' => ($display_label ? $this->t('Yes') : $this->t('No'))]); return $summary; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php index 76d0bdd24e6..bf7bb404200 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EmailDefaultWidget.php @@ -43,9 +43,9 @@ class EmailDefaultWidget extends WidgetBase { ]; $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -58,12 +58,12 @@ class EmailDefaultWidget extends WidgetBase { $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } else { - $summary[] = t('No placeholder'); + $summary[] = $this->t('No placeholder'); } - $summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]); + $summary[] = $this->t('Textfield size: @size', ['@size' => $this->getSetting('size')]); return $summary; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php index 2ce3912d8bd..22a1b2a085f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php @@ -40,10 +40,10 @@ class EntityReferenceAutocompleteWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['match_operator'] = [ '#type' => 'radios', - '#title' => t('Autocomplete matching'), + '#title' => $this->t('Autocomplete matching'), '#default_value' => $this->getSetting('match_operator'), '#options' => $this->getMatchOperatorOptions(), - '#description' => t('Select the method used to collect autocomplete suggestions. Note that Contains can cause performance issues on sites with thousands of entities.'), + '#description' => $this->t('Select the method used to collect autocomplete suggestions. Note that Contains can cause performance issues on sites with thousands of entities.'), ]; $element['match_limit'] = [ '#type' => 'number', @@ -54,16 +54,16 @@ class EntityReferenceAutocompleteWidget extends WidgetBase { ]; $element['size'] = [ '#type' => 'number', - '#title' => t('Size of textfield'), + '#title' => $this->t('Size of textfield'), '#default_value' => $this->getSetting('size'), '#min' => 1, '#required' => TRUE, ]; $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -75,16 +75,16 @@ class EntityReferenceAutocompleteWidget extends WidgetBase { $summary = []; $operators = $this->getMatchOperatorOptions(); - $summary[] = t('Autocomplete matching: @match_operator', ['@match_operator' => $operators[$this->getSetting('match_operator')]]); + $summary[] = $this->t('Autocomplete matching: @match_operator', ['@match_operator' => $operators[$this->getSetting('match_operator')]]); $size = $this->getSetting('match_limit') ?: $this->t('unlimited'); $summary[] = $this->t('Autocomplete suggestion list size: @size', ['@size' => $size]); - $summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]); + $summary[] = $this->t('Textfield size: @size', ['@size' => $this->getSetting('size')]); $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } else { - $summary[] = t('No placeholder'); + $summary[] = $this->t('No placeholder'); } return $summary; @@ -207,8 +207,8 @@ class EntityReferenceAutocompleteWidget extends WidgetBase { */ protected function getMatchOperatorOptions() { return [ - 'STARTS_WITH' => t('Starts with'), - 'CONTAINS' => t('Contains'), + 'STARTS_WITH' => $this->t('Starts with'), + 'CONTAINS' => $this->t('Contains'), ]; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php index 976b52832e7..f3ad573408c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/NumberWidget.php @@ -38,9 +38,9 @@ class NumberWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -53,10 +53,10 @@ class NumberWidget extends WidgetBase { $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } else { - $summary[] = t('No placeholder'); + $summary[] = $this->t('No placeholder'); } return $summary; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php index 7787106d85f..5c9603ee5b5 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsButtonsWidget.php @@ -64,7 +64,7 @@ class OptionsButtonsWidget extends OptionsWidgetBase { */ protected function getEmptyLabel() { if (!$this->required && !$this->multiple) { - return t('N/A'); + return $this->t('N/A'); } } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php index b623c8755ee..33e92109d25 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsSelectWidget.php @@ -62,7 +62,7 @@ class OptionsSelectWidget extends OptionsWidgetBase { if ($this->multiple) { // Multiple select: add a 'none' option for non-required fields. if (!$this->required) { - return t('- None -'); + return $this->t('- None -'); } } else { @@ -70,10 +70,10 @@ class OptionsSelectWidget extends OptionsWidgetBase { // and a 'select a value' option for required fields that do not come // with a value selected. if (!$this->required) { - return t('- None -'); + return $this->t('- None -'); } if (!$this->has_value) { - return t('- Select a value -'); + return $this->t('- Select a value -'); } } } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php index ffbfeb2f710..5b343aedc0a 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php @@ -9,6 +9,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\OptGroup; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Base class for the 'options_*' widgets. @@ -88,7 +89,7 @@ abstract class OptionsWidgetBase extends WidgetBase { */ public static function validateElement(array $element, FormStateInterface $form_state) { if ($element['#required'] && $element['#value'] == '_none') { - $form_state->setError($element, t('@name field is required.', ['@name' => $element['#title']])); + $form_state->setError($element, new TranslatableMarkup('@name field is required.', ['@name' => $element['#title']])); } // Massage submitted form values. diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextareaWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextareaWidget.php index 5f21b5edd49..e3f4a218c31 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextareaWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextareaWidget.php @@ -35,16 +35,16 @@ class StringTextareaWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['rows'] = [ '#type' => 'number', - '#title' => t('Rows'), + '#title' => $this->t('Rows'), '#default_value' => $this->getSetting('rows'), '#required' => TRUE, '#min' => 1, ]; $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -55,10 +55,10 @@ class StringTextareaWidget extends WidgetBase { public function settingsSummary() { $summary = []; - $summary[] = t('Number of rows: @rows', ['@rows' => $this->getSetting('rows')]); + $summary[] = $this->t('Number of rows: @rows', ['@rows' => $this->getSetting('rows')]); $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } return $summary; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php index a0bb425f0cb..4d86a33f831 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/StringTextfieldWidget.php @@ -35,16 +35,16 @@ class StringTextfieldWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['size'] = [ '#type' => 'number', - '#title' => t('Size of textfield'), + '#title' => $this->t('Size of textfield'), '#default_value' => $this->getSetting('size'), '#required' => TRUE, '#min' => 1, ]; $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -55,10 +55,10 @@ class StringTextfieldWidget extends WidgetBase { public function settingsSummary() { $summary = []; - $summary[] = t('Textfield size: @size', ['@size' => $this->getSetting('size')]); + $summary[] = $this->t('Textfield size: @size', ['@size' => $this->getSetting('size')]); $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } return $summary; diff --git a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php index a31831a2c5b..070fb96792b 100644 --- a/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php +++ b/core/modules/ckeditor5/src/Plugin/Editor/CKEditor5.php @@ -312,7 +312,7 @@ class CKEditor5 extends EditorBase implements ContainerFactoryPluginInterface { 'warning' => [$css_warning], ], '#status_headings' => [ - 'warning' => t('Warning message'), + 'warning' => $this->t('Warning message'), ], ]; } diff --git a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php index 255b5ab7c13..b3934b9d9c7 100644 --- a/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php +++ b/core/modules/comment/src/Plugin/Field/FieldType/CommentItem.php @@ -12,6 +12,7 @@ use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Session\AnonymousUserSession; use Drupal\Core\Url; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Plugin implementation of the 'comment' field type. @@ -55,26 +56,26 @@ class CommentItem extends FieldItemBase implements CommentItemInterface { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['status'] = DataDefinition::create('integer') - ->setLabel(t('Comment status')) + ->setLabel(new TranslatableMarkup('Comment status')) ->setRequired(TRUE); $properties['cid'] = DataDefinition::create('integer') - ->setLabel(t('Last comment ID')); + ->setLabel(new TranslatableMarkup('Last comment ID')); $properties['last_comment_timestamp'] = DataDefinition::create('integer') - ->setLabel(t('Last comment timestamp')) - ->setDescription(t('The time that the last comment was created.')); + ->setLabel(new TranslatableMarkup('Last comment timestamp')) + ->setDescription(new TranslatableMarkup('The time that the last comment was created.')); $properties['last_comment_name'] = DataDefinition::create('string') - ->setLabel(t('Last comment name')) - ->setDescription(t('The name of the user posting the last comment.')); + ->setLabel(new TranslatableMarkup('Last comment name')) + ->setDescription(new TranslatableMarkup('The name of the user posting the last comment.')); $properties['last_comment_uid'] = DataDefinition::create('integer') - ->setLabel(t('Last comment user ID')); + ->setLabel(new TranslatableMarkup('Last comment user ID')); $properties['comment_count'] = DataDefinition::create('integer') - ->setLabel(t('Number of comments')) - ->setDescription(t('The number of comments.')); + ->setLabel(new TranslatableMarkup('Number of comments')) + ->setDescription(new TranslatableMarkup('The number of comments.')); return $properties; } @@ -108,13 +109,13 @@ class CommentItem extends FieldItemBase implements CommentItemInterface { $element['default_mode'] = [ '#type' => 'checkbox', - '#title' => t('Threading'), + '#title' => $this->t('Threading'), '#default_value' => $settings['default_mode'], - '#description' => t('Show comment replies in a threaded list.'), + '#description' => $this->t('Show comment replies in a threaded list.'), ]; $element['per_page'] = [ '#type' => 'number', - '#title' => t('Comments per page'), + '#title' => $this->t('Comments per page'), '#default_value' => $settings['per_page'], '#required' => TRUE, '#min' => 1, @@ -122,28 +123,28 @@ class CommentItem extends FieldItemBase implements CommentItemInterface { ]; $element['anonymous'] = [ '#type' => 'select', - '#title' => t('Anonymous commenting'), + '#title' => $this->t('Anonymous commenting'), '#default_value' => $settings['anonymous'], '#options' => [ - CommentInterface::ANONYMOUS_MAYNOT_CONTACT => t('Anonymous posters may not enter their contact information'), - CommentInterface::ANONYMOUS_MAY_CONTACT => t('Anonymous posters may leave their contact information'), - CommentInterface::ANONYMOUS_MUST_CONTACT => t('Anonymous posters must leave their contact information'), + CommentInterface::ANONYMOUS_MAYNOT_CONTACT => $this->t('Anonymous posters may not enter their contact information'), + CommentInterface::ANONYMOUS_MAY_CONTACT => $this->t('Anonymous posters may leave their contact information'), + CommentInterface::ANONYMOUS_MUST_CONTACT => $this->t('Anonymous posters must leave their contact information'), ], '#access' => $anonymous_user->hasPermission('post comments'), ]; $element['form_location'] = [ '#type' => 'checkbox', - '#title' => t('Show reply form on the same page as comments'), + '#title' => $this->t('Show reply form on the same page as comments'), '#default_value' => $settings['form_location'], ]; $element['preview'] = [ '#type' => 'radios', - '#title' => t('Preview comment'), + '#title' => $this->t('Preview comment'), '#default_value' => $settings['preview'], '#options' => [ - DRUPAL_DISABLED => t('Disabled'), - DRUPAL_OPTIONAL => t('Optional'), - DRUPAL_REQUIRED => t('Required'), + DRUPAL_DISABLED => $this->t('Disabled'), + DRUPAL_OPTIONAL => $this->t('Optional'), + DRUPAL_REQUIRED => $this->t('Required'), ], ]; @@ -185,7 +186,7 @@ class CommentItem extends FieldItemBase implements CommentItemInterface { } $element['comment_type'] = [ '#type' => 'select', - '#title' => t('Comment type'), + '#title' => $this->t('Comment type'), '#options' => $options, '#required' => TRUE, '#description' => $this->t('Select the Comment type to use for this comment field. Manage the comment types from the administration overview page.', [':url' => Url::fromRoute('entity.comment_type.collection')->toString()]), diff --git a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php index c9478f622c2..a7159513bec 100644 --- a/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php +++ b/core/modules/comment/src/Plugin/Field/FieldWidget/CommentWidget.php @@ -29,22 +29,22 @@ class CommentWidget extends WidgetBase { $element['status'] = [ '#type' => 'radios', - '#title' => t('Comments'), + '#title' => $this->t('Comments'), '#title_display' => 'invisible', '#default_value' => $items->status, '#options' => [ - CommentItemInterface::OPEN => t('Open'), - CommentItemInterface::CLOSED => t('Closed'), - CommentItemInterface::HIDDEN => t('Hidden'), + CommentItemInterface::OPEN => $this->t('Open'), + CommentItemInterface::CLOSED => $this->t('Closed'), + CommentItemInterface::HIDDEN => $this->t('Hidden'), ], CommentItemInterface::OPEN => [ - '#description' => t('Users with the "Post comments" permission can post comments.'), + '#description' => $this->t('Users with the "Post comments" permission can post comments.'), ], CommentItemInterface::CLOSED => [ - '#description' => t('Users cannot post comments, but existing comments will be displayed.'), + '#description' => $this->t('Users cannot post comments, but existing comments will be displayed.'), ], CommentItemInterface::HIDDEN => [ - '#description' => t('Comments are hidden from view.'), + '#description' => $this->t('Comments are hidden from view.'), ], ]; // If the entity doesn't have any comments, the "hidden" option makes no @@ -53,7 +53,7 @@ class CommentWidget extends WidgetBase { if (!$this->isDefaultValueWidget($form_state) && !$items->comment_count) { $element['status'][CommentItemInterface::HIDDEN]['#access'] = FALSE; // Also adjust the description of the "closed" option. - $element['status'][CommentItemInterface::CLOSED]['#description'] = t('Users cannot post comments.'); + $element['status'][CommentItemInterface::CLOSED]['#description'] = $this->t('Users cannot post comments.'); } // If the advanced settings tabs-set is available (normally rendered in the // second column on wide-resolutions), place the field as a details element diff --git a/core/modules/content_translation/src/Plugin/Derivative/ContentTranslationContextualLinks.php b/core/modules/content_translation/src/Plugin/Derivative/ContentTranslationContextualLinks.php index 7a4cad5e3de..91fd520caab 100644 --- a/core/modules/content_translation/src/Plugin/Derivative/ContentTranslationContextualLinks.php +++ b/core/modules/content_translation/src/Plugin/Derivative/ContentTranslationContextualLinks.php @@ -5,6 +5,7 @@ namespace Drupal\content_translation\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\content_translation\ContentTranslationManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -14,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class ContentTranslationContextualLinks extends DeriverBase implements ContainerDeriverInterface { + use StringTranslationTrait; + /** * The content translation manager. * @@ -46,7 +49,7 @@ class ContentTranslationContextualLinks extends DeriverBase implements Container public function getDerivativeDefinitions($base_plugin_definition) { // Create contextual links for translatable entity types. foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) { - $this->derivatives[$entity_type_id]['title'] = t('Translate'); + $this->derivatives[$entity_type_id]['title'] = $this->t('Translate'); $this->derivatives[$entity_type_id]['route_name'] = "entity.$entity_type_id.content_translation_overview"; $this->derivatives[$entity_type_id]['group'] = $entity_type_id; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php index fa6549665af..23d01ea3faf 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php +++ b/core/modules/datetime/src/Plugin/Field/FieldFormatter/DateTimeDefaultFormatter.php @@ -52,8 +52,8 @@ class DateTimeDefaultFormatter extends DateTimeFormatterBase { $form['format_type'] = [ '#type' => 'select', - '#title' => t('Date format'), - '#description' => t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), + '#title' => $this->t('Date format'), + '#description' => $this->t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."), '#options' => $options, '#default_value' => $this->getSetting('format_type'), ]; @@ -68,7 +68,7 @@ class DateTimeDefaultFormatter extends DateTimeFormatterBase { $summary = parent::settingsSummary(); $date = new DrupalDateTime(); - $summary[] = t('Format: @display', ['@display' => $this->formatDate($date)]); + $summary[] = $this->t('Format: @display', ['@display' => $this->formatDate($date)]); return $summary; } diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php index 5f77efcd6cd..8c2bc82a299 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeFieldItemList.php @@ -34,19 +34,19 @@ class DateTimeFieldItemList extends FieldItemList { '#parents' => ['default_value_input'], 'default_date_type' => [ '#type' => 'select', - '#title' => t('Default date'), - '#description' => t('Set a default value for this date.'), + '#title' => $this->t('Default date'), + '#description' => $this->t('Set a default value for this date.'), '#default_value' => $default_value[0]['default_date_type'] ?? '', '#options' => [ - static::DEFAULT_VALUE_NOW => t('Current date'), - static::DEFAULT_VALUE_CUSTOM => t('Relative date'), + static::DEFAULT_VALUE_NOW => $this->t('Current date'), + static::DEFAULT_VALUE_CUSTOM => $this->t('Relative date'), ], '#empty_value' => '', ], 'default_date' => [ '#type' => 'textfield', - '#title' => t('Relative default value'), - '#description' => t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See strtotime for more details."), + '#title' => $this->t('Relative default value'), + '#description' => $this->t("Describe a time by reference to the current day, like '+90 days' (90 days from the day the field is created) or '+1 Saturday' (the next Saturday). See strtotime for more details."), '#default_value' => (isset($default_value[0]['default_date_type']) && $default_value[0]['default_date_type'] == static::DEFAULT_VALUE_CUSTOM) ? $default_value[0]['default_date'] : '', '#states' => [ 'visible' => [ @@ -67,7 +67,7 @@ class DateTimeFieldItemList extends FieldItemList { if ($form_state->getValue(['default_value_input', 'default_date_type']) == static::DEFAULT_VALUE_CUSTOM) { $is_strtotime = @strtotime($form_state->getValue(['default_value_input', 'default_date'])); if (!$is_strtotime) { - $form_state->setErrorByName('default_value_input][default_date', t('The relative date value entered is invalid.')); + $form_state->setErrorByName('default_value_input][default_date', $this->t('The relative date value entered is invalid.')); } } } diff --git a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php index 3264069008e..5e17728b99b 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php +++ b/core/modules/datetime/src/Plugin/Field/FieldType/DateTimeItem.php @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Plugin implementation of the 'datetime' field type. @@ -47,12 +48,12 @@ class DateTimeItem extends FieldItemBase implements DateTimeItemInterface { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('datetime_iso8601') - ->setLabel(t('Date value')) + ->setLabel(new TranslatableMarkup('Date value')) ->setRequired(TRUE); $properties['date'] = DataDefinition::create('any') - ->setLabel(t('Computed date')) - ->setDescription(t('The computed DateTime object.')) + ->setLabel(new TranslatableMarkup('Computed date')) + ->setDescription(new TranslatableMarkup('The computed DateTime object.')) ->setComputed(TRUE) ->setClass('\Drupal\datetime\DateTimeComputed') ->setSetting('date source', 'value'); @@ -86,12 +87,12 @@ class DateTimeItem extends FieldItemBase implements DateTimeItemInterface { $element['datetime_type'] = [ '#type' => 'select', - '#title' => t('Date type'), - '#description' => t('Choose the type of date to create.'), + '#title' => $this->t('Date type'), + '#description' => $this->t('Choose the type of date to create.'), '#default_value' => $this->getSetting('datetime_type'), '#options' => [ - static::DATETIME_TYPE_DATETIME => t('Date and time'), - static::DATETIME_TYPE_DATE => t('Date only'), + static::DATETIME_TYPE_DATETIME => $this->t('Date and time'), + static::DATETIME_TYPE_DATE => $this->t('Date only'), ], '#disabled' => $has_data, ]; diff --git a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php index 276d92c4319..0d85d34a051 100644 --- a/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php +++ b/core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php @@ -93,29 +93,33 @@ class DateTimeDatelistWidget extends DateTimeWidgetBase { $element['date_order'] = [ '#type' => 'select', - '#title' => t('Date part order'), + '#title' => $this->t('Date part order'), '#default_value' => $this->getSetting('date_order'), - '#options' => ['MDY' => t('Month/Day/Year'), 'DMY' => t('Day/Month/Year'), 'YMD' => t('Year/Month/Day')], + '#options' => [ + 'MDY' => $this->t('Month/Day/Year'), + 'DMY' => $this->t('Day/Month/Year'), + 'YMD' => $this->t('Year/Month/Day'), + ], ]; if ($this->getFieldSetting('datetime_type') == 'datetime') { $element['time_type'] = [ '#type' => 'select', - '#title' => t('Time type'), + '#title' => $this->t('Time type'), '#default_value' => $this->getSetting('time_type'), - '#options' => ['24' => t('24 hour time'), '12' => t('12 hour time')], + '#options' => ['24' => $this->t('24 hour time'), '12' => $this->t('12 hour time')], ]; $element['increment'] = [ '#type' => 'select', - '#title' => t('Time increments'), + '#title' => $this->t('Time increments'), '#default_value' => $this->getSetting('increment'), '#options' => [ - 1 => t('1 minute'), - 5 => t('5 minute'), - 10 => t('10 minute'), - 15 => t('15 minute'), - 30 => t('30 minute'), + 1 => $this->t('1 minute'), + 5 => $this->t('5 minute'), + 10 => $this->t('10 minute'), + 15 => $this->t('15 minute'), + 30 => $this->t('30 minute'), ], ]; } @@ -140,10 +144,10 @@ class DateTimeDatelistWidget extends DateTimeWidgetBase { public function settingsSummary() { $summary = []; - $summary[] = t('Date part order: @order', ['@order' => $this->getSetting('date_order')]); + $summary[] = $this->t('Date part order: @order', ['@order' => $this->getSetting('date_order')]); if ($this->getFieldSetting('datetime_type') == 'datetime') { - $summary[] = t('Time type: @time_type', ['@time_type' => $this->getSetting('time_type')]); - $summary[] = t('Time increments: @increment', ['@increment' => $this->getSetting('increment')]); + $summary[] = $this->t('Time type: @time_type', ['@time_type' => $this->getSetting('time_type')]); + $summary[] = $this->t('Time increments: @increment', ['@increment' => $this->getSetting('increment')]); } return $summary; diff --git a/core/modules/editor/tests/modules/src/Plugin/Editor/TRexEditor.php b/core/modules/editor/tests/modules/src/Plugin/Editor/TRexEditor.php index 5c8be2216e6..70af7d822df 100644 --- a/core/modules/editor/tests/modules/src/Plugin/Editor/TRexEditor.php +++ b/core/modules/editor/tests/modules/src/Plugin/Editor/TRexEditor.php @@ -34,7 +34,7 @@ class TRexEditor extends EditorBase { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['stumpy_arms'] = [ - '#title' => t('Stumpy arms'), + '#title' => $this->t('Stumpy arms'), '#type' => 'checkbox', '#default_value' => TRUE, ]; diff --git a/core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php b/core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php index f6a35434a43..fc7e4f4544e 100644 --- a/core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php +++ b/core/modules/editor/tests/modules/src/Plugin/Editor/UnicornEditor.php @@ -35,7 +35,7 @@ class UnicornEditor extends EditorBase { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['ponies_too'] = [ - '#title' => t('Pony mode'), + '#title' => $this->t('Pony mode'), '#type' => 'checkbox', '#default_value' => TRUE, ]; diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php index 80f860bfafd..74065a5672a 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldDefaultFormatter.php @@ -36,7 +36,7 @@ class TestFieldDefaultFormatter extends FormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['test_formatter_setting'] = [ - '#title' => t('Setting'), + '#title' => $this->t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting'), @@ -50,7 +50,7 @@ class TestFieldDefaultFormatter extends FormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')]); + $summary[] = $this->t('@setting: @value', ['@setting' => 'test_formatter_setting', '@value' => $this->getSetting('test_formatter_setting')]); return $summary; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php index f36fea2c391..86b8465e10f 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldEmptySettingFormatter.php @@ -34,7 +34,7 @@ class TestFieldEmptySettingFormatter extends FormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['field_empty_setting'] = [ - '#title' => t('Setting'), + '#title' => $this->t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('field_empty_setting'), @@ -50,7 +50,7 @@ class TestFieldEmptySettingFormatter extends FormatterBase { $summary = []; $setting = $this->getSetting('field_empty_setting'); if (!empty($setting)) { - $summary[] = t('Default empty setting now has a value.'); + $summary[] = $this->t('Default empty setting now has a value.'); } return $summary; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php index 978e18fbac6..7f6bab89edd 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldMultipleFormatter.php @@ -37,7 +37,7 @@ class TestFieldMultipleFormatter extends FormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['test_formatter_setting_multiple'] = [ - '#title' => t('Setting'), + '#title' => $this->t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting_multiple'), @@ -51,7 +51,7 @@ class TestFieldMultipleFormatter extends FormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')]); + $summary[] = $this->t('@setting: @value', ['@setting' => 'test_formatter_setting_multiple', '@value' => $this->getSetting('test_formatter_setting_multiple')]); return $summary; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php index 39bff8d8773..038fd151f82 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldFormatter/TestFieldPrepareViewFormatter.php @@ -35,7 +35,7 @@ class TestFieldPrepareViewFormatter extends FormatterBase { */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['test_formatter_setting_additional'] = [ - '#title' => t('Setting'), + '#title' => $this->t('Setting'), '#type' => 'textfield', '#size' => 20, '#default_value' => $this->getSetting('test_formatter_setting_additional'), @@ -49,7 +49,7 @@ class TestFieldPrepareViewFormatter extends FormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('@setting: @value', ['@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')]); + $summary[] = $this->t('@setting: @value', ['@setting' => 'test_formatter_setting_additional', '@value' => $this->getSetting('test_formatter_setting_additional')]); return $summary; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php index d889f816f10..ad2a135a217 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItem.php @@ -3,6 +3,7 @@ namespace Drupal\field_test\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\Field\FieldItemBase; @@ -47,7 +48,7 @@ class TestItem extends FieldItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') - ->setLabel(t('Test integer value')) + ->setLabel(new TranslatableMarkup('Test integer value')) ->setRequired(TRUE); return $properties; @@ -76,10 +77,10 @@ class TestItem extends FieldItemBase { public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { $form['test_field_storage_setting'] = [ '#type' => 'textfield', - '#title' => t('Field test field storage setting'), + '#title' => $this->t('Field test field storage setting'), '#default_value' => $this->getSetting('test_field_storage_setting'), '#required' => FALSE, - '#description' => t('A dummy form element to simulate field storage setting.'), + '#description' => $this->t('A dummy form element to simulate field storage setting.'), ]; return $form; @@ -91,10 +92,10 @@ class TestItem extends FieldItemBase { public function fieldSettingsForm(array $form, FormStateInterface $form_state) { $form['test_field_setting'] = [ '#type' => 'textfield', - '#title' => t('Field test field setting'), + '#title' => $this->t('Field test field setting'), '#default_value' => $this->getSetting('test_field_setting'), '#required' => FALSE, - '#description' => t('A dummy form element to simulate field setting.'), + '#description' => $this->t('A dummy form element to simulate field setting.'), ]; return $form; @@ -119,7 +120,7 @@ class TestItem extends FieldItemBase { 'value' => [ 'TestField' => [ 'value' => -1, - 'message' => t('%name does not accept the value @value.', ['%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1]), + 'message' => $this->t('%name does not accept the value @value.', ['%name' => $this->getFieldDefinition()->getLabel(), '@value' => -1]), ], ], ]); diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php index 6c98205f4f1..1c5754238af 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldType/TestItemWithPreconfiguredOptions.php @@ -4,6 +4,7 @@ namespace Drupal\field_test\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Defines the 'test_field_with_preconfigured_options' entity field item. @@ -24,8 +25,8 @@ class TestItemWithPreconfiguredOptions extends TestItem implements Preconfigured public static function getPreconfiguredOptions() { return [ 'custom_options' => [ - 'label' => t('All custom options'), - 'category' => t('Custom category'), + 'label' => new TranslatableMarkup('All custom options'), + 'category' => new TranslatableMarkup('Custom category'), 'field_storage_config' => [ 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'settings' => [ diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php index b2f9738f24c..ef4efd2078c 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php @@ -40,8 +40,8 @@ class TestFieldWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['test_widget_setting'] = [ '#type' => 'textfield', - '#title' => t('Field test field widget setting'), - '#description' => t('A dummy form element to simulate field widget setting.'), + '#title' => $this->t('Field test field widget setting'), + '#description' => $this->t('A dummy form element to simulate field widget setting.'), '#default_value' => $this->getSetting('test_widget_setting'), '#required' => FALSE, ]; @@ -53,7 +53,7 @@ class TestFieldWidget extends WidgetBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('@setting: @value', ['@setting' => 'test_widget_setting', '@value' => $this->getSetting('test_widget_setting')]); + $summary[] = $this->t('@setting: @value', ['@setting' => 'test_widget_setting', '@value' => $this->getSetting('test_widget_setting')]); return $summary; } diff --git a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php index 3f9c0ea09f0..eaf7e77e68a 100644 --- a/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php +++ b/core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidgetMultiple.php @@ -40,8 +40,8 @@ class TestFieldWidgetMultiple extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['test_widget_setting_multiple'] = [ '#type' => 'textfield', - '#title' => t('Field test field widget setting'), - '#description' => t('A dummy form element to simulate field widget setting.'), + '#title' => $this->t('Field test field widget setting'), + '#description' => $this->t('A dummy form element to simulate field widget setting.'), '#default_value' => $this->getSetting('test_widget_setting_multiple'), '#required' => FALSE, ]; @@ -53,7 +53,7 @@ class TestFieldWidgetMultiple extends WidgetBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('@setting: @value', ['@setting' => 'test_widget_setting_multiple', '@value' => $this->getSetting('test_widget_setting_multiple')]); + $summary[] = $this->t('@setting: @value', ['@setting' => 'test_widget_setting_multiple', '@value' => $this->getSetting('test_widget_setting_multiple')]); return $summary; } diff --git a/core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php b/core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php index e6a8db60387..3c0aa914fab 100644 --- a/core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php +++ b/core/modules/file/src/Plugin/Field/FieldFormatter/TableFormatter.php @@ -24,7 +24,7 @@ class TableFormatter extends DescriptionAwareFileFormatterBase { $elements = []; if ($files = $this->getEntitiesToView($items, $langcode)) { - $header = [t('Attachment'), t('Size')]; + $header = [$this->t('Attachment'), $this->t('Size')]; $rows = []; foreach ($files as $file) { $item = $file->_referringItem; diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php index 758d483e013..dc37bf03502 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php @@ -12,6 +12,7 @@ use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; /** @@ -96,11 +97,11 @@ class FileItem extends EntityReferenceItem { $properties = parent::propertyDefinitions($field_definition); $properties['display'] = DataDefinition::create('boolean') - ->setLabel(t('Display')) - ->setDescription(t('Flag to control whether this file should be displayed when viewing content')); + ->setLabel(new TranslatableMarkup('Display')) + ->setDescription(new TranslatableMarkup('Flag to control whether this file should be displayed when viewing content')); $properties['description'] = DataDefinition::create('string') - ->setLabel(t('Description')); + ->setLabel(new TranslatableMarkup('Description')); return $properties; } @@ -115,15 +116,15 @@ class FileItem extends EntityReferenceItem { $element['display_field'] = [ '#type' => 'checkbox', - '#title' => t('Enable Display field'), + '#title' => $this->t('Enable Display field'), '#default_value' => $this->getSetting('display_field'), - '#description' => t('The display option allows users to choose if a file should be shown when viewing the content.'), + '#description' => $this->t('The display option allows users to choose if a file should be shown when viewing the content.'), ]; $element['display_default'] = [ '#type' => 'checkbox', - '#title' => t('Files displayed by default'), + '#title' => $this->t('Files displayed by default'), '#default_value' => $this->getSetting('display_default'), - '#description' => t('This setting only has an effect if the display option is enabled.'), + '#description' => $this->t('This setting only has an effect if the display option is enabled.'), '#states' => [ 'visible' => [ ':input[name="settings[display_field]"]' => ['checked' => TRUE], @@ -134,10 +135,10 @@ class FileItem extends EntityReferenceItem { $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE); $element['uri_scheme'] = [ '#type' => 'radios', - '#title' => t('Upload destination'), + '#title' => $this->t('Upload destination'), '#options' => $scheme_options, '#default_value' => $this->getSetting('uri_scheme'), - '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + '#description' => $this->t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), '#disabled' => $has_data, ]; @@ -153,9 +154,9 @@ class FileItem extends EntityReferenceItem { $element['file_directory'] = [ '#type' => 'textfield', - '#title' => t('File directory'), + '#title' => $this->t('File directory'), '#default_value' => $settings['file_directory'], - '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), + '#description' => $this->t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'), '#element_validate' => [[static::class, 'validateDirectory']], '#weight' => 3, ]; @@ -164,7 +165,7 @@ class FileItem extends EntityReferenceItem { $extensions = str_replace(' ', ', ', $settings['file_extensions']); $element['file_extensions'] = [ '#type' => 'textfield', - '#title' => t('Allowed file extensions'), + '#title' => $this->t('Allowed file extensions'), '#default_value' => $extensions, '#description' => $this->t("Separate extensions with a comma or space. Each extension can contain alphanumeric characters, '.', and '_', and should start and end with an alphanumeric character."), '#element_validate' => [[static::class, 'validateExtensions']], @@ -177,9 +178,9 @@ class FileItem extends EntityReferenceItem { $element['max_filesize'] = [ '#type' => 'textfield', - '#title' => t('Maximum upload size'), + '#title' => $this->t('Maximum upload size'), '#default_value' => $settings['max_filesize'], - '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', ['%limit' => format_size(Environment::getUploadMaxSize())]), + '#description' => $this->t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit %limit).', ['%limit' => format_size(Environment::getUploadMaxSize())]), '#size' => 10, '#element_validate' => [[static::class, 'validateMaxFilesize']], '#weight' => 5, @@ -187,9 +188,9 @@ class FileItem extends EntityReferenceItem { $element['description_field'] = [ '#type' => 'checkbox', - '#title' => t('Enable Description field'), + '#title' => $this->t('Enable Description field'), '#default_value' => $settings['description_field'] ?? '', - '#description' => t('The description field allows users to enter a description about the uploaded file.'), + '#description' => $this->t('The description field allows users to enter a description about the uploaded file.'), '#weight' => 11, ]; @@ -228,7 +229,7 @@ class FileItem extends EntityReferenceItem { $extension_array = array_unique(array_filter(explode(' ', $extensions))); $extensions = implode(' ', $extension_array); if (!preg_match('/^([a-z0-9]+([._][a-z0-9])* ?)+$/', $extensions)) { - $form_state->setError($element, t("The list of allowed extensions is not valid. Allowed characters are a-z, 0-9, '.', and '_'. The first and last characters cannot be '.' or '_', and these two characters cannot appear next to each other. Separate extensions with a comma or space.")); + $form_state->setError($element, new TranslatableMarkup("The list of allowed extensions is not valid. Allowed characters are a-z, 0-9, '.', and '_'. The first and last characters cannot be '.' or '_', and these two characters cannot appear next to each other. Separate extensions with a comma or space.")); } else { $form_state->setValueForElement($element, $extensions); @@ -239,7 +240,8 @@ class FileItem extends EntityReferenceItem { if (!in_array('txt', $extension_array, TRUE) && !\Drupal::config('system.file')->get('allow_insecure_uploads')) { foreach ($extension_array as $extension) { if (preg_match(FileSystemInterface::INSECURE_EXTENSION_REGEX, 'test.' . $extension)) { - $form_state->setError($element, t('Add %txt_extension to the list of allowed extensions to securely upload files with a %extension extension. The %txt_extension extension will then be added automatically.', ['%extension' => $extension, '%txt_extension' => 'txt'])); + $form_state->setError($element, new TranslatableMarkup('Add %txt_extension to the list of allowed extensions to securely upload files with a %extension extension. The %txt_extension extension will then be added automatically.', ['%extension' => $extension, '%txt_extension' => 'txt'])); + break; } } @@ -260,7 +262,7 @@ class FileItem extends EntityReferenceItem { $element['#value'] = trim($element['#value']); $form_state->setValue(['settings', 'max_filesize'], $element['#value']); if (!empty($element['#value']) && !Bytes::validate($element['#value'])) { - $form_state->setError($element, t('The "@name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', ['@name' => $element['#title']])); + $form_state->setError($element, new TranslatableMarkup('The "@name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', ['@name' => $element['#title']])); } } diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index 354fed1cf7e..70bd4a71668 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -10,6 +10,7 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Element; use Drupal\Core\Render\ElementInfoManagerInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\file\Element\ManagedFile; use Drupal\file\Entity\File; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -63,13 +64,13 @@ class FileWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['progress_indicator'] = [ '#type' => 'radios', - '#title' => t('Progress indicator'), + '#title' => $this->t('Progress indicator'), '#options' => [ - 'throbber' => t('Throbber'), - 'bar' => t('Bar with progress meter'), + 'throbber' => $this->t('Throbber'), + 'bar' => $this->t('Bar with progress meter'), ], '#default_value' => $this->getSetting('progress_indicator'), - '#description' => t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'), + '#description' => $this->t('The throbber display does not show the status of uploads but takes up less space. The progress bar is helpful for monitoring progress on large uploads.'), '#weight' => 16, '#access' => file_progress_implementation(), ]; @@ -81,7 +82,7 @@ class FileWidget extends WidgetBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('Progress indicator: @progress_indicator', ['@progress_indicator' => $this->getSetting('progress_indicator')]); + $summary[] = $this->t('Progress indicator: @progress_indicator', ['@progress_indicator' => $this->getSetting('progress_indicator')]); return $summary; } @@ -137,7 +138,7 @@ class FileWidget extends WidgetBase { // defined by widget. $element['_weight'] = [ '#type' => 'weight', - '#title' => t('Weight for row @number', ['@number' => $delta + 1]), + '#title' => $this->t('Weight for row @number', ['@number' => $delta + 1]), '#title_display' => 'invisible', // Note: this 'delta' is the FAPI #type 'weight' element's property. '#delta' => $max, @@ -193,7 +194,7 @@ class FileWidget extends WidgetBase { // Add some properties that will eventually be added to the file upload // field. These are added here so that they may be referenced easily // through a hook_form_alter(). - $elements['#file_upload_title'] = t('Add a new file'); + $elements['#file_upload_title'] = $this->t('Add a new file'); $elements['#file_upload_description'] = [ '#theme' => 'file_upload_help', '#description' => '', @@ -368,7 +369,7 @@ class FileWidget extends WidgetBase { '@count' => $total_uploaded_count, '%list' => implode(', ', $removed_names), ]; - $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); + $message = new TranslatableMarkup('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args); \Drupal::messenger()->addWarning($message); $values['fids'] = array_slice($values['fids'], 0, $keep); NestedArray::setValue($form_state->getValues(), $element['#parents'], $values); @@ -391,7 +392,7 @@ class FileWidget extends WidgetBase { if ($element['#display_field']) { $element['display'] = [ '#type' => empty($item['fids']) ? 'hidden' : 'checkbox', - '#title' => t('Include file in display'), + '#title' => new TranslatableMarkup('Include file in display'), '#attributes' => ['class' => ['file-display']], ]; if (isset($item['display'])) { @@ -413,10 +414,10 @@ class FileWidget extends WidgetBase { $config = \Drupal::config('file.settings'); $element['description'] = [ '#type' => $config->get('description.type'), - '#title' => t('Description'), + '#title' => new TranslatableMarkup('Description'), '#value' => $item['description'] ?? '', '#maxlength' => $config->get('description.length'), - '#description' => t('The description may be used as the label of the link to the file.'), + '#description' => new TranslatableMarkup('The description may be used as the label of the link to the file.'), ]; } @@ -483,7 +484,7 @@ class FileWidget extends WidgetBase { $description = static::getDescriptionFromElement($element[$key]); $element[$key]['_weight'] = [ '#type' => 'weight', - '#title' => $description ? t('Weight for @title', ['@title' => $description]) : t('Weight for new file'), + '#title' => $description ? new TranslatableMarkup('Weight for @title', ['@title' => $description]) : new TranslatableMarkup('Weight for new file'), '#title_display' => 'invisible', '#delta' => $count, '#default_value' => $delta, diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index 0c5be967e0d..ab2c11c2e5b 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -122,24 +122,24 @@ class ImageFormatter extends ImageFormatterBase { Url::fromRoute('entity.image_style.collection') ); $element['image_style'] = [ - '#title' => t('Image style'), + '#title' => $this->t('Image style'), '#type' => 'select', '#default_value' => $this->getSetting('image_style'), - '#empty_option' => t('None (original image)'), + '#empty_option' => $this->t('None (original image)'), '#options' => $image_styles, '#description' => $description_link->toRenderable() + [ '#access' => $this->currentUser->hasPermission('administer image styles'), ], ]; $link_types = [ - 'content' => t('Content'), - 'file' => t('File'), + 'content' => $this->t('Content'), + 'file' => $this->t('File'), ]; $element['image_link'] = [ - '#title' => t('Link image to'), + '#title' => $this->t('Link image to'), '#type' => 'select', '#default_value' => $this->getSetting('image_link'), - '#empty_option' => t('Nothing'), + '#empty_option' => $this->t('Nothing'), '#options' => $link_types, ]; @@ -182,15 +182,15 @@ class ImageFormatter extends ImageFormatterBase { // their styles in code. $image_style_setting = $this->getSetting('image_style'); if (isset($image_styles[$image_style_setting])) { - $summary[] = t('Image style: @style', ['@style' => $image_styles[$image_style_setting]]); + $summary[] = $this->t('Image style: @style', ['@style' => $image_styles[$image_style_setting]]); } else { - $summary[] = t('Original image'); + $summary[] = $this->t('Original image'); } $link_types = [ - 'content' => t('Linked to content'), - 'file' => t('Linked to file'), + 'content' => $this->t('Linked to content'), + 'file' => $this->t('Linked to file'), ]; // Display this setting only if image is linked. $image_link_setting = $this->getSetting('image_link'); diff --git a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php index 8992a77ab75..ca449ad8908 100644 --- a/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php +++ b/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php @@ -10,6 +10,7 @@ use Drupal\Core\File\Exception\FileException; use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StreamWrapper\StreamWrapperInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; use Drupal\file\Entity\File; use Drupal\file\Plugin\Field\FieldType\FileItem; @@ -141,20 +142,20 @@ class ImageItem extends FileItem { unset($properties['description']); $properties['alt'] = DataDefinition::create('string') - ->setLabel(t('Alternative text')) - ->setDescription(t("Alternative image text, for the image's 'alt' attribute.")); + ->setLabel(new TranslatableMarkup('Alternative text')) + ->setDescription(new TranslatableMarkup("Alternative image text, for the image's 'alt' attribute.")); $properties['title'] = DataDefinition::create('string') - ->setLabel(t('Title')) - ->setDescription(t("Image title text, for the image's 'title' attribute.")); + ->setLabel(new TranslatableMarkup('Title')) + ->setDescription(new TranslatableMarkup("Image title text, for the image's 'title' attribute.")); $properties['width'] = DataDefinition::create('integer') - ->setLabel(t('Width')) - ->setDescription(t('The width of the image in pixels.')); + ->setLabel(new TranslatableMarkup('Width')) + ->setDescription(new TranslatableMarkup('The width of the image in pixels.')); $properties['height'] = DataDefinition::create('integer') - ->setLabel(t('Height')) - ->setDescription(t('The height of the image in pixels.')); + ->setLabel(new TranslatableMarkup('Height')) + ->setDescription(new TranslatableMarkup('The height of the image in pixels.')); return $properties; } @@ -173,15 +174,15 @@ class ImageItem extends FileItem { $scheme_options = \Drupal::service('stream_wrapper_manager')->getNames(StreamWrapperInterface::WRITE_VISIBLE); $element['uri_scheme'] = [ '#type' => 'radios', - '#title' => t('Upload destination'), + '#title' => $this->t('Upload destination'), '#options' => $scheme_options, '#default_value' => $settings['uri_scheme'], - '#description' => t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), + '#description' => $this->t('Select where the final files should be stored. Private file storage has significantly more overhead than public files, but allows restricted access to files within this field.'), ]; // Add default_image element. static::defaultImageForm($element, $settings); - $element['default_image']['#description'] = t('If no image is uploaded, this image will be shown on display.'); + $element['default_image']['#description'] = $this->t('If no image is uploaded, this image will be shown on display.'); return $element; } @@ -199,14 +200,14 @@ class ImageItem extends FileItem { $max_resolution = explode('x', $settings['max_resolution']) + ['', '']; $element['max_resolution'] = [ '#type' => 'item', - '#title' => t('Maximum image resolution'), + '#title' => $this->t('Maximum image resolution'), '#element_validate' => [[static::class, 'validateResolution']], '#weight' => 4.1, - '#description' => t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of EXIF data in the image.'), + '#description' => $this->t('The maximum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a larger image is uploaded, it will be resized to reflect the given width and height. Resizing images on upload will cause the loss of EXIF data in the image.'), ]; $element['max_resolution']['x'] = [ '#type' => 'number', - '#title' => t('Maximum width'), + '#title' => $this->t('Maximum width'), '#title_display' => 'invisible', '#default_value' => $max_resolution[0], '#min' => 1, @@ -215,25 +216,25 @@ class ImageItem extends FileItem { ]; $element['max_resolution']['y'] = [ '#type' => 'number', - '#title' => t('Maximum height'), + '#title' => $this->t('Maximum height'), '#title_display' => 'invisible', '#default_value' => $max_resolution[1], '#min' => 1, - '#field_suffix' => ' ' . t('pixels'), + '#field_suffix' => ' ' . $this->t('pixels'), '#suffix' => '', ]; $min_resolution = explode('x', $settings['min_resolution']) + ['', '']; $element['min_resolution'] = [ '#type' => 'item', - '#title' => t('Minimum image resolution'), + '#title' => $this->t('Minimum image resolution'), '#element_validate' => [[static::class, 'validateResolution']], '#weight' => 4.2, - '#description' => t('The minimum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'), + '#description' => $this->t('The minimum allowed image size expressed as WIDTH×HEIGHT (e.g. 640×480). Leave blank for no restriction. If a smaller image is uploaded, it will be rejected.'), ]; $element['min_resolution']['x'] = [ '#type' => 'number', - '#title' => t('Minimum width'), + '#title' => $this->t('Minimum width'), '#title_display' => 'invisible', '#default_value' => $min_resolution[0], '#min' => 1, @@ -242,11 +243,11 @@ class ImageItem extends FileItem { ]; $element['min_resolution']['y'] = [ '#type' => 'number', - '#title' => t('Minimum height'), + '#title' => $this->t('Minimum height'), '#title_display' => 'invisible', '#default_value' => $min_resolution[1], '#min' => 1, - '#field_suffix' => ' ' . t('pixels'), + '#field_suffix' => ' ' . $this->t('pixels'), '#suffix' => '', ]; @@ -256,16 +257,16 @@ class ImageItem extends FileItem { // Add title and alt configuration options. $element['alt_field'] = [ '#type' => 'checkbox', - '#title' => t('Enable Alt field'), + '#title' => $this->t('Enable Alt field'), '#default_value' => $settings['alt_field'], - '#description' => t('Short description of the image used by screen readers and displayed when the image is not loaded. Enabling this field is recommended.'), + '#description' => $this->t('Short description of the image used by screen readers and displayed when the image is not loaded. Enabling this field is recommended.'), '#weight' => 9, ]; $element['alt_field_required'] = [ '#type' => 'checkbox', - '#title' => t('Alt field required'), + '#title' => $this->t('Alt field required'), '#default_value' => $settings['alt_field_required'], - '#description' => t('Making this field required is recommended.'), + '#description' => $this->t('Making this field required is recommended.'), '#weight' => 10, '#states' => [ 'visible' => [ @@ -275,14 +276,14 @@ class ImageItem extends FileItem { ]; $element['title_field'] = [ '#type' => 'checkbox', - '#title' => t('Enable Title field'), + '#title' => $this->t('Enable Title field'), '#default_value' => $settings['title_field'], - '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image. Enabling this field is not recommended as it can cause problems with screen readers.'), + '#description' => $this->t('The title attribute is used as a tooltip when the mouse hovers over the image. Enabling this field is not recommended as it can cause problems with screen readers.'), '#weight' => 11, ]; $element['title_field_required'] = [ '#type' => 'checkbox', - '#title' => t('Title field required'), + '#title' => $this->t('Title field required'), '#default_value' => $settings['title_field_required'], '#weight' => 12, '#states' => [ @@ -294,7 +295,7 @@ class ImageItem extends FileItem { // Add default_image element. static::defaultImageForm($element, $settings); - $element['default_image']['#description'] = t("If no image is uploaded, this image will be shown on display and will override the field's default image."); + $element['default_image']['#description'] = $this->t("If no image is uploaded, this image will be shown on display and will override the field's default image."); return $element; } @@ -388,9 +389,9 @@ class ImageItem extends FileItem { if (!empty($element['x']['#value']) || !empty($element['y']['#value'])) { foreach (['x', 'y'] as $dimension) { if (!$element[$dimension]['#value']) { - // We expect the field name placeholder value to be wrapped in t() + // We expect the field name placeholder value to be wrapped in $this->t() // here, so it won't be escaped again as it's already marked safe. - $form_state->setError($element[$dimension], t('Both a height and width value must be specified in the @name field.', ['@name' => $element['#title']])); + $form_state->setError($element[$dimension], new TranslatableMarkup('Both a height and width value must be specified in the @name field.', ['@name' => $element['#title']])); return; } } @@ -412,7 +413,7 @@ class ImageItem extends FileItem { protected function defaultImageForm(array &$element, array $settings) { $element['default_image'] = [ '#type' => 'details', - '#title' => t('Default image'), + '#title' => $this->t('Default image'), '#open' => TRUE, ]; // Convert the stored UUID to a FID. @@ -423,8 +424,8 @@ class ImageItem extends FileItem { } $element['default_image']['uuid'] = [ '#type' => 'managed_file', - '#title' => t('Image'), - '#description' => t('Image to be shown if no image is uploaded.'), + '#title' => $this->t('Image'), + '#description' => $this->t('Image to be shown if no image is uploaded.'), '#default_value' => $fids, '#upload_location' => $settings['uri_scheme'] . '://default_images/', '#element_validate' => [ @@ -435,15 +436,15 @@ class ImageItem extends FileItem { ]; $element['default_image']['alt'] = [ '#type' => 'textfield', - '#title' => t('Alternative text'), - '#description' => t('Short description of the image used by screen readers and displayed when the image is not loaded. This is important for accessibility.'), + '#title' => $this->t('Alternative text'), + '#description' => $this->t('Short description of the image used by screen readers and displayed when the image is not loaded. This is important for accessibility.'), '#default_value' => $settings['default_image']['alt'], '#maxlength' => 512, ]; $element['default_image']['title'] = [ '#type' => 'textfield', - '#title' => t('Title'), - '#description' => t('The title attribute is used as a tooltip when the mouse hovers over the image.'), + '#title' => $this->t('Title'), + '#description' => $this->t('The title attribute is used as a tooltip when the mouse hovers over the image.'), '#default_value' => $settings['default_image']['title'], '#maxlength' => 1024, ]; diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index 5a602339a22..3037615d8ae 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Image\ImageFactory; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\ElementInfoManagerInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\file\Entity\File; use Drupal\file\Plugin\Field\FieldWidget\FileWidget; use Drupal\image\Entity\ImageStyle; @@ -71,12 +72,12 @@ class ImageWidget extends FileWidget { $element = parent::settingsForm($form, $form_state); $element['preview_image_style'] = [ - '#title' => t('Preview image style'), + '#title' => $this->t('Preview image style'), '#type' => 'select', '#options' => image_style_options(FALSE), - '#empty_option' => '<' . t('no preview') . '>', + '#empty_option' => '<' . $this->t('no preview') . '>', '#default_value' => $this->getSetting('preview_image_style'), - '#description' => t('The preview image will be shown while editing the content.'), + '#description' => $this->t('The preview image will be shown while editing the content.'), '#weight' => 15, ]; @@ -96,10 +97,10 @@ class ImageWidget extends FileWidget { // their styles in code. $image_style_setting = $this->getSetting('preview_image_style'); if (isset($image_styles[$image_style_setting])) { - $preview_image_style = t('Preview image style: @style', ['@style' => $image_styles[$image_style_setting]]); + $preview_image_style = $this->t('Preview image style: @style', ['@style' => $image_styles[$image_style_setting]]); } else { - $preview_image_style = t('No preview'); + $preview_image_style = $this->t('No preview'); } array_unshift($summary, $preview_image_style); @@ -256,10 +257,10 @@ class ImageWidget extends FileWidget { // Add the additional alt and title fields. $element['alt'] = [ - '#title' => t('Alternative text'), + '#title' => new TranslatableMarkup('Alternative text'), '#type' => 'textfield', '#default_value' => $item['alt'] ?? '', - '#description' => t('Short description of the image used by screen readers and displayed when the image is not loaded. This is important for accessibility.'), + '#description' => new TranslatableMarkup('Short description of the image used by screen readers and displayed when the image is not loaded. This is important for accessibility.'), // @see https://www.drupal.org/node/465106#alt-text '#maxlength' => 512, '#weight' => -12, @@ -269,9 +270,9 @@ class ImageWidget extends FileWidget { ]; $element['title'] = [ '#type' => 'textfield', - '#title' => t('Title'), + '#title' => new TranslatableMarkup('Title'), '#default_value' => $item['title'] ?? '', - '#description' => t('The title is used as a tool tip when the user hovers the mouse over the image.'), + '#description' => new TranslatableMarkup('The title is used as a tool tip when the user hovers the mouse over the image.'), '#maxlength' => 1024, '#weight' => -11, '#access' => (bool) $item['fids'] && $element['#title_field'], diff --git a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php index 61fb4d478c8..4e848326cf6 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ConvertImageEffect.php @@ -67,7 +67,7 @@ class ConvertImageEffect extends ConfigurableImageEffectBase { ); $form['extension'] = [ '#type' => 'select', - '#title' => t('Convert to'), + '#title' => $this->t('Convert to'), '#default_value' => $this->configuration['extension'], '#required' => TRUE, '#options' => $options, diff --git a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php index cdacda96b7c..8f99de88134 100644 --- a/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/CropImageEffect.php @@ -59,21 +59,21 @@ class CropImageEffect extends ResizeImageEffect { $form = parent::buildConfigurationForm($form, $form_state); $form['anchor'] = [ '#type' => 'radios', - '#title' => t('Anchor'), + '#title' => $this->t('Anchor'), '#options' => [ - 'left-top' => t('Top left'), - 'center-top' => t('Top center'), - 'right-top' => t('Top right'), - 'left-center' => t('Center left'), - 'center-center' => t('Center'), - 'right-center' => t('Center right'), - 'left-bottom' => t('Bottom left'), - 'center-bottom' => t('Bottom center'), - 'right-bottom' => t('Bottom right'), + 'left-top' => $this->t('Top left'), + 'center-top' => $this->t('Top center'), + 'right-top' => $this->t('Top right'), + 'left-center' => $this->t('Center left'), + 'center-center' => $this->t('Center'), + 'right-center' => $this->t('Center right'), + 'left-bottom' => $this->t('Bottom left'), + 'center-bottom' => $this->t('Bottom center'), + 'right-bottom' => $this->t('Bottom right'), ], '#theme' => 'image_anchor', '#default_value' => $this->configuration['anchor'], - '#description' => t('The part of the image that will be retained during the crop.'), + '#description' => $this->t('The part of the image that will be retained during the crop.'), ]; return $form; } diff --git a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php index dba34298def..26f70705db4 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ResizeImageEffect.php @@ -66,17 +66,17 @@ class ResizeImageEffect extends ConfigurableImageEffectBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['width'] = [ '#type' => 'number', - '#title' => t('Width'), + '#title' => $this->t('Width'), '#default_value' => $this->configuration['width'], - '#field_suffix' => ' ' . t('pixels'), + '#field_suffix' => ' ' . $this->t('pixels'), '#required' => TRUE, '#min' => 1, ]; $form['height'] = [ '#type' => 'number', - '#title' => t('Height'), + '#title' => $this->t('Height'), '#default_value' => $this->configuration['height'], - '#field_suffix' => ' ' . t('pixels'), + '#field_suffix' => ' ' . $this->t('pixels'), '#required' => TRUE, '#min' => 1, ]; diff --git a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php index 7e394a3cce6..d6453dbf946 100644 --- a/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/RotateImageEffect.php @@ -83,24 +83,24 @@ class RotateImageEffect extends ConfigurableImageEffectBase { $form['degrees'] = [ '#type' => 'number', '#default_value' => $this->configuration['degrees'], - '#title' => t('Rotation angle'), - '#description' => t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), + '#title' => $this->t('Rotation angle'), + '#description' => $this->t('The number of degrees the image should be rotated. Positive numbers are clockwise, negative are counter-clockwise.'), '#field_suffix' => '°', '#required' => TRUE, ]; $form['bgcolor'] = [ '#type' => 'textfield', '#default_value' => $this->configuration['bgcolor'], - '#title' => t('Background color'), - '#description' => t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'), + '#title' => $this->t('Background color'), + '#description' => $this->t('The background color to use for exposed areas of the image. Use web-style hex colors (#FFFFFF for white, #000000 for black). Leave blank for transparency on image types that support it.'), '#size' => 7, '#maxlength' => 7, ]; $form['random'] = [ '#type' => 'checkbox', '#default_value' => $this->configuration['random'], - '#title' => t('Randomize'), - '#description' => t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), + '#title' => $this->t('Randomize'), + '#description' => $this->t('Randomize the rotation angle for each image. The angle specified above is used as a maximum.'), ]; return $form; } diff --git a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php index bfb6d942fb9..13e5aaa2d2f 100644 --- a/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php +++ b/core/modules/image/src/Plugin/ImageEffect/ScaleImageEffect.php @@ -69,8 +69,8 @@ class ScaleImageEffect extends ResizeImageEffect { $form['upscale'] = [ '#type' => 'checkbox', '#default_value' => $this->configuration['upscale'], - '#title' => t('Allow Upscaling'), - '#description' => t('Let scale make images larger than their original size.'), + '#title' => $this->t('Allow Upscaling'), + '#description' => $this->t('Let scale make images larger than their original size.'), ]; return $form; } diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldFormatter/DummyAjaxFormatter.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldFormatter/DummyAjaxFormatter.php index cebc54becaa..0952a48dc6d 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldFormatter/DummyAjaxFormatter.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/Field/FieldFormatter/DummyAjaxFormatter.php @@ -24,7 +24,7 @@ class DummyAjaxFormatter extends FormatterBase { */ public function settingsSummary() { $summary = []; - $summary[] = t('Renders nothing'); + $summary[] = $this->t('Renders nothing'); return $summary; } diff --git a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php index a18c2637c08..1a8cfd7eea8 100644 --- a/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php +++ b/core/modules/image/tests/modules/image_module_test/src/Plugin/ImageEffect/AjaxTestImageEffect.php @@ -33,7 +33,7 @@ class AjaxTestImageEffect extends ConfigurableImageEffectBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['test_parameter'] = [ '#type' => 'number', - '#title' => t('Test parameter'), + '#title' => $this->t('Test parameter'), '#default_value' => $this->configuration['test_parameter'], '#min' => 0, ]; diff --git a/core/modules/language/src/Plugin/Condition/Language.php b/core/modules/language/src/Plugin/Condition/Language.php index f727dc7705f..62008496ecf 100644 --- a/core/modules/language/src/Plugin/Condition/Language.php +++ b/core/modules/language/src/Plugin/Condition/Language.php @@ -122,9 +122,9 @@ class Language extends ConditionPluginBase implements ContainerFactoryPluginInte $languages = array_pop($language_names); } if (!empty($this->configuration['negate'])) { - return t('The language is not @languages.', ['@languages' => $languages]); + return $this->t('The language is not @languages.', ['@languages' => $languages]); } - return t('The language is @languages.', ['@languages' => $languages]); + return $this->t('The language is @languages.', ['@languages' => $languages]); } /** diff --git a/core/modules/language/src/Plugin/Derivative/LanguageBlock.php b/core/modules/language/src/Plugin/Derivative/LanguageBlock.php index 93cc5b1c98e..54f0c1745f1 100644 --- a/core/modules/language/src/Plugin/Derivative/LanguageBlock.php +++ b/core/modules/language/src/Plugin/Derivative/LanguageBlock.php @@ -3,6 +3,7 @@ namespace Drupal\language\Plugin\Derivative; use Drupal\Component\Plugin\Derivative\DeriverBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\ConfigurableLanguageManagerInterface; /** @@ -10,6 +11,8 @@ use Drupal\language\ConfigurableLanguageManagerInterface; */ class LanguageBlock extends DeriverBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -21,12 +24,12 @@ class LanguageBlock extends DeriverBase { $configurable_types = $language_manager->getLanguageTypes(); foreach ($configurable_types as $type) { $this->derivatives[$type] = $base_plugin_definition; - $this->derivatives[$type]['admin_label'] = t('Language switcher (@type)', ['@type' => $info[$type]['name']]); + $this->derivatives[$type]['admin_label'] = $this->t('Language switcher (@type)', ['@type' => $info[$type]['name']]); } // If there is just one configurable type then change the title of the // block. if (count($configurable_types) == 1) { - $this->derivatives[reset($configurable_types)]['admin_label'] = t('Language switcher'); + $this->derivatives[reset($configurable_types)]['admin_label'] = $this->t('Language switcher'); } } diff --git a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php index e69b19c0c21..75a46fa4aa3 100644 --- a/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php +++ b/core/modules/link/src/Plugin/Field/FieldFormatter/LinkFormatter.php @@ -94,21 +94,21 @@ class LinkFormatter extends FormatterBase { $elements['trim_length'] = [ '#type' => 'number', - '#title' => t('Trim link text length'), - '#field_suffix' => t('characters'), + '#title' => $this->t('Trim link text length'), + '#field_suffix' => $this->t('characters'), '#default_value' => $this->getSetting('trim_length'), '#min' => 1, - '#description' => t('Leave blank to allow unlimited link text lengths.'), + '#description' => $this->t('Leave blank to allow unlimited link text lengths.'), ]; $elements['url_only'] = [ '#type' => 'checkbox', - '#title' => t('URL only'), + '#title' => $this->t('URL only'), '#default_value' => $this->getSetting('url_only'), '#access' => $this->getPluginId() == 'link', ]; $elements['url_plain'] = [ '#type' => 'checkbox', - '#title' => t('Show URL as plain text'), + '#title' => $this->t('Show URL as plain text'), '#default_value' => $this->getSetting('url_plain'), '#access' => $this->getPluginId() == 'link', '#states' => [ @@ -119,13 +119,13 @@ class LinkFormatter extends FormatterBase { ]; $elements['rel'] = [ '#type' => 'checkbox', - '#title' => t('Add rel="nofollow" to links'), + '#title' => $this->t('Add rel="nofollow" to links'), '#return_value' => 'nofollow', '#default_value' => $this->getSetting('rel'), ]; $elements['target'] = [ '#type' => 'checkbox', - '#title' => t('Open link in new window'), + '#title' => $this->t('Open link in new window'), '#return_value' => '_blank', '#default_value' => $this->getSetting('target'), ]; @@ -142,24 +142,24 @@ class LinkFormatter extends FormatterBase { $settings = $this->getSettings(); if (!empty($settings['trim_length'])) { - $summary[] = t('Link text trimmed to @limit characters', ['@limit' => $settings['trim_length']]); + $summary[] = $this->t('Link text trimmed to @limit characters', ['@limit' => $settings['trim_length']]); } else { - $summary[] = t('Link text not trimmed'); + $summary[] = $this->t('Link text not trimmed'); } if ($this->getPluginId() == 'link' && !empty($settings['url_only'])) { if (!empty($settings['url_plain'])) { - $summary[] = t('Show URL only as plain-text'); + $summary[] = $this->t('Show URL only as plain-text'); } else { - $summary[] = t('Show URL only'); + $summary[] = $this->t('Show URL only'); } } if (!empty($settings['rel'])) { - $summary[] = t('Add rel="@rel"', ['@rel' => $settings['rel']]); + $summary[] = $this->t('Add rel="@rel"', ['@rel' => $settings['rel']]); } if (!empty($settings['target'])) { - $summary[] = t('Open link in new window'); + $summary[] = $this->t('Open link in new window'); } return $summary; diff --git a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php index 84556f8be09..9154eee1cd8 100644 --- a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\MapDataDefinition; use Drupal\Core\Url; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\link\LinkItemInterface; /** @@ -41,13 +42,13 @@ class LinkItem extends FieldItemBase implements LinkItemInterface { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['uri'] = DataDefinition::create('uri') - ->setLabel(t('URI')); + ->setLabel(new TranslatableMarkup('URI')); $properties['title'] = DataDefinition::create('string') - ->setLabel(t('Link text')); + ->setLabel(new TranslatableMarkup('Link text')); $properties['options'] = MapDataDefinition::create() - ->setLabel(t('Options')); + ->setLabel(new TranslatableMarkup('Options')); return $properties; } @@ -89,23 +90,23 @@ class LinkItem extends FieldItemBase implements LinkItemInterface { $element['link_type'] = [ '#type' => 'radios', - '#title' => t('Allowed link type'), + '#title' => $this->t('Allowed link type'), '#default_value' => $this->getSetting('link_type'), '#options' => [ - static::LINK_INTERNAL => t('Internal links only'), - static::LINK_EXTERNAL => t('External links only'), - static::LINK_GENERIC => t('Both internal and external links'), + static::LINK_INTERNAL => $this->t('Internal links only'), + static::LINK_EXTERNAL => $this->t('External links only'), + static::LINK_GENERIC => $this->t('Both internal and external links'), ], ]; $element['title'] = [ '#type' => 'radios', - '#title' => t('Allow link text'), + '#title' => $this->t('Allow link text'), '#default_value' => $this->getSetting('title'), '#options' => [ - DRUPAL_DISABLED => t('Disabled'), - DRUPAL_OPTIONAL => t('Optional'), - DRUPAL_REQUIRED => t('Required'), + DRUPAL_DISABLED => $this->t('Disabled'), + DRUPAL_OPTIONAL => $this->t('Optional'), + DRUPAL_REQUIRED => $this->t('Required'), ], ]; diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 3d6d80f622b..031f89bebad 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -2,6 +2,7 @@ namespace Drupal\link\Plugin\Field\FieldWidget; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\Core\Entity\Element\EntityAutocomplete; use Drupal\Core\Field\FieldItemListInterface; @@ -71,7 +72,7 @@ class LinkWidget extends WidgetBase { $displayable_string = $uri_reference; } elseif ($scheme === 'entity') { - [$entity_type, $entity_id] = explode('/', substr($uri, 7), 2); + list($entity_type, $entity_id) = explode('/', substr($uri, 7), 2); // Show the 'entity:' URI as the entity autocomplete would. // @todo Support entity types other than 'node'. Will be fixed in // https://www.drupal.org/node/2423093. @@ -147,7 +148,7 @@ class LinkWidget extends WidgetBase { // @todo '' is valid input for BC reasons, may be removed by // https://www.drupal.org/node/2421941 if (parse_url($uri, PHP_URL_SCHEME) === 'internal' && !in_array($element['#value'][0], ['/', '?', '#'], TRUE) && substr($element['#value'], 0, 7) !== '') { - $form_state->setError($element, t('Manually entered paths should start with one of the following characters: / ? #')); + $form_state->setError($element, new TranslatableMarkup('Manually entered paths should start with one of the following characters: / ? #')); return; } } @@ -159,9 +160,9 @@ class LinkWidget extends WidgetBase { */ public static function validateTitleElement(&$element, FormStateInterface $form_state, $form) { if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') { - // We expect the field name placeholder value to be wrapped in t() here, + // We expect the field name placeholder value to be wrapped in $this->t() here, // so it won't be escaped again as it's already marked safe. - $form_state->setError($element['title'], t('@title field is required if there is @uri input.', ['@title' => $element['title']['#title'], '@uri' => $element['uri']['#title']])); + $form_state->setError($element['title'], new TranslatableMarkup('@title field is required if there is @uri input.', ['@title' => $element['title']['#title'], '@uri' => $element['uri']['#title']])); } } @@ -172,7 +173,7 @@ class LinkWidget extends WidgetBase { */ public static function validateTitleNoLink(&$element, FormStateInterface $form_state, $form) { if ($element['uri']['#value'] === '' && $element['title']['#value'] !== '') { - $form_state->setError($element['uri'], t('The @uri field is required when the @title field is specified.', ['@title' => $element['title']['#title'], '@uri' => $element['uri']['#title']])); + $form_state->setError($element['uri'], new TranslatableMarkup('The @uri field is required when the @title field is specified.', ['@title' => $element['title']['#title'], '@uri' => $element['uri']['#title']])); } } diff --git a/core/modules/media/src/Plugin/media/Source/OEmbed.php b/core/modules/media/src/Plugin/media/Source/OEmbed.php index 825141814a6..c589c87fcb0 100644 --- a/core/modules/media/src/Plugin/media/Source/OEmbed.php +++ b/core/modules/media/src/Plugin/media/Source/OEmbed.php @@ -49,8 +49,8 @@ use Symfony\Component\Mime\MimeTypes; * function example_media_source_info_alter(array &$sources) { * $sources['artwork'] = [ * 'id' => 'artwork', - * 'label' => t('Artwork'), - * 'description' => t('Use artwork from Flickr and DeviantArt.'), + * 'label' => $this->t('Artwork'), + * 'description' => $this->t('Use artwork from Flickr and DeviantArt.'), * 'allowed_field_types' => ['string'], * 'default_thumbnail_filename' => 'no-thumbnail.png', * 'providers' => ['Deviantart.com', 'Flickr'], diff --git a/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php b/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php index 8da3265f5b7..bdbc5355617 100644 --- a/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php +++ b/core/modules/media/src/Plugin/media/Source/OEmbedDeriver.php @@ -3,6 +3,7 @@ namespace Drupal\media\Plugin\media\Source; use Drupal\Component\Plugin\Derivative\DeriverBase; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Derives media source plugin definitions for supported oEmbed providers. @@ -13,6 +14,8 @@ use Drupal\Component\Plugin\Derivative\DeriverBase; */ class OEmbedDeriver extends DeriverBase { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -20,8 +23,8 @@ class OEmbedDeriver extends DeriverBase { $this->derivatives = [ 'video' => [ 'id' => 'video', - 'label' => t('Remote video'), - 'description' => t('Use remote video URL for reusable media.'), + 'label' => $this->t('Remote video'), + 'description' => $this->t('Use remote video URL for reusable media.'), 'providers' => ['YouTube', 'Vimeo'], 'default_thumbnail_filename' => 'video.png', ] + $base_plugin_definition, diff --git a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php index 39a10229e04..1766346a7d4 100644 --- a/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php +++ b/core/modules/media_library/src/Plugin/Field/FieldWidget/MediaLibraryWidget.php @@ -18,6 +18,7 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Security\TrustedCallbackInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\field_ui\FieldUI; use Drupal\media\Entity\Media; @@ -205,7 +206,7 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface 'label' => ['#markup' => $label], 'weight' => [ '#type' => 'weight', - '#title' => t('Weight for @title', ['@title' => $label]), + '#title' => $this->t('Weight for @title', ['@title' => $label]), '#title_display' => 'invisible', '#default_value' => $weight, '#attributes' => ['class' => ['weight']], @@ -267,7 +268,7 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface foreach ($media_types as $media_type) { $media_type_labels[] = $media_type->label(); } - $summary[] = t('Tab order: @order', ['@order' => implode(', ', $media_type_labels)]); + $summary[] = $this->t('Tab order: @order', ['@order' => implode(', ', $media_type_labels)]); } return $summary; } @@ -697,7 +698,7 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface // Announce the updated content to screen readers. if ($is_remove_button) { - $announcement = t('@label has been removed.', [ + $announcement = new TranslatableMarkup('@label has been removed.', [ '@label' => Media::load($field_state['removed_item_id'])->label(), ]); } @@ -849,7 +850,7 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface }, $element['#target_bundles']); foreach ($media as $media_item) { if ($element['#target_bundles'] && !in_array($media_item->bundle(), $element['#target_bundles'], TRUE)) { - $form_state->setError($element, t('The media item "@label" is not of an accepted type. Allowed types: @types', [ + $form_state->setError($element, new TranslatableMarkup('The media item "@label" is not of an accepted type. Allowed types: @types', [ '@label' => $media_item->label(), '@types' => implode(', ', $bundle_labels), ])); @@ -998,7 +999,7 @@ class MediaLibraryWidget extends WidgetBase implements TrustedCallbackInterface // the Form API's default validation would also catch this, the validation // error message is too vague, so a more precise one is provided here. if (count($field_state['items']) === 0) { - $form_state->setError($element, t('@name field is required.', ['@name' => $element['#title']])); + $form_state->setError($element, new TranslatableMarkup('@name field is required.', ['@name' => $element['#title']])); } } diff --git a/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php b/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php index f4309c131ca..b998b6eb1e8 100644 --- a/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php +++ b/core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php @@ -73,31 +73,31 @@ class MenuLink extends DrupalSqlBase { */ public function fields() { $fields = [ - 'menu_name' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."), - 'mlid' => t('The menu link ID (mlid) is the integer primary key.'), - 'plid' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'), - 'link_path' => t('The Drupal path or external path this link points to.'), - 'router_path' => t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'), - 'link_title' => t('The text displayed for the link, which may be modified by a title callback stored in {menu_router}.'), - 'options' => t('A serialized array of options to set on the URL, such as a query string or HTML attributes.'), - 'module' => t('The name of the module that generated this link.'), - 'hidden' => t('A flag for whether the link should be rendered in menus. (1 = a disabled menu link that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)'), - 'external' => t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'), - 'has_children' => t('Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).'), - 'expanded' => t('Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)'), - 'weight' => t('Link weight among links in the same menu at the same depth.'), - 'depth' => t('The depth relative to the top level. A link with plid == 0 will have depth == 1.'), - 'customized' => t('A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).'), - 'p1' => t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'), - 'p2' => t('The second mlid in the materialized path. See p1.'), - 'p3' => t('The third mlid in the materialized path. See p1.'), - 'p4' => t('The fourth mlid in the materialized path. See p1.'), - 'p5' => t('The fifth mlid in the materialized path. See p1.'), - 'p6' => t('The sixth mlid in the materialized path. See p1.'), - 'p7' => t('The seventh mlid in the materialized path. See p1.'), - 'p8' => t('The eighth mlid in the materialized path. See p1.'), - 'p9' => t('The ninth mlid in the materialized path. See p1.'), - 'updated' => t('Flag that indicates that this link was generated during the update from Drupal 5.'), + 'menu_name' => $this->t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."), + 'mlid' => $this->t('The menu link ID (mlid) is the integer primary key.'), + 'plid' => $this->t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'), + 'link_path' => $this->t('The Drupal path or external path this link points to.'), + 'router_path' => $this->t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'), + 'link_title' => $this->t('The text displayed for the link, which may be modified by a title callback stored in {menu_router}.'), + 'options' => $this->t('A serialized array of options to set on the URL, such as a query string or HTML attributes.'), + 'module' => $this->t('The name of the module that generated this link.'), + 'hidden' => $this->t('A flag for whether the link should be rendered in menus. (1 = a disabled menu link that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)'), + 'external' => $this->t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'), + 'has_children' => $this->t('Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).'), + 'expanded' => $this->t('Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)'), + 'weight' => $this->t('Link weight among links in the same menu at the same depth.'), + 'depth' => $this->t('The depth relative to the top level. A link with plid == 0 will have depth == 1.'), + 'customized' => $this->t('A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).'), + 'p1' => $this->t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'), + 'p2' => $this->t('The second mlid in the materialized path. See p1.'), + 'p3' => $this->t('The third mlid in the materialized path. See p1.'), + 'p4' => $this->t('The fourth mlid in the materialized path. See p1.'), + 'p5' => $this->t('The fifth mlid in the materialized path. See p1.'), + 'p6' => $this->t('The sixth mlid in the materialized path. See p1.'), + 'p7' => $this->t('The seventh mlid in the materialized path. See p1.'), + 'p8' => $this->t('The eighth mlid in the materialized path. See p1.'), + 'p9' => $this->t('The ninth mlid in the materialized path. See p1.'), + 'updated' => $this->t('Flag that indicates that this link was generated during the update from Drupal 5.'), ]; $schema = $this->getDatabase()->schema(); if ($schema->fieldExists('menu_links', 'language')) { diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php index d0f31ffa0b4..c419fa88428 100644 --- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php @@ -678,7 +678,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP $fields['destid' . ++$count] = $dest_id; } if ($count && $count != count($this->destinationIdFields())) { - $this->message->display(t('Could not save to map table due to missing destination id values'), 'error'); + $this->message->display($this->t('Could not save to map table due to missing destination id values'), 'error'); return; } if ($this->migration->getTrackLastImported()) { diff --git a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php b/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php index 123eb9c4cbe..2991aeec7a2 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php +++ b/core/modules/migrate/src/Plugin/migrate/source/EmptySource.php @@ -34,7 +34,7 @@ class EmptySource extends SourcePluginBase { */ public function fields() { return [ - 'id' => t('ID'), + 'id' => $this->t('ID'), ]; } diff --git a/core/modules/migrate/tests/modules/migrate_sql_count_cache_test/src/Plugin/migrate/source/SqlCountCache.php b/core/modules/migrate/tests/modules/migrate_sql_count_cache_test/src/Plugin/migrate/source/SqlCountCache.php index 48026d10a64..5d01930706a 100644 --- a/core/modules/migrate/tests/modules/migrate_sql_count_cache_test/src/Plugin/migrate/source/SqlCountCache.php +++ b/core/modules/migrate/tests/modules/migrate_sql_count_cache_test/src/Plugin/migrate/source/SqlCountCache.php @@ -18,7 +18,7 @@ class SqlCountCache extends SqlBase { */ public function fields() { return [ - 'id' => t('Id'), + 'id' => $this->t('Id'), ]; } diff --git a/core/modules/node/src/Plugin/Action/AssignOwnerNode.php b/core/modules/node/src/Plugin/Action/AssignOwnerNode.php index ae9a7402b6b..287dcb01898 100644 --- a/core/modules/node/src/Plugin/Action/AssignOwnerNode.php +++ b/core/modules/node/src/Plugin/Action/AssignOwnerNode.php @@ -76,7 +76,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $description = t('The username of the user to which you would like to assign ownership.'); + $description = $this->t('The username of the user to which you would like to assign ownership.'); $count = $this->connection->query("SELECT COUNT(*) FROM {users}")->fetchField(); // Use dropdown for fewer than 200 users; textbox for more than that. @@ -88,7 +88,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory } $form['owner_uid'] = [ '#type' => 'select', - '#title' => t('Username'), + '#title' => $this->t('Username'), '#default_value' => $this->configuration['owner_uid'], '#options' => $options, '#description' => $description, @@ -97,7 +97,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory else { $form['owner_uid'] = [ '#type' => 'entity_autocomplete', - '#title' => t('Username'), + '#title' => $this->t('Username'), '#target_type' => 'user', '#selection_settings' => [ 'include_anonymous' => FALSE, @@ -119,7 +119,7 @@ class AssignOwnerNode extends ConfigurableActionBase implements ContainerFactory public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { $exists = (bool) $this->connection->queryRange('SELECT 1 FROM {users_field_data} WHERE [uid] = :uid AND [default_langcode] = 1', 0, 1, [':uid' => $form_state->getValue('owner_uid')])->fetchField(); if (!$exists) { - $form_state->setErrorByName('owner_uid', t('Enter a valid username.')); + $form_state->setErrorByName('owner_uid', $this->t('Enter a valid username.')); } } diff --git a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php index 94abf8b6342..42f344d52ca 100644 --- a/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php +++ b/core/modules/node/src/Plugin/Action/UnpublishByKeywordNode.php @@ -49,9 +49,9 @@ class UnpublishByKeywordNode extends ConfigurableActionBase { */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['keywords'] = [ - '#title' => t('Keywords'), + '#title' => $this->t('Keywords'), '#type' => 'textarea', - '#description' => t('The content will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, "Company, Inc."'), + '#description' => $this->t('The content will be unpublished if it contains any of the phrases above. Use a case-sensitive, comma-separated list of phrases. Example: funny, bungee jumping, "Company, Inc."'), '#default_value' => Tags::implode($this->configuration['keywords']), ]; return $form; diff --git a/core/modules/node/src/Plugin/Search/NodeSearch.php b/core/modules/node/src/Plugin/Search/NodeSearch.php index 0342c5f01d2..1f6e1665300 100644 --- a/core/modules/node/src/Plugin/Search/NodeSearch.php +++ b/core/modules/node/src/Plugin/Search/NodeSearch.php @@ -584,14 +584,14 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter // Add advanced search keyword-related boxes. $form['advanced'] = [ '#type' => 'details', - '#title' => t('Advanced search'), + '#title' => $this->t('Advanced search'), '#attributes' => ['class' => ['search-advanced']], '#access' => $this->account && $this->account->hasPermission('use advanced search'), '#open' => $used_advanced, ]; $form['advanced']['keywords-fieldset'] = [ '#type' => 'fieldset', - '#title' => t('Keywords'), + '#title' => $this->t('Keywords'), ]; $form['advanced']['keywords'] = [ @@ -601,7 +601,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $form['advanced']['keywords-fieldset']['keywords']['or'] = [ '#type' => 'textfield', - '#title' => t('Containing any of the words'), + '#title' => $this->t('Containing any of the words'), '#size' => 30, '#maxlength' => 255, '#default_value' => $defaults['or'] ?? '', @@ -609,7 +609,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $form['advanced']['keywords-fieldset']['keywords']['phrase'] = [ '#type' => 'textfield', - '#title' => t('Containing the phrase'), + '#title' => $this->t('Containing the phrase'), '#size' => 30, '#maxlength' => 255, '#default_value' => $defaults['phrase'] ?? '', @@ -617,7 +617,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $form['advanced']['keywords-fieldset']['keywords']['negative'] = [ '#type' => 'textfield', - '#title' => t('Containing none of the words'), + '#title' => $this->t('Containing none of the words'), '#size' => 30, '#maxlength' => 255, '#default_value' => $defaults['negative'] ?? '', @@ -627,11 +627,11 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $types = array_map(['\Drupal\Component\Utility\Html', 'escape'], node_type_get_names()); $form['advanced']['types-fieldset'] = [ '#type' => 'fieldset', - '#title' => t('Types'), + '#title' => $this->t('Types'), ]; $form['advanced']['types-fieldset']['type'] = [ '#type' => 'checkboxes', - '#title' => t('Only of the type(s)'), + '#title' => $this->t('Only of the type(s)'), '#prefix' => '
', '#suffix' => '
', '#options' => $types, @@ -640,7 +640,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $form['advanced']['submit'] = [ '#type' => 'submit', - '#value' => t('Advanced search'), + '#value' => $this->t('Advanced search'), '#prefix' => '
', '#suffix' => '
', '#weight' => 100, @@ -651,16 +651,16 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter $language_list = $this->languageManager->getLanguages(LanguageInterface::STATE_ALL); foreach ($language_list as $langcode => $language) { // Make locked languages appear special in the list. - $language_options[$langcode] = $language->isLocked() ? t('- @name -', ['@name' => $language->getName()]) : $language->getName(); + $language_options[$langcode] = $language->isLocked() ? $this->t('- @name -', ['@name' => $language->getName()]) : $language->getName(); } if (count($language_options) > 1) { $form['advanced']['lang-fieldset'] = [ '#type' => 'fieldset', - '#title' => t('Languages'), + '#title' => $this->t('Languages'), ]; $form['advanced']['lang-fieldset']['language'] = [ '#type' => 'checkboxes', - '#title' => t('Languages'), + '#title' => $this->t('Languages'), '#prefix' => '
', '#suffix' => '
', '#options' => $language_options, @@ -823,7 +823,7 @@ class NodeSearch extends ConfigurableSearchPluginBase implements AccessibleInter // Output form for defining rank factor weights. $form['content_ranking'] = [ '#type' => 'details', - '#title' => t('Content ranking'), + '#title' => $this->t('Content ranking'), '#open' => TRUE, ]; $form['content_ranking']['info'] = [ diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php index a8fa1d0bbe1..b5fdc54a90f 100644 --- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php @@ -5,6 +5,7 @@ namespace Drupal\node\Plugin\migrate; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\FieldDiscoveryInterface; @@ -15,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { use MigrationDeriverTrait; + use StringTranslationTrait; /** * The base plugin ID this derivative is for. @@ -89,7 +91,7 @@ class D6NodeDeriver extends DeriverBase implements ContainerDeriverInterface { $node_type = $row->getSourceProperty('type'); $values = $base_plugin_definition; - $values['label'] = t("@label (@type)", [ + $values['label'] = $this->t("@label (@type)", [ '@label' => $values['label'], '@type' => $node_type, ]); diff --git a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php index 380aab81e4e..59b071413c6 100644 --- a/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D7NodeDeriver.php @@ -5,6 +5,7 @@ namespace Drupal\node\Plugin\migrate; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\FieldDiscoveryInterface; @@ -15,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface { use MigrationDeriverTrait; + use StringTranslationTrait; /** * The base plugin ID this derivative is for. @@ -89,7 +91,7 @@ class D7NodeDeriver extends DeriverBase implements ContainerDeriverInterface { $node_type = $row->getSourceProperty('type'); $values = $base_plugin_definition; - $values['label'] = t('@label (@type)', [ + $values['label'] = $this->t('@label (@type)', [ '@label' => $values['label'], '@type' => $row->getSourceProperty('name'), ]); diff --git a/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php b/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php index a3420165e01..810c157b5c4 100644 --- a/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php +++ b/core/modules/node/src/Plugin/migrate/source/d6/NodeRevision.php @@ -30,7 +30,7 @@ class NodeRevision extends Node { public function fields() { // Use all the node fields plus the vid that identifies the version. return parent::fields() + [ - 'vid' => t('The primary identifier for this version.'), + 'vid' => $this->t('The primary identifier for this version.'), 'log' => $this->t('Revision Log message'), 'timestamp' => $this->t('Revision timestamp'), ]; diff --git a/core/modules/node/src/Plugin/migrate/source/d7/NodeRevision.php b/core/modules/node/src/Plugin/migrate/source/d7/NodeRevision.php index 1b13b7bbf88..5be6ac3b3e2 100644 --- a/core/modules/node/src/Plugin/migrate/source/d7/NodeRevision.php +++ b/core/modules/node/src/Plugin/migrate/source/d7/NodeRevision.php @@ -28,7 +28,7 @@ class NodeRevision extends Node { public function fields() { // Use all the node fields plus the vid that identifies the version. return parent::fields() + [ - 'vid' => t('The primary identifier for this version.'), + 'vid' => $this->t('The primary identifier for this version.'), 'log' => $this->t('Revision Log message'), 'timestamp' => $this->t('Revision timestamp'), ]; diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php index 855d5b46c34..a09152d509e 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListFloatItem.php @@ -4,6 +4,7 @@ namespace Drupal\options\Plugin\Field\FieldType; use Drupal\Core\Field\FieldFilteredMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; /** @@ -25,7 +26,7 @@ class ListFloatItem extends ListItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('float') - ->setLabel(t('Float value')) + ->setLabel(new TranslatableMarkup('Float value')) ->setRequired(TRUE); return $properties; @@ -51,12 +52,12 @@ class ListFloatItem extends ListItemBase { * {@inheritdoc} */ protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); - $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); + $description = '

' . $this->t('The possible values this field can contain. Enter one value per line, in the format key|label.'); + $description .= '
' . $this->t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); + $description .= '
' . $this->t('The label is optional: if a line contains a single number, it will be used as key and label.'); + $description .= '
' . $this->t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; + $description .= '

' . $this->t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; return $description; } @@ -83,7 +84,7 @@ class ListFloatItem extends ListItemBase { */ protected static function validateAllowedValue($option) { if (!is_numeric($option)) { - return t('Allowed values list: each key must be a valid integer or decimal.'); + return new TranslatableMarkup('Allowed values list: each key must be a valid integer or decimal.'); } } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php index 8a960075190..eabec6f0222 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListIntegerItem.php @@ -4,6 +4,7 @@ namespace Drupal\options\Plugin\Field\FieldType; use Drupal\Core\Field\FieldFilteredMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; /** @@ -25,7 +26,7 @@ class ListIntegerItem extends ListItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('integer') - ->setLabel(t('Integer value')) + ->setLabel(new TranslatableMarkup('Integer value')) ->setRequired(TRUE); return $properties; @@ -51,12 +52,12 @@ class ListIntegerItem extends ListItemBase { * {@inheritdoc} */ protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single number, it will be used as key and label.'); - $description .= '
' . t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); + $description = '

' . $this->t('The possible values this field can contain. Enter one value per line, in the format key|label.'); + $description .= '
' . $this->t('The key is the stored value, and must be numeric. The label will be used in displayed values and edit forms.'); + $description .= '
' . $this->t('The label is optional: if a line contains a single number, it will be used as key and label.'); + $description .= '
' . $this->t('Lists of labels are also accepted (one label per line), only if the field does not hold any values yet. Numeric keys will be automatically generated from the positions in the list.'); $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; + $description .= '

' . $this->t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; return $description; } @@ -65,7 +66,7 @@ class ListIntegerItem extends ListItemBase { */ protected static function validateAllowedValue($option) { if (!preg_match('/^-?\d+$/', $option)) { - return t('Allowed values list: keys must be integers.'); + return new TranslatableMarkup('Allowed values list: keys must be integers.'); } } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php index 7c367589409..62c32aa513a 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListItemBase.php @@ -7,6 +7,7 @@ use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\OptGroup; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\OptionsProviderInterface; /** @@ -84,7 +85,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte $element['allowed_values'] = [ '#type' => 'textarea', - '#title' => t('Allowed values list'), + '#title' => $this->t('Allowed values list'), '#default_value' => $this->allowedValuesString($allowed_values), '#rows' => 10, '#access' => empty($allowed_values_function), @@ -99,8 +100,8 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte $element['allowed_values_function'] = [ '#type' => 'item', - '#title' => t('Allowed values list'), - '#markup' => t('The value of this field is being determined by the %function function and may not be changed.', ['%function' => $allowed_values_function]), + '#title' => $this->t('Allowed values list'), + '#markup' => $this->t('The value of this field is being determined by the %function function and may not be changed.', ['%function' => $allowed_values_function]), '#access' => !empty($allowed_values_function), '#value' => $allowed_values_function, ]; @@ -131,7 +132,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte $values = static::extractAllowedValues($element['#value'], $element['#field_has_data']); if (!is_array($values)) { - $form_state->setError($element, t('Allowed values list: invalid input.')); + $form_state->setError($element, new TranslatableMarkup('Allowed values list: invalid input.')); } else { // Check that keys are valid for the field type. @@ -146,7 +147,7 @@ abstract class ListItemBase extends FieldItemBase implements OptionsProviderInte if ($element['#field_has_data']) { $lost_keys = array_keys(array_diff_key($element['#allowed_values'], $values)); if (_options_values_in_use($element['#entity_type'], $element['#field_name'], $lost_keys)) { - $form_state->setError($element, t('Allowed values list: some values are being removed while currently in use.')); + $form_state->setError($element, new TranslatableMarkup('Allowed values list: some values are being removed while currently in use.')); } } diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php index 55503076432..acd86c0fa20 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php @@ -4,6 +4,7 @@ namespace Drupal\options\Plugin\Field\FieldType; use Drupal\Core\Field\FieldFilteredMarkup; use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\TypedData\DataDefinition; /** @@ -25,7 +26,7 @@ class ListStringItem extends ListItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Text value')) + ->setLabel(new TranslatableMarkup('Text value')) ->addConstraint('Length', ['max' => 255]) ->setRequired(TRUE); @@ -53,11 +54,11 @@ class ListStringItem extends ListItemBase { * {@inheritdoc} */ protected function allowedValuesDescription() { - $description = '

' . t('The possible values this field can contain. Enter one value per line, in the format key|label.'); - $description .= '
' . t('The key is the stored value. The label will be used in displayed values and edit forms.'); - $description .= '
' . t('The label is optional: if a line contains a single string, it will be used as key and label.'); + $description = '

' . $this->t('The possible values this field can contain. Enter one value per line, in the format key|label.'); + $description .= '
' . $this->t('The key is the stored value. The label will be used in displayed values and edit forms.'); + $description .= '
' . $this->t('The label is optional: if a line contains a single string, it will be used as key and label.'); $description .= '

'; - $description .= '

' . t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; + $description .= '

' . $this->t('Allowed HTML tags in labels: @tags', ['@tags' => FieldFilteredMarkup::displayAllowedTags()]) . '

'; return $description; } @@ -66,7 +67,7 @@ class ListStringItem extends ListItemBase { */ protected static function validateAllowedValue($option) { if (mb_strlen($option) > 255) { - return t('Allowed values list: each key must be a string at most 255 characters long.'); + return new TranslatableMarkup('Allowed values list: each key must be a string at most 255 characters long.'); } } diff --git a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php index 20d3aa8f518..088ef784e21 100644 --- a/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php +++ b/core/modules/path/src/Plugin/Field/FieldWidget/PathWidget.php @@ -56,7 +56,7 @@ class PathWidget extends WidgetBase { if (isset($form['advanced'])) { $element += [ '#type' => 'details', - '#title' => t('URL path settings'), + '#title' => $this->t('URL path settings'), '#open' => !empty($items[$delta]->alias), '#group' => 'advanced', '#access' => $entity->get('path')->access('edit'), diff --git a/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php index da0f53f3b94..4c625da4fcc 100644 --- a/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php +++ b/core/modules/responsive_image/src/Plugin/Field/FieldFormatter/ResponsiveImageFormatter.php @@ -134,7 +134,7 @@ class ResponsiveImageFormatter extends ImageFormatterBase { } $elements['responsive_image_style'] = [ - '#title' => t('Responsive image style'), + '#title' => $this->t('Responsive image style'), '#type' => 'select', '#default_value' => $this->getSetting('responsive_image_style') ?: NULL, '#required' => TRUE, @@ -146,14 +146,14 @@ class ResponsiveImageFormatter extends ImageFormatterBase { ]; $link_types = [ - 'content' => t('Content'), - 'file' => t('File'), + 'content' => $this->t('Content'), + 'file' => $this->t('File'), ]; $elements['image_link'] = [ - '#title' => t('Link image to'), + '#title' => $this->t('Link image to'), '#type' => 'select', '#default_value' => $this->getSetting('image_link'), - '#empty_option' => t('Nothing'), + '#empty_option' => $this->t('Nothing'), '#options' => $link_types, ]; @@ -168,11 +168,11 @@ class ResponsiveImageFormatter extends ImageFormatterBase { $responsive_image_style = $this->responsiveImageStyleStorage->load($this->getSetting('responsive_image_style')); if ($responsive_image_style) { - $summary[] = t('Responsive image style: @responsive_image_style', ['@responsive_image_style' => $responsive_image_style->label()]); + $summary[] = $this->t('Responsive image style: @responsive_image_style', ['@responsive_image_style' => $responsive_image_style->label()]); $link_types = [ - 'content' => t('Linked to content'), - 'file' => t('Linked to file'), + 'content' => $this->t('Linked to content'), + 'file' => $this->t('Linked to file'), ]; // Display this setting only if image is linked. if (isset($link_types[$this->getSetting('image_link')])) { @@ -180,7 +180,7 @@ class ResponsiveImageFormatter extends ImageFormatterBase { } } else { - $summary[] = t('Select a responsive image style.'); + $summary[] = $this->t('Select a responsive image style.'); } return $summary; diff --git a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php index 2ae2682ba7d..6037653f750 100644 --- a/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php +++ b/core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php @@ -91,16 +91,16 @@ class SearchExtraTypeSearch extends ConfigurableSearchPluginBase { // Output form for defining rank factor weights. $form['extra_type_settings'] = [ '#type' => 'fieldset', - '#title' => t('Extra type settings'), + '#title' => $this->t('Extra type settings'), '#tree' => TRUE, ]; $form['extra_type_settings']['boost'] = [ '#type' => 'select', - '#title' => t('Boost method'), + '#title' => $this->t('Boost method'), '#options' => [ - 'bi' => t('Bistro mathematics'), - 'ii' => t('Infinite Improbability'), + 'bi' => $this->t('Bistro mathematics'), + 'ii' => $this->t('Infinite Improbability'), ], '#default_value' => $this->configuration['boost'], ]; diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 076540c4b46..259210d514b 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -149,12 +149,12 @@ class GDToolkit extends ImageToolkitBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form['image_jpeg_quality'] = [ '#type' => 'number', - '#title' => t('JPEG quality'), - '#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'), + '#title' => $this->t('JPEG quality'), + '#description' => $this->t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'), '#min' => 0, '#max' => 100, '#default_value' => $this->configFactory->getEditable('system.image.gd')->get('jpeg_quality', FALSE), - '#field_suffix' => t('%'), + '#field_suffix' => $this->t('%'), ]; return $form; } @@ -376,14 +376,14 @@ class GDToolkit extends ImageToolkitBase { $info = gd_info(); $requirements['version'] = [ - 'title' => t('GD library'), + 'title' => $this->t('GD library'), 'value' => $info['GD Version'], ]; // Check for filter and rotate support. if (!function_exists('imagefilter') || !function_exists('imagerotate')) { $requirements['version']['severity'] = REQUIREMENT_WARNING; - $requirements['version']['description'] = t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See the PHP manual.'); + $requirements['version']['description'] = $this->t('The GD Library for PHP is enabled, but was compiled without support for functions used by the rotate and desaturate effects. It was probably compiled using the official GD libraries from http://www.libgd.org instead of the GD library bundled with PHP. You should recompile PHP --with-gd using the bundled GD library. See the PHP manual.'); } return $requirements; 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 da2dc46240c..1549978b423 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 @@ -32,8 +32,6 @@ class FieldTestItem extends FieldItemBase { * {@inheritdoc} */ 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 TranslatableMarkup. $properties['value'] = DataDefinition::create('string') ->setLabel(new TranslatableMarkup('Test value')) ->setRequired(TRUE); 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 766aa7a8d53..d53901f6b2c 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 @@ -8,12 +8,15 @@ use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; use Drupal\Component\Plugin\Factory\ReflectionFactory; use Drupal\Core\Plugin\Context\ContextDefinition; use Drupal\Core\Plugin\Context\EntityContextDefinition; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Defines a plugin manager used by Plugin API derivative unit tests. */ class MockBlockManager extends PluginManagerBase { + use StringTranslationTrait; + public function __construct() { // Create the object that can be used to return definitions for all the @@ -38,7 +41,7 @@ class MockBlockManager extends PluginManagerBase { // A simple plugin: the user login block. $this->discovery->setDefinition('user_login', [ 'id' => 'user_login', - 'label' => t('User login'), + 'label' => $this->t('User login'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserLoginBlock', ]); @@ -56,7 +59,7 @@ class MockBlockManager extends PluginManagerBase { // A plugin defining itself as a derivative. $this->discovery->setDefinition('menu:foo', [ 'id' => 'menu', - 'label' => t('Base label'), + 'label' => $this->t('Base label'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockMenuBlock', ]); @@ -68,7 +71,7 @@ class MockBlockManager extends PluginManagerBase { // derivatives are available to the system. $this->discovery->setDefinition('layout', [ 'id' => 'layout', - 'label' => t('Layout'), + 'label' => $this->t('Layout'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlock', 'deriver' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockLayoutBlockDeriver', ]); @@ -77,38 +80,38 @@ class MockBlockManager extends PluginManagerBase { // user object in order to return the user name from the getTitle() method. $this->discovery->setDefinition('user_name', [ 'id' => 'user_name', - 'label' => t('User name'), + 'label' => $this->t('User name'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock', 'context_definitions' => [ - 'user' => $this->createContextDefinition('entity:user', t('User')), + 'user' => $this->createContextDefinition('entity:user', $this->t('User')), ], ]); // An optional context version of the previous block plugin. $this->discovery->setDefinition('user_name_optional', [ 'id' => 'user_name_optional', - 'label' => t('User name optional'), + 'label' => $this->t('User name optional'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockUserNameBlock', 'context_definitions' => [ - 'user' => $this->createContextDefinition('entity:user', t('User'), FALSE), + 'user' => $this->createContextDefinition('entity:user', $this->t('User'), FALSE), ], ]); // A block plugin that requires a typed data string context to function. $this->discovery->setDefinition('string_context', [ 'id' => 'string_context', - 'label' => t('String typed data'), + 'label' => $this->t('String typed data'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\TypedDataStringBlock', ]); // A complex context plugin that requires both a user and node for context. $this->discovery->setDefinition('complex_context', [ 'id' => 'complex_context', - 'label' => t('Complex context'), + 'label' => $this->t('Complex context'), 'class' => 'Drupal\plugin_test\Plugin\plugin_test\mock_block\MockComplexContextBlock', 'context_definitions' => [ - 'user' => $this->createContextDefinition('entity:user', t('User')), - 'node' => $this->createContextDefinition('entity:node', t('Node')), + 'user' => $this->createContextDefinition('entity:user', $this->t('User')), + 'node' => $this->createContextDefinition('entity:node', $this->t('Node')), ], ]); diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php index 93fca538b88..9f25c046fac 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockLayoutBlockDeriver.php @@ -3,6 +3,7 @@ namespace Drupal\plugin_test\Plugin\plugin_test\mock_block; use Drupal\Component\Plugin\Derivative\DeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Mock implementation of DeriverInterface for the mock layout block plugin. @@ -11,6 +12,8 @@ use Drupal\Component\Plugin\Derivative\DeriverInterface; */ class MockLayoutBlockDeriver implements DeriverInterface { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -41,7 +44,7 @@ class MockLayoutBlockDeriver implements DeriverInterface { // customized one, but in a real implementation, this would be fetched // from some \Drupal::config() object. 'foo' => [ - 'label' => t('Layout Foo'), + 'label' => $this->t('Layout Foo'), ] + $base_plugin_definition, ]; diff --git a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockMenuBlockDeriver.php b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockMenuBlockDeriver.php index 22ef9809a66..254bbdb7133 100644 --- a/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockMenuBlockDeriver.php +++ b/core/modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/mock_block/MockMenuBlockDeriver.php @@ -3,6 +3,7 @@ namespace Drupal\plugin_test\Plugin\plugin_test\mock_block; use Drupal\Component\Plugin\Derivative\DeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Mock implementation of DeriverInterface for the mock menu block plugin. @@ -11,6 +12,8 @@ use Drupal\Component\Plugin\Derivative\DeriverInterface; */ class MockMenuBlockDeriver implements DeriverInterface { + use StringTranslationTrait; + /** * {@inheritdoc} */ @@ -36,14 +39,14 @@ class MockMenuBlockDeriver implements DeriverInterface { // Drupal's configuration to find out which menus actually exist. $derivatives = [ 'main_menu' => [ - 'label' => t('Main menu'), + 'label' => $this->t('Main menu'), ] + $base_plugin_definition, 'navigation' => [ - 'label' => t('Navigation'), + 'label' => $this->t('Navigation'), ] + $base_plugin_definition, 'foo' => [ // Instead of the derivative label, the specific label will be used. - 'label' => t('Derivative label'), + 'label' => $this->t('Derivative label'), // This setting will be merged in. 'setting' => 'default', ] + $base_plugin_definition, diff --git a/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php b/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php index c116f813ede..2306b87f472 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php +++ b/core/modules/taxonomy/src/Plugin/migrate/D7TaxonomyTermDeriver.php @@ -5,6 +5,7 @@ namespace Drupal\taxonomy\Plugin\migrate; use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\MigrationDeriverTrait; use Drupal\migrate_drupal\FieldDiscoveryInterface; @@ -15,6 +16,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInterface { use MigrationDeriverTrait; + use StringTranslationTrait; /** * The base plugin ID this derivative is for. @@ -74,7 +76,7 @@ class D7TaxonomyTermDeriver extends DeriverBase implements ContainerDeriverInter $bundle = $row->getSourceProperty('machine_name'); $values = $base_plugin_definition; - $values['label'] = t('@label (@type)', [ + $values['label'] = $this->t('@label (@type)', [ '@label' => $values['label'], '@type' => $row->getSourceProperty('name'), ]); diff --git a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php index 7758aee4e0d..e9c4c9368d6 100644 --- a/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php +++ b/core/modules/taxonomy/src/Plugin/views/filter/TaxonomyIndexTid.php @@ -280,7 +280,7 @@ class TaxonomyIndexTid extends ManyToOne { $this->helper->buildOptionsForm($form, $form_state); // Show help text if not exposed to end users. - $form['value']['#description'] = t('Leave blank for all. Otherwise, the first selected term will be the default instead of "Any".'); + $form['value']['#description'] = $this->t('Leave blank for all. Otherwise, the first selected term will be the default instead of "Any".'); } } diff --git a/core/modules/telephone/src/Plugin/Field/FieldFormatter/TelephoneLinkFormatter.php b/core/modules/telephone/src/Plugin/Field/FieldFormatter/TelephoneLinkFormatter.php index 60ee25cbc3d..875f47ffa4c 100644 --- a/core/modules/telephone/src/Plugin/Field/FieldFormatter/TelephoneLinkFormatter.php +++ b/core/modules/telephone/src/Plugin/Field/FieldFormatter/TelephoneLinkFormatter.php @@ -35,7 +35,7 @@ class TelephoneLinkFormatter extends FormatterBase { public function settingsForm(array $form, FormStateInterface $form_state) { $elements['title'] = [ '#type' => 'textfield', - '#title' => t('Title to replace basic numeric telephone number display'), + '#title' => $this->t('Title to replace basic numeric telephone number display'), '#default_value' => $this->getSetting('title'), ]; @@ -50,10 +50,10 @@ class TelephoneLinkFormatter extends FormatterBase { $settings = $this->getSettings(); if (!empty($settings['title'])) { - $summary[] = t('Link using text: @title', ['@title' => $settings['title']]); + $summary[] = $this->t('Link using text: @title', ['@title' => $settings['title']]); } else { - $summary[] = t('Link using provided telephone number.'); + $summary[] = $this->t('Link using provided telephone number.'); } return $summary; diff --git a/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php index 17fc9d5e42a..8fea6f93f0c 100644 --- a/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php +++ b/core/modules/telephone/src/Plugin/Field/FieldType/TelephoneItem.php @@ -6,6 +6,7 @@ use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Plugin implementation of the 'telephone' field type. @@ -40,7 +41,7 @@ class TelephoneItem extends FieldItemBase { */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Telephone number')) + ->setLabel(new TranslatableMarkup('Telephone number')) ->setRequired(TRUE); return $properties; @@ -66,7 +67,7 @@ class TelephoneItem extends FieldItemBase { 'value' => [ 'Length' => [ 'max' => $max_length, - 'maxMessage' => t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), + 'maxMessage' => $this->t('%name: the telephone number may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), ], ], ]); diff --git a/core/modules/telephone/src/Plugin/Field/FieldWidget/TelephoneDefaultWidget.php b/core/modules/telephone/src/Plugin/Field/FieldWidget/TelephoneDefaultWidget.php index 99db3c13fe9..8887d06b0a9 100644 --- a/core/modules/telephone/src/Plugin/Field/FieldWidget/TelephoneDefaultWidget.php +++ b/core/modules/telephone/src/Plugin/Field/FieldWidget/TelephoneDefaultWidget.php @@ -34,9 +34,9 @@ class TelephoneDefaultWidget extends WidgetBase { public function settingsForm(array $form, FormStateInterface $form_state) { $element['placeholder'] = [ '#type' => 'textfield', - '#title' => t('Placeholder'), + '#title' => $this->t('Placeholder'), '#default_value' => $this->getSetting('placeholder'), - '#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), + '#description' => $this->t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'), ]; return $element; } @@ -49,10 +49,10 @@ class TelephoneDefaultWidget extends WidgetBase { $placeholder = $this->getSetting('placeholder'); if (!empty($placeholder)) { - $summary[] = t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); + $summary[] = $this->t('Placeholder: @placeholder', ['@placeholder' => $placeholder]); } else { - $summary[] = t('No placeholder'); + $summary[] = $this->t('No placeholder'); } return $summary; diff --git a/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php b/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php index 6f90a56d99e..d961036a915 100644 --- a/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php +++ b/core/modules/text/src/Plugin/Field/FieldFormatter/TextTrimmedFormatter.php @@ -41,11 +41,11 @@ class TextTrimmedFormatter extends FormatterBase implements TrustedCallbackInter */ public function settingsForm(array $form, FormStateInterface $form_state) { $element['trim_length'] = [ - '#title' => t('Trimmed limit'), + '#title' => $this->t('Trimmed limit'), '#type' => 'number', - '#field_suffix' => t('characters'), + '#field_suffix' => $this->t('characters'), '#default_value' => $this->getSetting('trim_length'), - '#description' => t('If the summary is not set, the trimmed %label field will end at the last full sentence before this character limit.', ['%label' => $this->fieldDefinition->getLabel()]), + '#description' => $this->t('If the summary is not set, the trimmed %label field will end at the last full sentence before this character limit.', ['%label' => $this->fieldDefinition->getLabel()]), '#min' => 1, '#required' => TRUE, ]; @@ -57,7 +57,7 @@ class TextTrimmedFormatter extends FormatterBase implements TrustedCallbackInter */ public function settingsSummary() { $summary = []; - $summary[] = t('Trimmed limit: @trim_length characters', ['@trim_length' => $this->getSetting('trim_length')]); + $summary[] = $this->t('Trimmed limit: @trim_length characters', ['@trim_length' => $this->getSetting('trim_length')]); return $summary; } diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php index dcee58346d1..47a23dcf77f 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextItem.php @@ -61,7 +61,7 @@ class TextItem extends TextItemBase { 'value' => [ 'Length' => [ 'max' => $max_length, - 'maxMessage' => t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), + 'maxMessage' => $this->t('%name: the text may not be longer than @max characters.', ['%name' => $this->getFieldDefinition()->getLabel(), '@max' => $max_length]), ], ], ]); @@ -78,10 +78,10 @@ class TextItem extends TextItemBase { $element['max_length'] = [ '#type' => 'number', - '#title' => t('Maximum length'), + '#title' => $this->t('Maximum length'), '#default_value' => $this->getSetting('max_length'), '#required' => TRUE, - '#description' => t('The maximum length of the field in characters.'), + '#description' => $this->t('The maximum length of the field in characters.'), '#min' => 1, '#disabled' => $has_data, ]; diff --git a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php index 9c9a160e239..9437c381fc1 100644 --- a/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php +++ b/core/modules/text/src/Plugin/Field/FieldType/TextWithSummaryItem.php @@ -5,6 +5,7 @@ namespace Drupal\text\Plugin\Field\FieldType; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TypedData\DataDefinition; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Plugin implementation of the 'text_with_summary' field type. @@ -37,11 +38,11 @@ class TextWithSummaryItem extends TextItemBase { $properties = parent::propertyDefinitions($field_definition); $properties['summary'] = DataDefinition::create('string') - ->setLabel(t('Summary')); + ->setLabel(new TranslatableMarkup('Summary')); $properties['summary_processed'] = DataDefinition::create('string') - ->setLabel(t('Processed summary')) - ->setDescription(t('The summary text with the text format applied.')) + ->setLabel(new TranslatableMarkup('Processed summary')) + ->setDescription(new TranslatableMarkup('The summary text with the text format applied.')) ->setComputed(TRUE) ->setClass('\Drupal\text\TextProcessed') ->setSetting('text source', 'summary'); @@ -91,15 +92,15 @@ class TextWithSummaryItem extends TextItemBase { $element['display_summary'] = [ '#type' => 'checkbox', - '#title' => t('Summary input'), + '#title' => $this->t('Summary input'), '#default_value' => $settings['display_summary'], - '#description' => t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'), + '#description' => $this->t('This allows authors to input an explicit summary, to be displayed instead of the automatically trimmed text when using the "Summary or trimmed" display type.'), ]; $element['required_summary'] = [ '#type' => 'checkbox', - '#title' => t('Require summary'), - '#description' => t('The summary will also be visible when marked as required.'), + '#title' => $this->t('Require summary'), + '#description' => $this->t('The summary will also be visible when marked as required.'), '#default_value' => $settings['required_summary'], ]; diff --git a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php index 999bfc46239..60b51650c87 100644 --- a/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php +++ b/core/modules/text/src/Plugin/Field/FieldWidget/TextareaWithSummaryWidget.php @@ -38,7 +38,7 @@ class TextareaWithSummaryWidget extends TextareaWidget { $element = parent::settingsForm($form, $form_state); $element['summary_rows'] = [ '#type' => 'number', - '#title' => t('Summary rows'), + '#title' => $this->t('Summary rows'), '#default_value' => $this->getSetting('summary_rows'), '#description' => $element['rows']['#description'], '#required' => TRUE, @@ -46,7 +46,7 @@ class TextareaWithSummaryWidget extends TextareaWidget { ]; $element['show_summary'] = [ '#type' => 'checkbox', - '#title' => t('Always show the summary field'), + '#title' => $this->t('Always show the summary field'), '#default_value' => $this->getSetting('show_summary'), ]; return $element; @@ -58,9 +58,9 @@ class TextareaWithSummaryWidget extends TextareaWidget { public function settingsSummary() { $summary = parent::settingsSummary(); - $summary[] = t('Number of summary rows: @rows', ['@rows' => $this->getSetting('summary_rows')]); + $summary[] = $this->t('Number of summary rows: @rows', ['@rows' => $this->getSetting('summary_rows')]); if ($this->getSetting('show_summary')) { - $summary[] = t('Summary field will always be visible'); + $summary[] = $this->t('Summary field will always be visible'); } return $summary; @@ -78,7 +78,7 @@ class TextareaWithSummaryWidget extends TextareaWidget { $element['summary'] = [ '#type' => $display_summary ? 'textarea' : 'value', '#default_value' => $items[$delta]->summary, - '#title' => t('Summary'), + '#title' => $this->t('Summary'), '#rows' => $this->getSetting('summary_rows'), '#description' => !$required ? $this->t('Leave blank to use trimmed value of full text as the summary.') : '', '#attributes' => ['class' => ['js-text-summary', 'text-summary']], diff --git a/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php b/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php index e496e1f9fa8..43dd5b30a6b 100644 --- a/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php +++ b/core/modules/user/src/Plugin/Action/ChangeUserRoleBase.php @@ -62,7 +62,7 @@ abstract class ChangeUserRoleBase extends ConfigurableActionBase implements Cont unset($roles[RoleInterface::AUTHENTICATED_ID]); $form['rid'] = [ '#type' => 'radios', - '#title' => t('Role'), + '#title' => $this->t('Role'), '#options' => $roles, '#default_value' => $this->configuration['rid'], '#required' => TRUE, diff --git a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php index 4d9d0f23f5f..3706e39eda2 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsBlock.php @@ -95,7 +95,7 @@ class ViewsBlock implements ContainerDeriverInterface { else { // Allow translators to control the punctuation. Plugin // definitions get cached, so use TranslatableMarkup() instead of - // t() to avoid double escaping when $admin_label is rendered + // $this->t() to avoid double escaping when $admin_label is rendered // during requests that use the cached definition. $admin_label = new TranslatableMarkup('@view: @display', ['@view' => $view->label(), '@display' => $display->display['display_title']]); } diff --git a/core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php b/core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php index 8dd537cc083..757b574189b 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsEntityRow.php @@ -4,6 +4,7 @@ namespace Drupal\views\Plugin\Derivative; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\ViewsData; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -16,6 +17,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class ViewsEntityRow implements ContainerDeriverInterface { + use StringTranslationTrait; + /** * Stores all entity row plugin information. * @@ -93,7 +96,7 @@ class ViewsEntityRow implements ContainerDeriverInterface { 'id' => 'entity:' . $entity_type_id, 'provider' => 'views', 'title' => $entity_type->getLabel(), - 'help' => t('Display the @label', ['@label' => $entity_type->getLabel()]), + 'help' => $this->t('Display the @label', ['@label' => $entity_type->getLabel()]), 'base' => [$entity_type->getDataTable() ?: $entity_type->getBaseTable()], 'entity_type' => $entity_type_id, 'display_types' => ['normal'], diff --git a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php index 0dcf62ee3d3..57ac710c246 100644 --- a/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php +++ b/core/modules/views/src/Plugin/Derivative/ViewsExposedFilterBlock.php @@ -4,6 +4,7 @@ namespace Drupal\views\Plugin\Derivative; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Drupal\Core\Entity\EntityStorageInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -13,6 +14,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface; */ class ViewsExposedFilterBlock implements ContainerDeriverInterface { + use StringTranslationTrait; + /** * List of derivative definitions. * @@ -85,7 +88,7 @@ class ViewsExposedFilterBlock implements ContainerDeriverInterface { // Add a block definition for the block. if ($display->usesExposedFormInBlock()) { $delta = $view->id() . '-' . $display->display['id']; - $desc = t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]); + $desc = $this->t('Exposed form: @view-@display_id', ['@view' => $view->id(), '@display_id' => $display->display['id']]); $this->derivatives[$delta] = [ 'admin_label' => $desc, 'config_dependencies' => [ diff --git a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php index cf80704f6b3..96cb20b3979 100644 --- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php +++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php @@ -10,6 +10,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\views\Render\ViewsRenderPipelineMarkup; use Drupal\views\Views; @@ -321,7 +322,7 @@ class ViewsSelection extends SelectionPluginBase implements ContainerFactoryPlug [$view, $display] = explode(':', $element['view_and_display']['#value']); } else { - $form_state->setError($element, t('The views entity selection mode requires a view.')); + $form_state->setError($element, new TranslatableMarkup('The views entity selection mode requires a view.')); return; } diff --git a/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php b/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php index 992e8e252f5..55df6484efd 100644 --- a/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php +++ b/core/modules/views/src/Plugin/views/BrokenHandlerTrait.php @@ -16,7 +16,7 @@ trait BrokenHandlerTrait { * @see \Drupal\views\Plugin\views\PluginBase::defineOptions() */ public function adminLabel($short = FALSE) { - return t('Broken/missing handler'); + return $this->t('Broken/missing handler'); } /** @@ -51,7 +51,7 @@ trait BrokenHandlerTrait { * @see \Drupal\views\Plugin\views\PluginBase::defineOptions() */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { - $description_top = t('The handler for this item is broken or missing. The following details are available:'); + $description_top = $this->t('The handler for this item is broken or missing. The following details are available:'); foreach ($this->definition['original_configuration'] as $key => $value) { if (is_scalar($value)) { @@ -59,7 +59,7 @@ trait BrokenHandlerTrait { } } - $description_bottom = t('Enabling the appropriate module may solve this issue. Otherwise, check to see if there is a module update available.'); + $description_bottom = $this->t('Enabling the appropriate module may solve this issue. Otherwise, check to see if there is a module update available.'); $form['description'] = [ '#type' => 'container', diff --git a/core/modules/views/src/Plugin/views/area/DisplayLink.php b/core/modules/views/src/Plugin/views/area/DisplayLink.php index 02f2e7480d8..c7c1968ba2c 100644 --- a/core/modules/views/src/Plugin/views/area/DisplayLink.php +++ b/core/modules/views/src/Plugin/views/area/DisplayLink.php @@ -129,10 +129,10 @@ class DisplayLink extends AreaPluginBase { // recommend keeping the display options equal, we do not want to enforce // this. $unequal_options = [ - 'filters' => t('Filter criteria'), - 'sorts' => t('Sort criteria'), - 'pager' => t('Pager'), - 'arguments' => t('Contextual filters'), + 'filters' => $this->t('Filter criteria'), + 'sorts' => $this->t('Sort criteria'), + 'pager' => $this->t('Pager'), + 'arguments' => $this->t('Contextual filters'), ]; foreach (array_keys($unequal_options) as $option) { if ($this->hasEqualOptions($linked_display_id, $option)) { diff --git a/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php b/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php index 0b05e173af1..02533c7198b 100644 --- a/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php +++ b/core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php @@ -48,8 +48,8 @@ abstract class TokenizeAreaPluginBase extends AreaPluginBase { // Get a list of the available fields and arguments for token replacement. $options = []; - $optgroup_arguments = (string) t('Arguments'); - $optgroup_fields = (string) t('Fields'); + $optgroup_arguments = (string) $this->t('Arguments'); + $optgroup_fields = (string) $this->t('Fields'); foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) { $options[$optgroup_fields]["{{ $field }}"] = $handler->adminLabel(); } diff --git a/core/modules/views/src/Plugin/views/area/View.php b/core/modules/views/src/Plugin/views/area/View.php index 0f2d5bc91e7..6dae7802f70 100644 --- a/core/modules/views/src/Plugin/views/area/View.php +++ b/core/modules/views/src/Plugin/views/area/View.php @@ -118,7 +118,7 @@ class View extends AreaPluginBase { // Check if the view is part of the parent views of this view $search = "$view_name:$display_id"; if (in_array($search, $this->view->parent_views)) { - \Drupal::messenger()->addError(t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id])); + \Drupal::messenger()->addError($this->t("Recursion detected in view @view display @display.", ['@view' => $view_name, '@display' => $display_id])); } else { if (!empty($this->options['inherit_arguments']) && !empty($this->view->args)) { diff --git a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php index ff5042485c1..02e4b36c533 100644 --- a/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php @@ -420,8 +420,8 @@ abstract class ArgumentPluginBase extends HandlerBase implements CacheableDepend foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) { /** @var \Drupal\views\Plugin\views\argument\ArgumentPluginBase $handler */ - $options[(string) t('Arguments')]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]); - $options[(string) t('Arguments')]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]); + $options[(string) $this->t('Arguments')]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]); + $options[(string) $this->t('Arguments')]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]); } // We have some options, so make a list. diff --git a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php index ea557f386d2..c9f24b6aa99 100644 --- a/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php @@ -1741,7 +1741,7 @@ abstract class DisplayPluginBase extends PluginBase implements DisplayPluginInte ]; $options = []; - $optgroup_arguments = (string) t('Arguments'); + $optgroup_arguments = (string) $this->t('Arguments'); foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) { $options[$optgroup_arguments]["{{ arguments.$arg }}"] = $this->t('@argument title', ['@argument' => $handler->adminLabel()]); $options[$optgroup_arguments]["{{ raw_arguments.$arg }}"] = $this->t('@argument input', ['@argument' => $handler->adminLabel()]); diff --git a/core/modules/views/src/Plugin/views/field/Boolean.php b/core/modules/views/src/Plugin/views/field/Boolean.php index 8ea2ab2bc49..82b7fda9950 100644 --- a/core/modules/views/src/Plugin/views/field/Boolean.php +++ b/core/modules/views/src/Plugin/views/field/Boolean.php @@ -54,15 +54,15 @@ class Boolean extends FieldPluginBase { parent::init($view, $display, $options); $default_formats = [ - 'yes-no' => [t('Yes'), $this->t('No')], - 'true-false' => [t('True'), $this->t('False')], - 'on-off' => [t('On'), $this->t('Off')], - 'enabled-disabled' => [t('Enabled'), $this->t('Disabled')], + 'yes-no' => [$this->t('Yes'), $this->t('No')], + 'true-false' => [$this->t('True'), $this->t('False')], + 'on-off' => [$this->t('On'), $this->t('Off')], + 'enabled-disabled' => [$this->t('Enabled'), $this->t('Disabled')], 'boolean' => [1, 0], 'unicode-yes-no' => ['✔', '✖'], ]; $output_formats = $this->definition['output formats'] ?? []; - $custom_format = ['custom' => [t('Custom')]]; + $custom_format = ['custom' => [$this->t('Custom')]]; $this->formats = array_merge($default_formats, $output_formats, $custom_format); } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 12e2235216a..2a1c4fc8508 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -14,6 +14,7 @@ use Drupal\views\Render\ViewsRenderPipelineMarkup; use Drupal\views\ResultRow; use Drupal\views\ViewExecutable; use Twig\Environment; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * @defgroup views_field_handlers Views field handler plugins @@ -891,8 +892,8 @@ abstract class FieldPluginBase extends HandlerBase implements FieldHandlerInterf // Setup the tokens for fields. $previous = $this->getPreviousFieldLabels(); - $optgroup_arguments = (string) t('Arguments'); - $optgroup_fields = (string) t('Fields'); + $optgroup_arguments = (string) $this->t('Arguments'); + $optgroup_fields = (string) $this->t('Fields'); foreach ($previous as $id => $label) { $options[$optgroup_fields]["{{ $id }}"] = substr(strrchr($label, ":"), 2); } @@ -1834,7 +1835,7 @@ abstract class FieldPluginBase extends HandlerBase implements FieldHandlerInterf $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value)); if (!empty($alter['ellipsis'])) { - $value .= t('…'); + $value .= new TranslatableMarkup('…'); } } if (!empty($alter['html'])) { diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 5fdeeb958b6..3a8d5de6b22 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -72,7 +72,7 @@ class InOperator extends FilterPluginBase { } } else { - $this->valueOptions = [t('Yes'), $this->t('No')]; + $this->valueOptions = [$this->t('Yes'), $this->t('No')]; } return $this->valueOptions; diff --git a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php index 2367981ad5a..1e81e51e235 100644 --- a/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php +++ b/core/modules/views/tests/modules/views_test_data/src/Plugin/views/field/FieldFormButtonTest.php @@ -46,7 +46,7 @@ class FieldFormButtonTest extends FieldPluginBase { foreach ($this->view->result as $row_index => $row) { $form[$this->options['id']][$row_index] = [ '#type' => 'submit', - '#value' => t('Test Button'), + '#value' => $this->t('Test Button'), '#name' => 'test-button-' . $row_index, '#test_button' => TRUE, '#row_index' => $row_index, diff --git a/core/modules/views/tests/src/Kernel/Plugin/RelationshipJoinTestBase.php b/core/modules/views/tests/src/Kernel/Plugin/RelationshipJoinTestBase.php index ecb90a7f3f3..aaaa78df88c 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/RelationshipJoinTestBase.php +++ b/core/modules/views/tests/src/Kernel/Plugin/RelationshipJoinTestBase.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\views\Kernel\Plugin; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\user\Entity\User; use Drupal\views\Views; @@ -69,8 +70,8 @@ abstract class RelationshipJoinTestBase extends PluginKernelTestBase { protected function viewsData() { $data = parent::viewsData(); $data['views_test_data']['uid'] = [ - 'title' => t('UID'), - 'help' => t('The test data UID'), + 'title' => new TranslatableMarkup('UID'), + 'help' => new TranslatableMarkup('The test data UID'), 'relationship' => [ 'id' => 'standard', 'base' => 'users_field_data', diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 3960b29673d..9836486b3ea 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -164,6 +164,9 @@ + + */Plugin/* + diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/AnnotatedClassDiscoveryTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/AnnotatedClassDiscoveryTest.php index c1017acc3d2..fe747c01fc9 100644 --- a/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/AnnotatedClassDiscoveryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/AnnotatedClassDiscoveryTest.php @@ -3,6 +3,7 @@ namespace Drupal\KernelTests\Core\Plugin\Discovery; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Tests that plugins are correctly discovered using annotated classes. @@ -29,7 +30,7 @@ class AnnotatedClassDiscoveryTest extends DiscoveryTestBase { 'label' => 'Banana', 'color' => 'yellow', 'uses' => [ - 'bread' => t('Banana bread'), + 'bread' => new TranslatableMarkup('Banana bread'), 'loaf' => [ 'singular' => '@count loaf', 'plural' => '@count loaves', diff --git a/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php b/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php index 1cacefefc9c..48f987decce 100644 --- a/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php +++ b/core/tests/Drupal/KernelTests/Core/Plugin/Discovery/CustomDirectoryAnnotatedClassDiscoveryTest.php @@ -3,6 +3,7 @@ namespace Drupal\KernelTests\Core\Plugin\Discovery; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; +use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Tests that plugins in a custom directory are correctly discovered using @@ -43,7 +44,7 @@ class CustomDirectoryAnnotatedClassDiscoveryTest extends DiscoveryTestBase { 'label' => 'Banana', 'color' => 'yellow', 'uses' => [ - 'bread' => t('Banana bread'), + 'bread' => new TranslatableMarkup('Banana bread'), 'loaf' => [ 'singular' => '@count loaf', 'plural' => '@count loaves',