diff --git a/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php b/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php index 5ad29d02a1bbda7505d925254645f66ab0397ff2..47eb5113d9c03d216f28c52f6a2093b68efca9b0 100644 --- a/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php +++ b/core/modules/announcements_feed/src/Hook/AnnouncementsFeedHooks.php @@ -6,12 +6,15 @@ use Drupal\Core\Link; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for announcements_feed. */ class AnnouncementsFeedHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -20,14 +23,14 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.announcements_feed': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Announcements module displays announcements from the Drupal community. For more information, see the <a href=":documentation">online documentation for the Announcements module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Announcements module displays announcements from the Drupal community. For more information, see the <a href=":documentation">online documentation for the Announcements module</a>.', [ ':documentation' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/announcements-feed', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; - $output .= '<dl><dt>' . t('Accessing announcements') . '</dt>'; - $output .= '<dd>' . t('Users with the "View drupal.org announcements" permission may click on the "Announcements" item in the administration toolbar, or access @link, to see all announcements relevant to the Drupal version of your site.', [ - '@link' => Link::createFromRoute(t('Announcements'), 'announcements_feed.announcement')->toString(), + $output .= '<h2>' . $this->t('Uses') . '</h2>'; + $output .= '<dl><dt>' . $this->t('Accessing announcements') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the "View drupal.org announcements" permission may click on the "Announcements" item in the administration toolbar, or access @link, to see all announcements relevant to the Drupal version of your site.', [ + '@link' => Link::createFromRoute($this->t('Announcements'), 'announcements_feed.announcement')->toString(), ]) . '</dd>'; $output .= '</dl>'; return $output; diff --git a/core/modules/automated_cron/src/Hook/AutomatedCronHooks.php b/core/modules/automated_cron/src/Hook/AutomatedCronHooks.php index 64be8d4c2512fde5eb5ff058c268ea308351d74a..3c0ffbdfc86d30072c8948b633144baaf7c36d99 100644 --- a/core/modules/automated_cron/src/Hook/AutomatedCronHooks.php +++ b/core/modules/automated_cron/src/Hook/AutomatedCronHooks.php @@ -2,6 +2,7 @@ namespace Drupal\automated_cron\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class AutomatedCronHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,18 +22,18 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.automated_cron': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Automated Cron module runs cron operations for your site using normal browser/page requests instead of having to set up a separate cron job. The Automated Cron module checks at the end of each server response when cron operation was last ran and, if it has been too long since last run, it executes the cron tasks after sending a server response. For more information, see the <a href=":automated_cron-documentation">online documentation for the Automated Cron module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Automated Cron module runs cron operations for your site using normal browser/page requests instead of having to set up a separate cron job. The Automated Cron module checks at the end of each server response when cron operation was last ran and, if it has been too long since last run, it executes the cron tasks after sending a server response. For more information, see the <a href=":automated_cron-documentation">online documentation for the Automated Cron module</a>.', [ ':automated_cron-documentation' => 'https://www.drupal.org/documentation/modules/automated_cron', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Configuring Automated Cron') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":cron-settings">Cron page</a>, you can set the frequency (time interval) for running cron jobs.', [ + $output .= '<dt>' . $this->t('Configuring Automated Cron') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":cron-settings">Cron page</a>, you can set the frequency (time interval) for running cron jobs.', [ ':cron-settings' => Url::fromRoute('system.cron_settings')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Disabling Automated Cron') . '</dt>'; - $output .= '<dd>' . t('To disable automated cron, the recommended method is to uninstall the module, to reduce site overhead. If you only want to disable it temporarily, you can set the frequency to Never on the Cron page, and then change the frequency back when you want to start it up again.') . '</dd>'; + $output .= '<dt>' . $this->t('Disabling Automated Cron') . '</dt>'; + $output .= '<dd>' . $this->t('To disable automated cron, the recommended method is to uninstall the module, to reduce site overhead. If you only want to disable it temporarily, you can set the frequency to Never on the Cron page, and then change the frequency back when you want to start it up again.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -45,13 +48,13 @@ public function formSystemCronSettingsAlter(&$form, &$form_state) : void { $options = [3600, 10800, 21600, 43200, 86400, 604800]; $form['cron']['interval'] = [ '#type' => 'select', - '#title' => t('Run cron every'), - '#description' => t('More information about setting up scheduled tasks can be found by <a href=":url">reading the cron tutorial on drupal.org</a>.', [ + '#title' => $this->t('Run cron every'), + '#description' => $this->t('More information about setting up scheduled tasks can be found by <a href=":url">reading the cron tutorial on drupal.org</a>.', [ ':url' => 'https://www.drupal.org/docs/8/administering-a-drupal-8-site/cron-automated-tasks', ]), '#default_value' => $automated_cron_settings->get('interval'), '#options' => [ - 0 => t('Never'), + 0 => $this->t('Never'), ] + array_map([ \Drupal::service('date.formatter'), 'formatInterval', diff --git a/core/modules/ban/src/Hook/BanHooks.php b/core/modules/ban/src/Hook/BanHooks.php index c4966a1a41a5ab04ffa05c94bd4be772a498b77e..b299f4274514b6a29f36743d719695007c13f617 100644 --- a/core/modules/ban/src/Hook/BanHooks.php +++ b/core/modules/ban/src/Hook/BanHooks.php @@ -2,6 +2,7 @@ namespace Drupal\ban\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class BanHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,17 +22,17 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.ban': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Ban module allows administrators to ban visits to their site from individual IP addresses. For more information, see the <a href=":url">online documentation for the Ban module</a>.', [':url' => 'https://www.drupal.org/documentation/modules/ban']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Ban module allows administrators to ban visits to their site from individual IP addresses. For more information, see the <a href=":url">online documentation for the Ban module</a>.', [':url' => 'https://www.drupal.org/documentation/modules/ban']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Banning IP addresses') . '</dt>'; - $output .= '<dd>' . t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [':bans' => Url::fromRoute('ban.admin_page')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Banning IP addresses') . '</dt>'; + $output .= '<dd>' . $this->t('Administrators can enter IP addresses to ban on the <a href=":bans">IP address bans</a> page.', [':bans' => Url::fromRoute('ban.admin_page')->toString()]) . '</dd>'; $output .= '</dl>'; return $output; case 'ban.admin_page': - return '<p>' . t('IP addresses listed here are banned from your site. Banned addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '</p>'; + return '<p>' . $this->t('IP addresses listed here are banned from your site. Banned addresses are completely forbidden from accessing the site and instead see a brief message explaining the situation.') . '</p>'; } } diff --git a/core/modules/basic_auth/src/Hook/BasicAuthHooks.php b/core/modules/basic_auth/src/Hook/BasicAuthHooks.php index 2660b1ff87817836733f75c6f3d90003a031f336..a133c99ef2304c66be3910b5a5091d65b496e6f2 100644 --- a/core/modules/basic_auth/src/Hook/BasicAuthHooks.php +++ b/core/modules/basic_auth/src/Hook/BasicAuthHooks.php @@ -2,6 +2,7 @@ namespace Drupal\basic_auth\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class BasicAuthHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,8 +22,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.basic_auth': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The HTTP Basic Authentication module supplies an <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic authentication</a> provider for web service requests. This authentication provider authenticates requests using the HTTP Basic Authentication username and password, as an alternative to using Drupal\'s standard cookie-based authentication system. It is only useful if your site provides web services configured to use this type of authentication (for instance, the <a href=":rest_help">RESTful Web Services module</a>). For more information, see the <a href=":hba_do">online documentation for the HTTP Basic Authentication module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The HTTP Basic Authentication module supplies an <a href="http://en.wikipedia.org/wiki/Basic_access_authentication">HTTP Basic authentication</a> provider for web service requests. This authentication provider authenticates requests using the HTTP Basic Authentication username and password, as an alternative to using Drupal\'s standard cookie-based authentication system. It is only useful if your site provides web services configured to use this type of authentication (for instance, the <a href=":rest_help">RESTful Web Services module</a>). For more information, see the <a href=":hba_do">online documentation for the HTTP Basic Authentication module</a>.', [ ':hba_do' => 'https://www.drupal.org/documentation/modules/basic_auth', ':rest_help' => \Drupal::moduleHandler()->moduleExists('rest') ? Url::fromRoute('help.page', [ 'name' => 'rest', diff --git a/core/modules/big_pipe/src/Hook/BigPipeHooks.php b/core/modules/big_pipe/src/Hook/BigPipeHooks.php index 93b1f1f0f487f1c64a7ad9c0094f96ac6359f4f2..f9d2a87f1c0abf4d3251a9edc0ee36ab9c7c08cd 100644 --- a/core/modules/big_pipe/src/Hook/BigPipeHooks.php +++ b/core/modules/big_pipe/src/Hook/BigPipeHooks.php @@ -2,6 +2,7 @@ namespace Drupal\big_pipe\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\big_pipe\Render\Placeholder\BigPipeStrategy; use Drupal\Core\Routing\RouteMatchInterface; @@ -12,6 +13,8 @@ */ class BigPipeHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,14 +22,14 @@ class BigPipeHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.big_pipe': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The BigPipe module sends pages with dynamic content in a way that allows browsers to show them much faster. For more information, see the <a href=":big_pipe-documentation">online documentation for the BigPipe module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The BigPipe module sends pages with dynamic content in a way that allows browsers to show them much faster. For more information, see the <a href=":big_pipe-documentation">online documentation for the BigPipe module</a>.', [ ':big_pipe-documentation' => 'https://www.drupal.org/documentation/modules/big_pipe', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Speeding up your site') . '</dt>'; - $output .= '<dd>' . t('The module requires no configuration. Every part of the page contains metadata that allows BigPipe to figure this out on its own.') . '</dd>'; + $output .= '<dt>' . $this->t('Speeding up your site') . '</dt>'; + $output .= '<dd>' . $this->t('The module requires no configuration. Every part of the page contains metadata that allows BigPipe to figure this out on its own.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/block/src/Hook/BlockHooks.php b/core/modules/block/src/Hook/BlockHooks.php index 579a87fab65a65a57922a753d675e4bf72555b11..5b0991bcc502c0e09691890ce4590ab0fb3e5202 100644 --- a/core/modules/block/src/Hook/BlockHooks.php +++ b/core/modules/block/src/Hook/BlockHooks.php @@ -3,6 +3,7 @@ namespace Drupal\block\Hook; use Drupal\Core\Block\BlockPluginInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\ConfigurableLanguageInterface; use Drupal\system\Entity\Menu; use Drupal\block\Entity\Block; @@ -16,6 +17,8 @@ */ class BlockHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -25,30 +28,30 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'help.page.block': $block_content = \Drupal::moduleHandler()->moduleExists('block_content') ? Url::fromRoute('help.page', ['name' => 'block_content'])->toString() : '#'; $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Block module allows you to place blocks in regions of your installed themes, and configure block settings. For more information, see the <a href=":blocks-documentation">online documentation for the Block module</a>.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block/']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Block module allows you to place blocks in regions of your installed themes, and configure block settings. For more information, see the <a href=":blocks-documentation">online documentation for the Block module</a>.', [':blocks-documentation' => 'https://www.drupal.org/documentation/modules/block/']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Placing and moving blocks') . '</dt>'; - $output .= '<dd>' . t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Toggling between different themes') . '</dt>'; - $output .= '<dd>' . t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '</dd>'; - $output .= '<dt>' . t('Demonstrating block regions for a theme') . '</dt>'; - $output .= '<dd>' . t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Configuring block settings') . '</dt>'; - $output .= '<dd>' . t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Controlling visibility') . '</dt>'; - $output .= '<dd>' . t('You can control the visibility of a block by restricting it to specific pages, content types, and/or roles by setting the appropriate options under <em>Visibility settings</em> of the block configuration.') . '</dd>'; - $output .= '<dt>' . t('Adding content blocks') . '</dt>'; - $output .= '<dd>' . t('You can add content blocks, if the <em>Block Content</em> module is installed. For more information, see the <a href=":blockcontent-help">Block Content help page</a>.', [':blockcontent-help' => $block_content]) . '</dd>'; + $output .= '<dt>' . $this->t('Placing and moving blocks') . '</dt>'; + $output .= '<dd>' . $this->t('You can place a new block in a region by selecting <em>Place block</em> on the <a href=":blocks">Block layout page</a>. Once a block is placed, it can be moved to a different region by drag-and-drop or by using the <em>Region</em> drop-down list, and then clicking <em>Save blocks</em>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Toggling between different themes') . '</dt>'; + $output .= '<dd>' . $this->t('Blocks are placed and configured specifically for each theme. The Block layout page opens with the default theme, but you can toggle to other installed themes.') . '</dd>'; + $output .= '<dt>' . $this->t('Demonstrating block regions for a theme') . '</dt>'; + $output .= '<dd>' . $this->t('You can see where the regions are for the current theme by clicking the <em>Demonstrate block regions</em> link on the <a href=":blocks">Block layout page</a>. Regions are specific to each theme.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Configuring block settings') . '</dt>'; + $output .= '<dd>' . $this->t('To change the settings of an individual block click on the <em>Configure</em> link on the <a href=":blocks">Block layout page</a>. The available options vary depending on the module that provides the block. For all blocks you can change the block title and toggle whether to display it.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Controlling visibility') . '</dt>'; + $output .= '<dd>' . $this->t('You can control the visibility of a block by restricting it to specific pages, content types, and/or roles by setting the appropriate options under <em>Visibility settings</em> of the block configuration.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding content blocks') . '</dt>'; + $output .= '<dd>' . $this->t('You can add content blocks, if the <em>Block Content</em> module is installed. For more information, see the <a href=":blockcontent-help">Block Content help page</a>.', [':blockcontent-help' => $block_content]) . '</dd>'; $output .= '</dl>'; return $output; } if ($route_name == 'block.admin_display' || $route_name == 'block.admin_display_theme') { $demo_theme = $route_match->getParameter('theme') ?: \Drupal::config('system.theme')->get('default'); $themes = \Drupal::service('theme_handler')->listInfo(); - $output = '<p>' . t('Block placement is specific to each theme on your site. Changes will not be saved until you click <em>Save blocks</em> at the bottom of the page.') . '</p>'; - $output .= '<p>' . Link::fromTextAndUrl(t('Demonstrate block regions (@theme)', ['@theme' => $themes[$demo_theme]->info['name']]), Url::fromRoute('block.admin_demo', ['theme' => $demo_theme]))->toString() . '</p>'; + $output = '<p>' . $this->t('Block placement is specific to each theme on your site. Changes will not be saved until you click <em>Save blocks</em> at the bottom of the page.') . '</p>'; + $output .= '<p>' . Link::fromTextAndUrl($this->t('Demonstrate block regions (@theme)', ['@theme' => $themes[$demo_theme]->info['name']]), Url::fromRoute('block.admin_demo', ['theme' => $demo_theme]))->toString() . '</p>'; return $output; } } @@ -70,7 +73,7 @@ public function pageTop(array &$page_top): void { $theme = \Drupal::theme()->getActiveTheme()->getName(); $page_top['backlink'] = [ '#type' => 'link', - '#title' => t('Exit block region demonstration'), + '#title' => $this->t('Exit block region demonstration'), '#options' => [ 'attributes' => [ 'class' => [ @@ -122,7 +125,7 @@ public function rebuild(): void { // Disable blocks in invalid regions. if (!isset($regions[$block->getRegion()])) { if ($block->status()) { - \Drupal::messenger()->addWarning(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()])); + \Drupal::messenger()->addWarning($this->t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()])); } $block->setRegion(system_default_region($theme))->disable()->save(); } @@ -197,7 +200,7 @@ public function blockBuildLocalActionsBlockAlter(array &$build, BlockPluginInter 'actions' => [ '#theme' => 'menu_local_action', '#link' => [ - 'title' => t('Add'), + 'title' => $this->t('Add'), 'url' => Url::fromUserInput('#'), ], ], diff --git a/core/modules/block_content/src/Hook/BlockContentHooks.php b/core/modules/block_content/src/Hook/BlockContentHooks.php index 1542880099c1157afaeedf810c18b8402cf3a53f..d7907dfdf34d665622561302bbfbba5b00281582 100644 --- a/core/modules/block_content/src/Hook/BlockContentHooks.php +++ b/core/modules/block_content/src/Hook/BlockContentHooks.php @@ -7,6 +7,7 @@ use Drupal\block_content\BlockContentInterface; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\AlterableInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -16,6 +17,8 @@ */ class BlockContentHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -25,20 +28,20 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'help.page.block_content': $field_ui = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'; $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Block Content module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em>. For more information, see the <a href=":online-help">online documentation for the Block Content module</a>.', [':online-help' => 'https://www.drupal.org/documentation/modules/block_content']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Block Content module allows you to create and manage custom <em>block types</em> and <em>content-containing blocks</em>. For more information, see the <a href=":online-help">online documentation for the Block Content module</a>.', [':online-help' => 'https://www.drupal.org/documentation/modules/block_content']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating and managing block types') . '</dt>'; - $output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create and edit block types with fields and display settings, from the <a href=":types">Block types</a> page under the Structure menu. For more information about managing fields and display settings, see the <a href=":field-ui">Field UI module help</a> and <a href=":field">Field module help</a>.', [ + $output .= '<dt>' . $this->t('Creating and managing block types') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the <em>Administer blocks</em> permission can create and edit block types with fields and display settings, from the <a href=":types">Block types</a> page under the Structure menu. For more information about managing fields and display settings, see the <a href=":field-ui">Field UI module help</a> and <a href=":field">Field module help</a>.', [ ':types' => Url::fromRoute('entity.block_content_type.collection')->toString(), ':field-ui' => $field_ui, ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Creating content blocks') . '</dt>'; - $output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can create, edit, and delete content blocks of each defined block type, from the <a href=":block-library">Content blocks page</a>. After creating a block, place it in a region from the <a href=":blocks">Block layout page</a>, just like blocks provided by other modules.', [ + $output .= '<dt>' . $this->t('Creating content blocks') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the <em>Administer blocks</em> permission can create, edit, and delete content blocks of each defined block type, from the <a href=":block-library">Content blocks page</a>. After creating a block, place it in a region from the <a href=":blocks">Block layout page</a>, just like blocks provided by other modules.', [ ':blocks' => Url::fromRoute('block.admin_display')->toString(), ':block-library' => Url::fromRoute('entity.block_content.collection')->toString(), ]) . '</dd>'; @@ -146,7 +149,7 @@ public function entityOperation(EntityInterface $entity) : array { $custom_block = reset($custom_block); if ($custom_block && $custom_block->access('update')) { $operations['block-edit'] = [ - 'title' => t('Edit block'), + 'title' => $this->t('Edit block'), 'url' => $custom_block->toUrl('edit-form')->setOptions([]), 'weight' => 50, ]; diff --git a/core/modules/breakpoint/src/Hook/BreakpointHooks.php b/core/modules/breakpoint/src/Hook/BreakpointHooks.php index d503d3339f43e7356c95eaed7ae0be007cb83923..b1da0df2d45eaccbb5c3aed6dc0cf70fd0c666ea 100644 --- a/core/modules/breakpoint/src/Hook/BreakpointHooks.php +++ b/core/modules/breakpoint/src/Hook/BreakpointHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for breakpoint. */ class BreakpointHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -18,23 +21,23 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.breakpoint': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Breakpoint module keeps track of the height, width, and resolution breakpoints where a responsive design needs to change in order to respond to different devices being used to view the site. This module does not have a user interface. For more information, see the <a href=":docs">online documentation for the Breakpoint module</a>.', [':docs' => 'https://www.drupal.org/documentation/modules/breakpoint']) . '</p>'; - $output .= '<h4>' . t('Terminology') . '</h4>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Breakpoint module keeps track of the height, width, and resolution breakpoints where a responsive design needs to change in order to respond to different devices being used to view the site. This module does not have a user interface. For more information, see the <a href=":docs">online documentation for the Breakpoint module</a>.', [':docs' => 'https://www.drupal.org/documentation/modules/breakpoint']) . '</p>'; + $output .= '<h4>' . $this->t('Terminology') . '</h4>'; $output .= '<dl>'; - $output .= '<dt>' . t('Breakpoint') . '</dt>'; - $output .= '<dd>' . t('A breakpoint separates the height or width of viewports (screens, printers, and other media output types) into steps. For instance, a width breakpoint of 40em creates two steps: one for widths up to 40em and one for widths above 40em. Breakpoints can be used to define when layouts should shift from one form to another, when images should be resized, and other changes that need to respond to changes in viewport height or width.') . '</dd>'; - $output .= '<dt>' . t('Media query') . '</dt>'; - $output .= '<dd>' . t('<a href=":w3">Media queries</a> are a formal way to encode breakpoints. For instance, a width breakpoint at 40em would be written as the media query "(min-width: 40em)". Breakpoints are really just media queries with some additional meta-data, such as a name and multiplier information.', [':w3' => 'https://www.w3.org/TR/css3-mediaqueries/']) . '</dd>'; - $output .= '<dt>' . t('Resolution multiplier') . '</dt>'; - $output .= '<dd>' . t('Resolution multipliers are a measure of the viewport\'s device resolution, defined to be the ratio between the physical pixel size of the active device and the <a href="http://en.wikipedia.org/wiki/Device_independent_pixel">device-independent pixel</a> size. The Breakpoint module defines multipliers of 1, 1.5, and 2; when defining breakpoints, modules and themes can define which multipliers apply to each breakpoint.') . '</dd>'; - $output .= '<dt>' . t('Breakpoint group') . '</dt>'; - $output .= '<dd>' . t('Breakpoints can be organized into groups. Modules and themes should use groups to separate out breakpoints that are meant to be used for different purposes, such as breakpoints for layouts or breakpoints for image sizing.') . '</dd>'; + $output .= '<dt>' . $this->t('Breakpoint') . '</dt>'; + $output .= '<dd>' . $this->t('A breakpoint separates the height or width of viewports (screens, printers, and other media output types) into steps. For instance, a width breakpoint of 40em creates two steps: one for widths up to 40em and one for widths above 40em. Breakpoints can be used to define when layouts should shift from one form to another, when images should be resized, and other changes that need to respond to changes in viewport height or width.') . '</dd>'; + $output .= '<dt>' . $this->t('Media query') . '</dt>'; + $output .= '<dd>' . $this->t('<a href=":w3">Media queries</a> are a formal way to encode breakpoints. For instance, a width breakpoint at 40em would be written as the media query "(min-width: 40em)". Breakpoints are really just media queries with some additional meta-data, such as a name and multiplier information.', [':w3' => 'https://www.w3.org/TR/css3-mediaqueries/']) . '</dd>'; + $output .= '<dt>' . $this->t('Resolution multiplier') . '</dt>'; + $output .= '<dd>' . $this->t('Resolution multipliers are a measure of the viewport\'s device resolution, defined to be the ratio between the physical pixel size of the active device and the <a href="http://en.wikipedia.org/wiki/Device_independent_pixel">device-independent pixel</a> size. The Breakpoint module defines multipliers of 1, 1.5, and 2; when defining breakpoints, modules and themes can define which multipliers apply to each breakpoint.') . '</dd>'; + $output .= '<dt>' . $this->t('Breakpoint group') . '</dt>'; + $output .= '<dd>' . $this->t('Breakpoints can be organized into groups. Modules and themes should use groups to separate out breakpoints that are meant to be used for different purposes, such as breakpoints for layouts or breakpoints for image sizing.') . '</dd>'; $output .= '</dl>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Defining breakpoints and breakpoint groups') . '</dt>'; - $output .= '<dd>' . t('Modules and themes can use the API provided by the Breakpoint module to define breakpoints and breakpoint groups, and to assign resolution multipliers to breakpoints.') . '</dd>'; + $output .= '<dt>' . $this->t('Defining breakpoints and breakpoint groups') . '</dt>'; + $output .= '<dd>' . $this->t('Modules and themes can use the API provided by the Breakpoint module to define breakpoints and breakpoint groups, and to assign resolution multipliers to breakpoints.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php b/core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php index 2775c9654d6ebdabd4452a581ac2bf668a14cff1..bd3f133c0eea75bd54a62b4c726f13dab6fd6629 100644 --- a/core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php +++ b/core/modules/ckeditor5/src/Hook/Ckeditor5Hooks.php @@ -7,6 +7,7 @@ use Drupal\Core\Render\Element; use Drupal\ckeditor5\Plugin\Editor\CKEditor5; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -16,6 +17,8 @@ */ class Ckeditor5Hooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -24,18 +27,18 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.ckeditor5': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The CKEditor 5 module provides a highly-accessible, highly-usable visual text editor and adds a toolbar to text fields. Users can use buttons to format content and to create semantically correct and valid HTML. The CKEditor module uses the framework provided by the <a href=":text_editor">Text Editor module</a>. It requires JavaScript to be enabled in the browser. For more information, see the <a href=":doc_url">online documentation for the CKEditor 5 module</a> and the <a href=":cke5_url">CKEditor 5 website</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The CKEditor 5 module provides a highly-accessible, highly-usable visual text editor and adds a toolbar to text fields. Users can use buttons to format content and to create semantically correct and valid HTML. The CKEditor module uses the framework provided by the <a href=":text_editor">Text Editor module</a>. It requires JavaScript to be enabled in the browser. For more information, see the <a href=":doc_url">online documentation for the CKEditor 5 module</a> and the <a href=":cke5_url">CKEditor 5 website</a>.', [ ':doc_url' => 'https://www.drupal.org/docs/contributed-modules/ckeditor-5', ':cke5_url' => 'https://ckeditor.com/ckeditor-5/', ':text_editor' => Url::fromRoute('help.page', [ 'name' => 'editor', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Enabling CKEditor 5 for individual text formats') . '</dt>'; - $output .= '<dd>' . t('CKEditor 5 has to be installed and configured separately for individual text formats from the <a href=":formats">Text formats and editors page</a> because the filter settings for each text format can be different. For more information, see the <a href=":text_editor">Text Editor help page</a> and <a href=":filter">Filter help page</a>.', [ + $output .= '<dt>' . $this->t('Enabling CKEditor 5 for individual text formats') . '</dt>'; + $output .= '<dd>' . $this->t('CKEditor 5 has to be installed and configured separately for individual text formats from the <a href=":formats">Text formats and editors page</a> because the filter settings for each text format can be different. For more information, see the <a href=":text_editor">Text Editor help page</a> and <a href=":filter">Filter help page</a>.', [ ':formats' => Url::fromRoute('filter.admin_overview')->toString(), ':text_editor' => Url::fromRoute('help.page', [ 'name' => 'editor', @@ -44,43 +47,43 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'filter', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Configuring the toolbar') . '</dt>'; - $output .= '<dd>' . t('When CKEditor 5 is chosen from the <em>Text editor</em> drop-down menu, its toolbar configuration is displayed. You can add and remove buttons from the <em>Active toolbar</em> by dragging and dropping them. Separators and rows can be added to organize the buttons.') . '</dd>'; - $output .= '<dt>' . t('Filtering HTML content') . '</dt>'; - $output .= '<dd>' . t("Unlike other text editors, plugin configuration determines the tags and attributes allowed in text formats using CKEditor 5. If using the <em>Limit allowed HTML tags and correct faulty HTML</em> filter, this filter's values will be automatically set based on enabled plugins and toolbar items."); - $output .= '<dt>' . t('Toggling between formatted text and HTML source') . '</dt>'; - $output .= '<dd>' . t('If the <em>Source</em> button is available in the toolbar, users can click this button to disable the visual editor and edit the HTML source directly. After toggling back, the visual editor uses the HTML tags allowed via plugin configuration (and not explicity disallowed by filters) to format the text. Tags not enabled via plugin configuration will be stripped out of the HTML source when the user toggles back to the text editor.') . '</dd>'; - $output .= '<dt>' . t('Developing CKEditor 5 plugins in Drupal') . '</dt>'; - $output .= '<dd>' . t('See the <a href=":dev_docs_url">online documentation</a> for detailed information on developing CKEditor 5 plugins for use in Drupal.', [ + $output .= '<dt>' . $this->t('Configuring the toolbar') . '</dt>'; + $output .= '<dd>' . $this->t('When CKEditor 5 is chosen from the <em>Text editor</em> drop-down menu, its toolbar configuration is displayed. You can add and remove buttons from the <em>Active toolbar</em> by dragging and dropping them. Separators and rows can be added to organize the buttons.') . '</dd>'; + $output .= '<dt>' . $this->t('Filtering HTML content') . '</dt>'; + $output .= '<dd>' . $this->t("Unlike other text editors, plugin configuration determines the tags and attributes allowed in text formats using CKEditor 5. If using the <em>Limit allowed HTML tags and correct faulty HTML</em> filter, this filter's values will be automatically set based on enabled plugins and toolbar items."); + $output .= '<dt>' . $this->t('Toggling between formatted text and HTML source') . '</dt>'; + $output .= '<dd>' . $this->t('If the <em>Source</em> button is available in the toolbar, users can click this button to disable the visual editor and edit the HTML source directly. After toggling back, the visual editor uses the HTML tags allowed via plugin configuration (and not explicity disallowed by filters) to format the text. Tags not enabled via plugin configuration will be stripped out of the HTML source when the user toggles back to the text editor.') . '</dd>'; + $output .= '<dt>' . $this->t('Developing CKEditor 5 plugins in Drupal') . '</dt>'; + $output .= '<dd>' . $this->t('See the <a href=":dev_docs_url">online documentation</a> for detailed information on developing CKEditor 5 plugins for use in Drupal.', [ ':dev_docs_url' => 'https://www.drupal.org/docs/contributed-modules/ckeditor-5/plugin-and-contrib-module-development', ]) . '</dd>'; $output .= '</dd>'; - $output .= '<dt>' . t('Accessibility features') . '</dt>'; - $output .= '<dd>' . t('The built in WYSIWYG editor (CKEditor 5) comes with a number of accessibility features. CKEditor 5 comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', [ + $output .= '<dt>' . $this->t('Accessibility features') . '</dt>'; + $output .= '<dd>' . $this->t('The built in WYSIWYG editor (CKEditor 5) comes with a number of accessibility features. CKEditor 5 comes with built in <a href=":shortcuts">keyboard shortcuts</a>, which can be beneficial for both power users and keyboard only users.', [ ':shortcuts' => 'https://ckeditor.com/docs/ckeditor5/latest/features/keyboard-support.html', ]) . '</dd>'; - $output .= '<dt>' . t('Generating accessible content') . '</dt>'; + $output .= '<dt>' . $this->t('Generating accessible content') . '</dt>'; $output .= '<dd>'; $output .= '<ul>'; - $output .= '<li>' . t('HTML tables can be created with table headers and caption/summary elements.') . '</li>'; - $output .= '<li>' . t('Alt text is required by default on images added through CKEditor (note that this can be overridden).') . '</li>'; - $output .= '<li>' . t('Semantic HTML5 figure/figcaption are available to add captions to images.') . '</li>'; - $output .= '<li>' . t('To support multilingual page content, CKEditor 5 can be configured to include a language button in the toolbar.') . '</li>'; + $output .= '<li>' . $this->t('HTML tables can be created with table headers and caption/summary elements.') . '</li>'; + $output .= '<li>' . $this->t('Alt text is required by default on images added through CKEditor (note that this can be overridden).') . '</li>'; + $output .= '<li>' . $this->t('Semantic HTML5 figure/figcaption are available to add captions to images.') . '</li>'; + $output .= '<li>' . $this->t('To support multilingual page content, CKEditor 5 can be configured to include a language button in the toolbar.') . '</li>'; $output .= '</ul>'; $output .= '</dd>'; $output .= '</dl>'; - $output .= '<h3 id="migration-settings">' . t('Migrating an Existing Text Format to CKEditor 5') . '</h2>'; - $output .= '<p>' . t('When switching an existing text format to use CKEditor 5, an automatic process is initiated that helps text formats switching to CKEditor 5 from CKEditor 4 (or no text editor) to do so with minimal effort and zero data loss.') . '</p>'; - $output .= '<p>' . t("This process is designed for there to be no data loss risk in switching to CKEditor 5. However some of your editor's functionality may not be 100% equivalent to what was available previously. In most cases, these changes are minimal. After the process completes, status and/or warning messages will summarize any changes that occurred, and more detailed information will be available in the site's logs.") . '</p>'; - $output .= '<p>' . t('CKEditor 5 will attempt to enable plugins that provide equivalent toolbar items to those used prior to switching to CKEditor 5. All core CKEditor 4 plugins and many popular contrib plugins already have CKEditor 5 equivalents. In some cases, functionality that required contrib modules is now built into CKEditor 5. In instances where a plugin does not have an equivalent, no data loss will occur but elements previously provided via the plugin may need to be added manually as HTML via source editing.') . '</p>'; - $output .= '<h4>' . t('Additional migration considerations for text formats with restricted HTML') . '</h4>'; + $output .= '<h3 id="migration-settings">' . $this->t('Migrating an Existing Text Format to CKEditor 5') . '</h2>'; + $output .= '<p>' . $this->t('When switching an existing text format to use CKEditor 5, an automatic process is initiated that helps text formats switching to CKEditor 5 from CKEditor 4 (or no text editor) to do so with minimal effort and zero data loss.') . '</p>'; + $output .= '<p>' . $this->t("This process is designed for there to be no data loss risk in switching to CKEditor 5. However some of your editor's functionality may not be 100% equivalent to what was available previously. In most cases, these changes are minimal. After the process completes, status and/or warning messages will summarize any changes that occurred, and more detailed information will be available in the site's logs.") . '</p>'; + $output .= '<p>' . $this->t('CKEditor 5 will attempt to enable plugins that provide equivalent toolbar items to those used prior to switching to CKEditor 5. All core CKEditor 4 plugins and many popular contrib plugins already have CKEditor 5 equivalents. In some cases, functionality that required contrib modules is now built into CKEditor 5. In instances where a plugin does not have an equivalent, no data loss will occur but elements previously provided via the plugin may need to be added manually as HTML via source editing.') . '</p>'; + $output .= '<h4>' . $this->t('Additional migration considerations for text formats with restricted HTML') . '</h4>'; $output .= '<dl>'; - $output .= '<dt>' . t('The “Allowed HTML tags" field in the “Limit allowed HTML tags and correct Faulty HTML" filter is now read-only') . '</dt>'; - $output .= '<dd>' . t('This field accurately represents the tags/attributes allowed by a text format, but the allowed tags are based on which plugins are enabled and how they are configured. For example, enabling the Underline plugin adds the <u> tag to “Allowed HTML tags".') . '</dd>'; - $output .= '<dt id="required-tags">' . t('The <p> and <br > tags will be automatically added to your text format.') . '</dt>'; - $output .= '<dd>' . t('CKEditor 5 requires the <p> and <br > tags to achieve basic functionality. They will be automatically added to “Allowed HTML tags" on formats that previously did not allow them.') . '</dd>'; - $output .= '<dt id="source-editing">' . t('Tags/attributes that are not explicitly supported by any plugin are supported by Source Editing') . '</dt>'; - $output .= '<dd>' . t('When a necessary tag/attribute is not directly supported by an available plugin, the "Source Editing" plugin is enabled. This plugin is typically used for by passing the CKEditor 5 UI and editing contents as HTML source. In the settings for Source Editing, tags/attributes that aren\'t available via other plugins are added to Source Editing\'s "Manually editable HTML tags" setting so they are supported by the text format.') . '</dd>'; + $output .= '<dt>' . $this->t('The “Allowed HTML tags" field in the “Limit allowed HTML tags and correct Faulty HTML" filter is now read-only') . '</dt>'; + $output .= '<dd>' . $this->t('This field accurately represents the tags/attributes allowed by a text format, but the allowed tags are based on which plugins are enabled and how they are configured. For example, enabling the Underline plugin adds the <u> tag to “Allowed HTML tags".') . '</dd>'; + $output .= '<dt id="required-tags">' . $this->t('The <p> and <br > tags will be automatically added to your text format.') . '</dt>'; + $output .= '<dd>' . $this->t('CKEditor 5 requires the <p> and <br > tags to achieve basic functionality. They will be automatically added to “Allowed HTML tags" on formats that previously did not allow them.') . '</dd>'; + $output .= '<dt id="source-editing">' . $this->t('Tags/attributes that are not explicitly supported by any plugin are supported by Source Editing') . '</dt>'; + $output .= '<dd>' . $this->t('When a necessary tag/attribute is not directly supported by an available plugin, the "Source Editing" plugin is enabled. This plugin is typically used for by passing the CKEditor 5 UI and editing contents as HTML source. In the settings for Source Editing, tags/attributes that aren\'t available via other plugins are added to Source Editing\'s "Manually editable HTML tags" setting so they are supported by the text format.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -114,7 +117,7 @@ public function formFilterFormatFormAlter(array &$form, FormStateInterface $form // being validated. $filter_allowed_html['#attributes']['readonly'] = TRUE; $filter_allowed_html['#wrapper_attributes']['class'][] = 'form-disabled'; - $filter_allowed_html['#description'] = t('With CKEditor 5 this is a + $filter_allowed_html['#description'] = $this->t('With CKEditor 5 this is a read-only field. The allowed HTML tags and attributes are determined by the CKEditor 5 configuration. Manually removing tags would break enabled functionality, and any manually added tags would be removed by diff --git a/core/modules/comment/src/Hook/CommentHooks.php b/core/modules/comment/src/Hook/CommentHooks.php index e33586e82065808dee02f2c2c78bc06492b8175c..67dcbd6c6e6eed78460c702edafe385754b610f1 100644 --- a/core/modules/comment/src/Hook/CommentHooks.php +++ b/core/modules/comment/src/Hook/CommentHooks.php @@ -4,6 +4,7 @@ use Drupal\Core\Field\FieldTypeCategoryManagerInterface; use Drupal\Core\Entity\Entity\EntityViewMode; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\UserInterface; use Drupal\user\RoleInterface; use Drupal\Core\Form\FormStateInterface; @@ -24,6 +25,8 @@ */ class CommentHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -31,12 +34,12 @@ class CommentHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.comment': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href=":comment">online documentation for the Comment module</a>.', [':comment' => 'https://www.drupal.org/documentation/modules/comment']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Comment module allows users to comment on site content, set commenting defaults and permissions, and moderate comments. For more information, see the <a href=":comment">online documentation for the Comment module</a>.', [':comment' => 'https://www.drupal.org/documentation/modules/comment']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Enabling commenting') . '</dt>'; - $output .= '<dd>' . t('Comment functionality can be enabled for any entity sub-type (for example, a <a href=":content-type">content type</a>) by adding a <em>Comments</em> field on its <em>Manage fields page</em>. Adding or removing commenting for an entity through the user interface requires the <a href=":field_ui">Field UI</a> module to be installed, even though the commenting functionality works without it. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', [ + $output .= '<dt>' . $this->t('Enabling commenting') . '</dt>'; + $output .= '<dd>' . $this->t('Comment functionality can be enabled for any entity sub-type (for example, a <a href=":content-type">content type</a>) by adding a <em>Comments</em> field on its <em>Manage fields page</em>. Adding or removing commenting for an entity through the user interface requires the <a href=":field_ui">Field UI</a> module to be installed, even though the commenting functionality works without it. For more information on fields and entities, see the <a href=":field">Field module help page</a>.', [ ':content-type' => \Drupal::moduleHandler()->moduleExists('node') ? Url::fromRoute('entity.node_type.collection')->toString() : '#', ':field' => Url::fromRoute('help.page', [ 'name' => 'field', @@ -45,16 +48,16 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Configuring commenting settings') . '</dt>'; - $output .= '<dd>' . t('Commenting settings can be configured by editing the <em>Comments</em> field on the <em>Manage fields page</em> of an entity type if the <em>Field UI module</em> is installed. Configuration includes the label of the comments field, the number of comments to be displayed, and whether they are shown in threaded list. Commenting can be configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. Changing this configuration for an entity type will not change existing entity items.') . '</dd>'; - $output .= '<dt>' . t('Overriding default settings') . '</dt>'; - $output .= '<dd>' . t('Users with the appropriate permissions can override the default commenting settings of an entity type when they create an item of that type.') . '</dd>'; - $output .= '<dt>' . t('Adding comment types') . '</dt>'; - $output .= '<dd>' . t('Additional <em>comment types</em> can be created per entity sub-type and added on the <a href=":field">Comment types page</a>. If there are multiple comment types available you can select the appropriate one after adding a <em>Comments field</em>.', [ + $output .= '<dt>' . $this->t('Configuring commenting settings') . '</dt>'; + $output .= '<dd>' . $this->t('Commenting settings can be configured by editing the <em>Comments</em> field on the <em>Manage fields page</em> of an entity type if the <em>Field UI module</em> is installed. Configuration includes the label of the comments field, the number of comments to be displayed, and whether they are shown in threaded list. Commenting can be configured as: <em>Open</em> to allow new comments, <em>Closed</em> to view existing comments, but prevent new comments, or <em>Hidden</em> to hide existing comments and prevent new comments. Changing this configuration for an entity type will not change existing entity items.') . '</dd>'; + $output .= '<dt>' . $this->t('Overriding default settings') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the appropriate permissions can override the default commenting settings of an entity type when they create an item of that type.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding comment types') . '</dt>'; + $output .= '<dd>' . $this->t('Additional <em>comment types</em> can be created per entity sub-type and added on the <a href=":field">Comment types page</a>. If there are multiple comment types available you can select the appropriate one after adding a <em>Comments field</em>.', [ ':field' => Url::fromRoute('entity.comment_type.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Approving and managing comments') . '</dt>'; - $output .= '<dd>' . t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href=":comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href=":admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', [ + $output .= '<dt>' . $this->t('Approving and managing comments') . '</dt>'; + $output .= '<dd>' . $this->t('Comments from users who have the <em>Skip comment approval</em> permission are published immediately. All other comments are placed in the <a href=":comment-approval">Unapproved comments</a> queue, until a user who has permission to <em>Administer comments and comment settings</em> publishes or deletes them. Published comments can be bulk managed on the <a href=":admin-comment">Published comments</a> administration page. When a comment has no replies, it remains editable by its author, as long as the author has <em>Edit own comments</em> permission.', [ ':comment-approval' => Url::fromRoute('comment.admin_approval')->toString(), ':admin-comment' => Url::fromRoute('comment.admin')->toString(), ]) . '</dd>'; @@ -62,7 +65,7 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.comment_type.collection': - $output = '<p>' . t('This page provides a list of all comment types on the site and allows you to manage the fields, form and display settings for each.') . '</p>'; + $output = '<p>' . $this->t('This page provides a list of all comment types on the site and allows you to manage the fields, form and display settings for each.') . '</p>'; return $output; } } @@ -77,15 +80,15 @@ public function entityExtraFieldInfo(): array { $return['comment'][$comment_type->id()] = [ 'form' => [ 'author' => [ - 'label' => t('Author'), - 'description' => t('Author textfield'), + 'label' => $this->t('Author'), + 'description' => $this->t('Author textfield'), 'weight' => -2, ], ], ]; $return['comment'][$comment_type->id()]['display']['links'] = [ - 'label' => t('Links'), - 'description' => t('Comment operation links'), + 'label' => $this->t('Links'), + 'description' => $this->t('Comment operation links'), 'weight' => 100, 'visible' => TRUE, ]; diff --git a/core/modules/comment/src/Hook/CommentTokensHooks.php b/core/modules/comment/src/Hook/CommentTokensHooks.php index 68696eee760b4a5a770f624ef6886bcd214f1ba0..7d7e9d0c03f51d6b6081da058d2fb8513e11ef20 100644 --- a/core/modules/comment/src/Hook/CommentTokensHooks.php +++ b/core/modules/comment/src/Hook/CommentTokensHooks.php @@ -8,20 +8,23 @@ use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for comment. */ class CommentTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $type = [ - 'name' => t('Comments'), - 'description' => t('Tokens for comments posted on the site.'), + 'name' => $this->t('Comments'), + 'description' => $this->t('Tokens for comments posted on the site.'), 'needs-data' => 'comment', ]; $tokens = []; @@ -35,68 +38,68 @@ public function tokenInfo(): array { $token_type = $entity_type_id == 'taxonomy_term' ? 'term' : $entity_type_id; // @todo Make this work per field. See https://www.drupal.org/node/2031903. $tokens[$token_type]['comment-count'] = [ - 'name' => t("Comment count"), - 'description' => t("The number of comments posted on an entity."), + 'name' => $this->t("Comment count"), + 'description' => $this->t("The number of comments posted on an entity."), ]; $tokens[$token_type]['comment-count-new'] = [ - 'name' => t("New comment count"), - 'description' => t("The number of comments posted on an entity since the reader last viewed it."), + 'name' => $this->t("New comment count"), + 'description' => $this->t("The number of comments posted on an entity since the reader last viewed it."), ]; } } // Core comment tokens - $comment['cid'] = ['name' => t("Comment ID"), 'description' => t("The unique ID of the comment.")]; - $comment['uuid'] = ['name' => t('UUID'), 'description' => t("The UUID of the comment.")]; + $comment['cid'] = ['name' => $this->t("Comment ID"), 'description' => $this->t("The unique ID of the comment.")]; + $comment['uuid'] = ['name' => $this->t('UUID'), 'description' => $this->t("The UUID of the comment.")]; $comment['hostname'] = [ - 'name' => t("IP Address"), - 'description' => t("The IP address of the computer the comment was posted from."), + 'name' => $this->t("IP Address"), + 'description' => $this->t("The IP address of the computer the comment was posted from."), ]; $comment['mail'] = [ - 'name' => t("Email address"), - 'description' => t("The email address left by the comment author."), + 'name' => $this->t("Email address"), + 'description' => $this->t("The email address left by the comment author."), ]; $comment['homepage'] = [ - 'name' => t("Home page"), - 'description' => t("The home page URL left by the comment author."), + 'name' => $this->t("Home page"), + 'description' => $this->t("The home page URL left by the comment author."), ]; - $comment['title'] = ['name' => t("Title"), 'description' => t("The title of the comment.")]; + $comment['title'] = ['name' => $this->t("Title"), 'description' => $this->t("The title of the comment.")]; $comment['body'] = [ - 'name' => t("Content"), - 'description' => t("The formatted content of the comment itself."), + 'name' => $this->t("Content"), + 'description' => $this->t("The formatted content of the comment itself."), ]; $comment['langcode'] = [ - 'name' => t('Language code'), - 'description' => t('The language code of the language the comment is written in.'), + 'name' => $this->t('Language code'), + 'description' => $this->t('The language code of the language the comment is written in.'), ]; - $comment['url'] = ['name' => t("URL"), 'description' => t("The URL of the comment.")]; + $comment['url'] = ['name' => $this->t("URL"), 'description' => $this->t("The URL of the comment.")]; $comment['edit-url'] = [ - 'name' => t("Edit URL"), - 'description' => t("The URL of the comment's edit page."), + 'name' => $this->t("Edit URL"), + 'description' => $this->t("The URL of the comment's edit page."), ]; // Chained tokens for comments $comment['created'] = [ - 'name' => t("Date created"), - 'description' => t("The date the comment was posted."), + 'name' => $this->t("Date created"), + 'description' => $this->t("The date the comment was posted."), 'type' => 'date', ]; $comment['changed'] = [ - 'name' => t("Date changed"), - 'description' => t("The date the comment was most recently updated."), + 'name' => $this->t("Date changed"), + 'description' => $this->t("The date the comment was most recently updated."), 'type' => 'date', ]; $comment['parent'] = [ - 'name' => t("Parent"), - 'description' => t("The comment's parent, if comment threading is active."), + 'name' => $this->t("Parent"), + 'description' => $this->t("The comment's parent, if comment threading is active."), 'type' => 'comment', ]; $comment['entity'] = [ - 'name' => t("Entity"), - 'description' => t("The entity the comment was posted to."), + 'name' => $this->t("Entity"), + 'description' => $this->t("The entity the comment was posted to."), 'type' => 'entity', ]; $comment['author'] = [ - 'name' => t("Author"), - 'description' => t("The author name of the comment."), + 'name' => $this->t("Author"), + 'description' => $this->t("The author name of the comment."), 'type' => 'user', ]; return ['types' => ['comment' => $type], 'tokens' => ['comment' => $comment] + $tokens]; diff --git a/core/modules/comment/src/Hook/CommentViewsHooks.php b/core/modules/comment/src/Hook/CommentViewsHooks.php index 9ca89e72322ef8344110c27e630e0bc3842f4125..fce0814b213831586e79cd1103609904a21ac4a2 100644 --- a/core/modules/comment/src/Hook/CommentViewsHooks.php +++ b/core/modules/comment/src/Hook/CommentViewsHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for comment. */ class CommentViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data_alter(). */ @@ -18,8 +21,8 @@ public function viewsDataAlter(&$data): void { // New comments are only supported for node table because it requires the // history table. $data['node']['new_comments'] = [ - 'title' => t('New comments'), - 'help' => t('The number of new comments on the node.'), + 'title' => $this->t('New comments'), + 'help' => $this->t('The number of new comments on the node.'), 'field' => [ 'id' => 'node_new_comments', 'no group by' => TRUE, @@ -36,8 +39,8 @@ public function viewsDataAlter(&$data): void { if ($fields) { $data[$base_table]['comments_link'] = [ 'field' => [ - 'title' => t('Add comment link'), - 'help' => t('Display the standard add comment link used on regular @entity_type, which will only display if the viewing user has access to add a comment.', $args), + 'title' => $this->t('Add comment link'), + 'help' => $this->t('Display the standard add comment link used on regular @entity_type, which will only display if the viewing user has access to add a comment.', $args), 'id' => 'comment_entity_link', ], ]; @@ -46,8 +49,8 @@ public function viewsDataAlter(&$data): void { $table = $entity_type->getBaseTable(); } $data[$table]['uid_touch'] = [ - 'title' => t('User posted or commented'), - 'help' => t('Display nodes only if a user posted the @entity_type or commented on the @entity_type.', $args), + 'title' => $this->t('User posted or commented'), + 'help' => $this->t('Display nodes only if a user posted the @entity_type or commented on the @entity_type.', $args), 'argument' => [ 'field' => 'uid', 'name table' => 'users_field_data', @@ -68,13 +71,13 @@ public function viewsDataAlter(&$data): void { ]; foreach ($fields as $field_name => $field) { $data[$base_table][$field_name . '_cid'] = [ - 'title' => t('Comments of the @entity_type using field: @field_name', $args + [ + 'title' => $this->t('Comments of the @entity_type using field: @field_name', $args + [ '@field_name' => $field_name, ]), - 'help' => t('Relate all comments on the @entity_type. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.', $args), + 'help' => $this->t('Relate all comments on the @entity_type. This will create 1 duplicate record for every comment. Usually if you need this it is better to create a comment view.', $args), 'relationship' => [ - 'group' => t('Comment'), - 'label' => t('Comments'), + 'group' => $this->t('Comment'), + 'label' => $this->t('Comments'), 'base' => 'comment_field_data', 'base field' => 'entity_id', 'relationship field' => $entity_type->getKey('id'), diff --git a/core/modules/config/src/Hook/ConfigHooks.php b/core/modules/config/src/Hook/ConfigHooks.php index da61458be8b8685851fc87992c287fdfe98cb382..1fafec387a7720d2cb87834e4dd76b83322af910 100644 --- a/core/modules/config/src/Hook/ConfigHooks.php +++ b/core/modules/config/src/Hook/ConfigHooks.php @@ -3,6 +3,7 @@ namespace Drupal\config\Hook; use Drupal\Core\StreamWrapper\StreamWrapperManager; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class ConfigHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -20,22 +23,22 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.config': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Configuration Manager module provides a user interface for importing and exporting configuration changes between installations of your website in different environments. Configuration is stored in YAML format. For more information, see the <a href=":url">online documentation for the Configuration Manager module</a>.', [':url' => 'https://www.drupal.org/documentation/administer/config']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Configuration Manager module provides a user interface for importing and exporting configuration changes between installations of your website in different environments. Configuration is stored in YAML format. For more information, see the <a href=":url">online documentation for the Configuration Manager module</a>.', [':url' => 'https://www.drupal.org/documentation/administer/config']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Exporting the full configuration') . '</dt>'; - $output .= '<dd>' . t('You can create and download an archive consisting of all your site\'s configuration exported as <em>*.yml</em> files on the <a href=":url">Export</a> page.', [':url' => Url::fromRoute('config.export_full')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Importing a full configuration') . '</dt>'; - $output .= '<dd>' . t('You can upload a full site configuration from an archive file on the <a href=":url">Import</a> page. When importing data from a different environment, the site and import files must have matching configuration values for UUID in the <em>system.site</em> configuration item. That means that your other environments should initially be set up as clones of the target site. Migrations are not supported.', [':url' => Url::fromRoute('config.import_full')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Synchronizing configuration') . '</dt>'; - $output .= '<dd>' . t('You can review differences between the active configuration and an imported configuration archive on the <a href=":synchronize">Synchronize</a> page to ensure that the changes are as expected, before finalizing the import. The Synchronize page also shows configuration items that would be added or removed.', [':synchronize' => Url::fromRoute('config.sync')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Exporting a single configuration item') . '</dt>'; - $output .= '<dd>' . t('You can export a single configuration item by selecting a <em>Configuration type</em> and <em>Configuration name</em> on the <a href=":single-export">Single export</a> page. The configuration and its corresponding <em>*.yml file name</em> are then displayed on the page for you to copy.', [ + $output .= '<dt>' . $this->t('Exporting the full configuration') . '</dt>'; + $output .= '<dd>' . $this->t('You can create and download an archive consisting of all your site\'s configuration exported as <em>*.yml</em> files on the <a href=":url">Export</a> page.', [':url' => Url::fromRoute('config.export_full')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Importing a full configuration') . '</dt>'; + $output .= '<dd>' . $this->t('You can upload a full site configuration from an archive file on the <a href=":url">Import</a> page. When importing data from a different environment, the site and import files must have matching configuration values for UUID in the <em>system.site</em> configuration item. That means that your other environments should initially be set up as clones of the target site. Migrations are not supported.', [':url' => Url::fromRoute('config.import_full')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Synchronizing configuration') . '</dt>'; + $output .= '<dd>' . $this->t('You can review differences between the active configuration and an imported configuration archive on the <a href=":synchronize">Synchronize</a> page to ensure that the changes are as expected, before finalizing the import. The Synchronize page also shows configuration items that would be added or removed.', [':synchronize' => Url::fromRoute('config.sync')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Exporting a single configuration item') . '</dt>'; + $output .= '<dd>' . $this->t('You can export a single configuration item by selecting a <em>Configuration type</em> and <em>Configuration name</em> on the <a href=":single-export">Single export</a> page. The configuration and its corresponding <em>*.yml file name</em> are then displayed on the page for you to copy.', [ ':single-export' => Url::fromRoute('config.export_single')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Importing a single configuration item') . '</dt>'; - $output .= '<dd>' . t('You can import a single configuration item by pasting it in YAML format into the form on the <a href=":single-import">Single import</a> page.', [ + $output .= '<dt>' . $this->t('Importing a single configuration item') . '</dt>'; + $output .= '<dd>' . $this->t('You can import a single configuration item by pasting it in YAML format into the form on the <a href=":single-import">Single import</a> page.', [ ':single-import' => Url::fromRoute('config.import_single')->toString(), ]) . '</dd>'; $output .= '</dl>'; @@ -43,27 +46,27 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'config.sync': $output = ''; - $output .= '<p>' . t('Compare the configuration uploaded to your sync directory with the active configuration before completing the import.') . '</p>'; + $output .= '<p>' . $this->t('Compare the configuration uploaded to your sync directory with the active configuration before completing the import.') . '</p>'; return $output; case 'config.export_full': $output = ''; - $output .= '<p>' . t('Export and download the full configuration of this site as a gzipped tar file.') . '</p>'; + $output .= '<p>' . $this->t('Export and download the full configuration of this site as a gzipped tar file.') . '</p>'; return $output; case 'config.import_full': $output = ''; - $output .= '<p>' . t('Upload a full site configuration archive to the sync directory. It can then be compared and imported on the Synchronize page.') . '</p>'; + $output .= '<p>' . $this->t('Upload a full site configuration archive to the sync directory. It can then be compared and imported on the Synchronize page.') . '</p>'; return $output; case 'config.export_single': $output = ''; - $output .= '<p>' . t('Choose a configuration item to display its YAML structure.') . '</p>'; + $output .= '<p>' . $this->t('Choose a configuration item to display its YAML structure.') . '</p>'; return $output; case 'config.import_single': $output = ''; - $output .= '<p>' . t('Import a single configuration item by pasting its YAML structure into the text field.') . '</p>'; + $output .= '<p>' . $this->t('Import a single configuration item by pasting its YAML structure into the text field.') . '</p>'; return $output; } } diff --git a/core/modules/config_translation/src/Hook/ConfigTranslationHooks.php b/core/modules/config_translation/src/Hook/ConfigTranslationHooks.php index f79a60cef490327f1b6ccecc35273f0cdd016668..f1fd2434efcac8ac65f6dfd36611178d3aa3dee9 100644 --- a/core/modules/config_translation/src/Hook/ConfigTranslationHooks.php +++ b/core/modules/config_translation/src/Hook/ConfigTranslationHooks.php @@ -2,6 +2,7 @@ namespace Drupal\config_translation\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldConfigInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface; @@ -14,6 +15,8 @@ */ class ConfigTranslationHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,8 +25,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.config_translation': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href=":language">Language</a>, <a href=":content-translation">Content Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":doc_url">online documentation for the Configuration Translation module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href=":language">Language</a>, <a href=":content-translation">Content Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":doc_url">online documentation for the Configuration Translation module</a>.', [ ':doc_url' => 'https://www.drupal.org/documentation/modules/config_translation', ':config' => Url::fromRoute('help.page', [ 'name' => 'config', @@ -38,25 +41,25 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'content_translation', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Enabling translation') . '</dt>'; - $output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [ + $output .= '<dt>' . $this->t('Enabling translation') . '</dt>'; + $output .= '<dd>' . $this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [ ':url' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Translating configuration text') . '</dt>'; - $output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href=":translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', [ + $output .= '<dt>' . $this->t('Translating configuration text') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href=":translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', [ ':translation-page' => Url::fromRoute('config_translation.mapper_list')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Translating date formats') . '</dt>'; - $output .= '<dd>' . t('You can choose to translate date formats on the <a href=":translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', [ + $output .= '<dt>' . $this->t('Translating date formats') . '</dt>'; + $output .= '<dd>' . $this->t('You can choose to translate date formats on the <a href=":translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', [ ':translation-page' => Url::fromRoute('config_translation.mapper_list')->toString(), ]) . '</dd>'; $output .= '</dl>'; return $output; case 'config_translation.mapper_list': - $output = '<p>' . t('This page lists all configuration items on your site that have translatable text, like your site name, role names, etc.') . '</p>'; + $output = '<p>' . $this->t('This page lists all configuration items on your site that have translatable text, like your site name, role names, etc.') . '</p>'; return $output; } } @@ -186,7 +189,7 @@ public function entityOperation(EntityInterface $entity): array { $link_template = "config-translation-overview.{$entity->getTargetEntityTypeId()}"; } $operations['translate'] = [ - 'title' => t('Translate'), + 'title' => $this->t('Translate'), 'weight' => 50, 'url' => $entity->toUrl($link_template), ]; diff --git a/core/modules/contact/src/Hook/ContactHooks.php b/core/modules/contact/src/Hook/ContactHooks.php index 9aaab81a707bc41d4157e2f8bf17ee64b9b6c787..16fb53327227c61d32d0f86189ff430a55b6195d 100644 --- a/core/modules/contact/src/Hook/ContactHooks.php +++ b/core/modules/contact/src/Hook/ContactHooks.php @@ -4,6 +4,7 @@ use Drupal\contact\Plugin\rest\resource\ContactMessageResource; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\Entity\User; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -14,6 +15,8 @@ */ class ContactHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -25,18 +28,18 @@ public function help($route_name, RouteMatchInterface $route_match) { $block_page = \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#'; $contact_page = Url::fromRoute('entity.contact_form.collection')->toString(); $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Contact module allows visitors to contact registered users on your site, using the personal contact form, and also allows you to set up site-wide contact forms. For more information, see the <a href=":contact">online documentation for the Contact module</a>.', [':contact' => 'https://www.drupal.org/documentation/modules/contact']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Contact module allows visitors to contact registered users on your site, using the personal contact form, and also allows you to set up site-wide contact forms. For more information, see the <a href=":contact">online documentation for the Contact module</a>.', [':contact' => 'https://www.drupal.org/documentation/modules/contact']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Using the personal contact form') . '</dt>'; - $output .= '<dd>' . t("Site visitors can email registered users on your site by using the personal contact form, without knowing or learning the email address of the recipient. When a site visitor is viewing a user profile, the viewer will see a <em>Contact</em> tab or link, which leads to the personal contact form. The personal contact link is not shown when you are viewing your own profile, and users must have both <em>View user information</em> (to see user profiles) and <em>Use users' personal contact forms</em> permission to see the link. The user whose profile is being viewed must also have their personal contact form enabled (this is a user account setting); viewers with <em>Administer users</em> permission can bypass this setting.") . '</dd>'; - $output .= '<dt>' . t('Configuring contact forms') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":contact_admin">Contact forms page</a>, you can configure the fields and display of the personal contact form, and you can set up one or more site-wide contact forms. Each site-wide contact form has a machine name, a label, and one or more defined recipients; when a site visitor submits the form, the field values are sent to those recipients.', [':contact_admin' => $contact_page]) . '</dd>'; - $output .= '<dt>' . t('Linking to contact forms') . '</dt>'; - $output .= '<dd>' . t('One site-wide contact form can be designated as the default contact form. If you choose to designate a default form, the <em>Contact</em> menu link in the <em>Footer</em> menu will link to it. You can modify this link from the <a href=":menu-settings">Menus page</a> if you have the Menu UI module installed. You can also create links to other contact forms; the URL for each form you have set up has format <em>contact/machine_name_of_form</em>.', [':menu-settings' => $menu_page]) . '</p>'; - $output .= '<dt>' . t('Adding content to contact forms') . '</dt>'; - $output .= '<dd>' . t('From the <a href=":contact_admin">Contact forms page</a>, you can configure the fields to be shown on contact forms, including their labels and help text. If you would like other content (such as text or images) to appear on a contact form, use a block. You can create and edit blocks on the <a href=":blocks">Block layout page</a>, if the Block module is installed.', [':blocks' => $block_page, ':contact_admin' => $contact_page]) . '</dd>'; + $output .= '<dt>' . $this->t('Using the personal contact form') . '</dt>'; + $output .= '<dd>' . $this->t("Site visitors can email registered users on your site by using the personal contact form, without knowing or learning the email address of the recipient. When a site visitor is viewing a user profile, the viewer will see a <em>Contact</em> tab or link, which leads to the personal contact form. The personal contact link is not shown when you are viewing your own profile, and users must have both <em>View user information</em> (to see user profiles) and <em>Use users' personal contact forms</em> permission to see the link. The user whose profile is being viewed must also have their personal contact form enabled (this is a user account setting); viewers with <em>Administer users</em> permission can bypass this setting.") . '</dd>'; + $output .= '<dt>' . $this->t('Configuring contact forms') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":contact_admin">Contact forms page</a>, you can configure the fields and display of the personal contact form, and you can set up one or more site-wide contact forms. Each site-wide contact form has a machine name, a label, and one or more defined recipients; when a site visitor submits the form, the field values are sent to those recipients.', [':contact_admin' => $contact_page]) . '</dd>'; + $output .= '<dt>' . $this->t('Linking to contact forms') . '</dt>'; + $output .= '<dd>' . $this->t('One site-wide contact form can be designated as the default contact form. If you choose to designate a default form, the <em>Contact</em> menu link in the <em>Footer</em> menu will link to it. You can modify this link from the <a href=":menu-settings">Menus page</a> if you have the Menu UI module installed. You can also create links to other contact forms; the URL for each form you have set up has format <em>contact/machine_name_of_form</em>.', [':menu-settings' => $menu_page]) . '</p>'; + $output .= '<dt>' . $this->t('Adding content to contact forms') . '</dt>'; + $output .= '<dd>' . $this->t('From the <a href=":contact_admin">Contact forms page</a>, you can configure the fields to be shown on contact forms, including their labels and help text. If you would like other content (such as text or images) to appear on a contact form, use a block. You can create and edit blocks on the <a href=":blocks">Block layout page</a>, if the Block module is installed.', [':blocks' => $block_page, ':contact_admin' => $contact_page]) . '</dd>'; $output .= '</dl>'; return $output; } @@ -58,25 +61,25 @@ public function entityTypeAlter(array &$entity_types) : void { public function entityExtraFieldInfo(): array { $fields = []; foreach (array_keys(\Drupal::service('entity_type.bundle.info')->getBundleInfo('contact_message')) as $bundle) { - $fields['contact_message'][$bundle]['form']['name'] = ['label' => t('Sender name'), 'description' => t('Text'), 'weight' => -50]; - $fields['contact_message'][$bundle]['form']['mail'] = ['label' => t('Sender email'), 'description' => t('Email'), 'weight' => -40]; + $fields['contact_message'][$bundle]['form']['name'] = ['label' => $this->t('Sender name'), 'description' => $this->t('Text'), 'weight' => -50]; + $fields['contact_message'][$bundle]['form']['mail'] = ['label' => $this->t('Sender email'), 'description' => $this->t('Email'), 'weight' => -40]; if ($bundle == 'personal') { - $fields['contact_message'][$bundle]['form']['recipient'] = ['label' => t('Recipient username'), 'description' => t('User'), 'weight' => -30]; + $fields['contact_message'][$bundle]['form']['recipient'] = ['label' => $this->t('Recipient username'), 'description' => $this->t('User'), 'weight' => -30]; } $fields['contact_message'][$bundle]['form']['preview'] = [ - 'label' => t('Preview sender message'), - 'description' => t('Preview'), + 'label' => $this->t('Preview sender message'), + 'description' => $this->t('Preview'), 'weight' => 40, ]; $fields['contact_message'][$bundle]['form']['copy'] = [ - 'label' => t('Send copy to sender'), - 'description' => t('Option'), + 'label' => $this->t('Send copy to sender'), + 'description' => $this->t('Option'), 'weight' => 50, ]; } $fields['user']['user']['form']['contact'] = [ - 'label' => t('Contact settings'), - 'description' => t('Contact module form element.'), + 'label' => $this->t('Contact settings'), + 'description' => $this->t('Contact module form element.'), 'weight' => 5, ]; return $fields; @@ -132,14 +135,14 @@ public function mail($key, &$message, $params): void { switch ($key) { case 'page_mail': case 'page_copy': - $message['subject'] .= t('[@form] @subject', $variables, $options); - $message['body'][] = t("@sender-name (@sender-url) sent a message using the contact form at @form-url.", $variables, $options); + $message['subject'] .= $this->t('[@form] @subject', $variables, $options); + $message['body'][] = $this->t("@sender-name (@sender-url) sent a message using the contact form at @form-url.", $variables, $options); $build = \Drupal::entityTypeManager()->getViewBuilder('contact_message')->view($contact_message, 'mail'); $message['body'][] = \Drupal::service('renderer')->renderInIsolation($build); break; case 'page_autoreply': - $message['subject'] .= t('[@form] @subject', $variables, $options); + $message['subject'] .= $this->t('[@form] @subject', $variables, $options); $message['body'][] = $params['contact_form']->getReply(); break; @@ -152,15 +155,15 @@ public function mail($key, &$message, $params): void { 'language' => $language, ])->toString(), ]; - $message['subject'] .= t('[@site-name] @subject', $variables, $options); - $message['body'][] = t('Hello @recipient-name,', $variables, $options); - $message['body'][] = t("@sender-name (@sender-url) has sent you a message via your contact form at @site-name.", $variables, $options); + $message['subject'] .= $this->t('[@site-name] @subject', $variables, $options); + $message['body'][] = $this->t('Hello @recipient-name,', $variables, $options); + $message['body'][] = $this->t("@sender-name (@sender-url) has sent you a message via your contact form at @site-name.", $variables, $options); // Only include the opt-out line in the original email and not in the // copy to the sender. Also exclude this if the email was sent from a // user administrator because they can always send emails even if the // contacted user has disabled their contact form. if ($key === 'user_mail' && !$params['sender']->hasPermission('administer users')) { - $message['body'][] = t("If you don't want to receive such messages, you can change your settings at @recipient-edit-url.", $variables, $options); + $message['body'][] = $this->t("If you don't want to receive such messages, you can change your settings at @recipient-edit-url.", $variables, $options); } $build = \Drupal::entityTypeManager()->getViewBuilder('contact_message')->view($contact_message, 'mail'); $message['body'][] = \Drupal::service('renderer')->renderInIsolation($build); @@ -179,7 +182,7 @@ public function mail($key, &$message, $params): void { public function formUserFormAlter(&$form, FormStateInterface $form_state) : void { $form['contact'] = [ '#type' => 'details', - '#title' => t('Contact settings'), + '#title' => $this->t('Contact settings'), '#open' => TRUE, '#weight' => 5, ]; @@ -189,9 +192,9 @@ public function formUserFormAlter(&$form, FormStateInterface $form_state) : void } $form['contact']['contact'] = [ '#type' => 'checkbox', - '#title' => t('Personal contact form'), + '#title' => $this->t('Personal contact form'), '#default_value' => $account_data ?? \Drupal::config('contact.settings')->get('user_default_enabled'), - '#description' => t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), + '#description' => $this->t('Allow other users to contact you via a personal contact form which keeps your email address hidden. Note that some privileged users such as site administrators are still able to contact you even if you choose to disable this feature.'), ]; $form['actions']['submit']['#submit'][] = 'contact_user_profile_form_submit'; } @@ -205,14 +208,14 @@ public function formUserFormAlter(&$form, FormStateInterface $form_state) : void public function formUserAdminSettingsAlter(&$form, FormStateInterface $form_state) : void { $form['contact'] = [ '#type' => 'details', - '#title' => t('Contact settings'), + '#title' => $this->t('Contact settings'), '#open' => TRUE, '#weight' => 0, ]; $form['contact']['contact_default_status'] = [ '#type' => 'checkbox', - '#title' => t('Enable the personal contact form by default for new users'), - '#description' => t('Changing this setting will not affect existing users.'), + '#title' => $this->t('Enable the personal contact form by default for new users'), + '#description' => $this->t('Changing this setting will not affect existing users.'), '#default_value' => \Drupal::configFactory()->getEditable('contact.settings')->get('user_default_enabled'), ]; // Add submit handler to save contact configuration. diff --git a/core/modules/contact/src/Hook/ContactViewsHooks.php b/core/modules/contact/src/Hook/ContactViewsHooks.php index 7fbfe26a63cf55096f7a1bc68a9a05acd291027d..f67399473de270af768a80a45cd029da004fd0e2 100644 --- a/core/modules/contact/src/Hook/ContactViewsHooks.php +++ b/core/modules/contact/src/Hook/ContactViewsHooks.php @@ -3,12 +3,15 @@ namespace Drupal\contact\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for contact. */ class ContactViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data_alter(). */ @@ -16,8 +19,8 @@ class ContactViewsHooks { public function viewsDataAlter(&$data): void { $data['users']['contact'] = [ 'field' => [ - 'title' => t('Contact link'), - 'help' => t('Provide a simple link to the user contact page.'), + 'title' => $this->t('Contact link'), + 'help' => $this->t('Provide a simple link to the user contact page.'), 'id' => 'contact_link', ], ]; diff --git a/core/modules/content_moderation/src/Hook/ContentModerationHooks.php b/core/modules/content_moderation/src/Hook/ContentModerationHooks.php index 6692a8b675b5059a8927105b67118d32116313da..ad2d2fe411de11c7e3a06a65aa39451b894e34c6 100644 --- a/core/modules/content_moderation/src/Hook/ContentModerationHooks.php +++ b/core/modules/content_moderation/src/Hook/ContentModerationHooks.php @@ -3,6 +3,7 @@ namespace Drupal\content_moderation\Hook; use Drupal\Core\Access\AccessResultInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\Plugin\views\filter\Broken; use Drupal\views\ViewExecutable; use Drupal\views\Views; @@ -34,6 +35,8 @@ */ class ContentModerationHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -43,17 +46,17 @@ public function help($route_name, RouteMatchInterface $route_match) { // Main module help for the content_moderation module. case 'help.page.content_moderation': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Content Moderation module allows you to expand on Drupal\'s "unpublished" and "published" states for content. It allows you to have a published version that is live, but have a separate working copy that is undergoing review before it is published. This is achieved by using <a href=":workflows">Workflows</a> to apply different states and transitions to entities as needed. For more information, see the <a href=":content_moderation">online documentation for the Content Moderation module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Content Moderation module allows you to expand on Drupal\'s "unpublished" and "published" states for content. It allows you to have a published version that is live, but have a separate working copy that is undergoing review before it is published. This is achieved by using <a href=":workflows">Workflows</a> to apply different states and transitions to entities as needed. For more information, see the <a href=":content_moderation">online documentation for the Content Moderation module</a>.', [ ':content_moderation' => 'https://www.drupal.org/documentation/modules/content_moderation', ':workflows' => Url::fromRoute('help.page', [ 'name' => 'workflows', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Applying workflows') . '</dt>'; - $output .= '<dd>' . t('Content Moderation allows you to apply <a href=":workflows">Workflows</a> to content, content blocks, and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a>, to provide more fine-grained publishing options. For example, a Basic page might have states such as Draft and Published, with allowed transitions such as Draft to Published (making the current revision "live"), and Published to Draft (making a new draft revision of published content).', [ + $output .= '<dt>' . $this->t('Applying workflows') . '</dt>'; + $output .= '<dd>' . $this->t('Content Moderation allows you to apply <a href=":workflows">Workflows</a> to content, content blocks, and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a>, to provide more fine-grained publishing options. For example, a Basic page might have states such as Draft and Published, with allowed transitions such as Draft to Published (making the current revision "live"), and Published to Draft (making a new draft revision of published content).', [ ':workflows' => Url::fromRoute('help.page', [ 'name' => 'workflows', ])->toString(), @@ -64,14 +67,14 @@ public function help($route_name, RouteMatchInterface $route_match) { if (\Drupal::moduleHandler()->moduleExists('views')) { $moderated_content_view = View::load('moderated_content'); if (isset($moderated_content_view) && $moderated_content_view->status() === TRUE) { - $output .= '<dt>' . t('Moderating content') . '</dt>'; - $output .= '<dd>' . t('You can view a list of content awaiting moderation on the <a href=":moderated">moderated content page</a>. This will show any content in an unpublished state, such as Draft or Archived, to help surface content that requires more work from content editors.', [ + $output .= '<dt>' . $this->t('Moderating content') . '</dt>'; + $output .= '<dd>' . $this->t('You can view a list of content awaiting moderation on the <a href=":moderated">moderated content page</a>. This will show any content in an unpublished state, such as Draft or Archived, to help surface content that requires more work from content editors.', [ ':moderated' => Url::fromRoute('view.moderated_content.moderated_content')->toString(), ]) . '</dd>'; } } - $output .= '<dt>' . t('Configure Content Moderation permissions') . '</dt>'; - $output .= '<dd>' . t('Each transition is exposed as a permission. If a user has the permission for a transition, they can use the transition to change the state of the content item, from Draft to Published.') . '</dd>'; + $output .= '<dt>' . $this->t('Configure Content Moderation permissions') . '</dt>'; + $output .= '<dd>' . $this->t('Each transition is exposed as a permission. If a user has the permission for a transition, they can use the transition to change the state of the content item, from Draft to Published.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/content_translation/src/Hook/ContentTranslationHooks.php b/core/modules/content_translation/src/Hook/ContentTranslationHooks.php index e25afd41636bf09cb810fd03517836af8551cbb3..69fb38b712040b5ab25a6d8b9adb41d7a108dc56 100644 --- a/core/modules/content_translation/src/Hook/ContentTranslationHooks.php +++ b/core/modules/content_translation/src/Hook/ContentTranslationHooks.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -22,6 +23,8 @@ */ class ContentTranslationHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -30,8 +33,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.content_translation': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Content Translation module allows you to translate content, comments, content blocks, taxonomy terms, users and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a>. Together with the modules <a href=":language">Language</a>, <a href=":config-trans">Configuration Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":translation-entity">online documentation for the Content Translation module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Content Translation module allows you to translate content, comments, content blocks, taxonomy terms, users and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a>. Together with the modules <a href=":language">Language</a>, <a href=":config-trans">Configuration Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":translation-entity">online documentation for the Content Translation module</a>.', [ ':locale' => \Drupal::moduleHandler()->moduleExists('locale') ? Url::fromRoute('help.page', [ 'name' => 'locale', ])->toString() : '#', @@ -46,31 +49,31 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'field', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Enabling translation') . '</dt>'; - $output .= '<dd>' . t('In order to translate content, the website must have at least two <a href=":url">languages</a>. When that is the case, you can enable translation for the desired content entities on the <a href=":translation-entity">Content language</a> page. When enabling translation you can choose the default language for content and decide whether to show the language selection field on the content editing forms.', [ + $output .= '<dt>' . $this->t('Enabling translation') . '</dt>'; + $output .= '<dd>' . $this->t('In order to translate content, the website must have at least two <a href=":url">languages</a>. When that is the case, you can enable translation for the desired content entities on the <a href=":translation-entity">Content language</a> page. When enabling translation you can choose the default language for content and decide whether to show the language selection field on the content editing forms.', [ ':url' => Url::fromRoute('entity.configurable_language.collection')->toString(), ':translation-entity' => Url::fromRoute('language.content_settings_page')->toString(), ':language-help' => Url::fromRoute('help.page', [ 'name' => 'language', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Enabling field translation') . '</dt>'; - $output .= '<dd>' . t('You can define which fields of a content entity can be translated. For example, you might want to translate the title and body field while leaving the image field untranslated. If you exclude a field from being translated, it will still show up in the content editing form, but any changes made to that field will be applied to <em>all</em> translations of that content.') . '</dd>'; - $output .= '<dt>' . t('Translating content') . '</dt>'; - $output .= '<dd>' . t('If translation is enabled you can translate a content entity via the Translate tab (or Translate link). The Translations page of a content entity gives an overview of the translation status for the current content and lets you add, edit, and delete its translations. This process is similar for every translatable content entity on your site.') . '</dd>'; - $output .= '<dt>' . t('Changing the source language for a translation') . '</dt>'; - $output .= '<dd>' . t('When you add a new translation, the original text you are translating is displayed in the edit form as the <em>source</em>. If at least one translation of the original content already exists when you add a new translation, you can choose either the original content (default) or one of the other translations as the source, using the select list in the Source language section. After saving the translation, the chosen source language is then listed on the Translate tab of the content.') . '</dd>'; - $output .= '<dt>' . t('Setting status of translations') . '</dt>'; - $output .= '<dd>' . t('If you edit a translation in one language you may want to set the status of the other translations as <em>out-of-date</em>. You can set this status by selecting the <em>Flag other translations as outdated</em> checkbox in the Translation section of the content editing form. The status will be visible on the Translations page.') . '</dd>'; + $output .= '<dt>' . $this->t('Enabling field translation') . '</dt>'; + $output .= '<dd>' . $this->t('You can define which fields of a content entity can be translated. For example, you might want to translate the title and body field while leaving the image field untranslated. If you exclude a field from being translated, it will still show up in the content editing form, but any changes made to that field will be applied to <em>all</em> translations of that content.') . '</dd>'; + $output .= '<dt>' . $this->t('Translating content') . '</dt>'; + $output .= '<dd>' . $this->t('If translation is enabled you can translate a content entity via the Translate tab (or Translate link). The Translations page of a content entity gives an overview of the translation status for the current content and lets you add, edit, and delete its translations. This process is similar for every translatable content entity on your site.') . '</dd>'; + $output .= '<dt>' . $this->t('Changing the source language for a translation') . '</dt>'; + $output .= '<dd>' . $this->t('When you add a new translation, the original text you are translating is displayed in the edit form as the <em>source</em>. If at least one translation of the original content already exists when you add a new translation, you can choose either the original content (default) or one of the other translations as the source, using the select list in the Source language section. After saving the translation, the chosen source language is then listed on the Translate tab of the content.') . '</dd>'; + $output .= '<dt>' . $this->t('Setting status of translations') . '</dt>'; + $output .= '<dd>' . $this->t('If you edit a translation in one language you may want to set the status of the other translations as <em>out-of-date</em>. You can set this status by selecting the <em>Flag other translations as outdated</em> checkbox in the Translation section of the content editing form. The status will be visible on the Translations page.') . '</dd>'; $output .= '</dl>'; return $output; case 'language.content_settings_page': $output = ''; if (!\Drupal::languageManager()->isMultilingual()) { - $output .= '<p>' . t('Before you can translate content, there must be at least two languages added on the <a href=":url">languages administration</a> page.', [ + $output .= '<p>' . $this->t('Before you can translate content, there must be at least two languages added on the <a href=":url">languages administration</a> page.', [ ':url' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</p>'; } @@ -299,7 +302,7 @@ public function entityOperation(EntityInterface $entity): array { $operations = []; if ($entity->hasLinkTemplate('drupal:content-translation-overview') && content_translation_translate_access($entity)->isAllowed()) { $operations['translate'] = [ - 'title' => t('Translate'), + 'title' => $this->t('Translate'), 'url' => $entity->toUrl('drupal:content-translation-overview'), 'weight' => 50, ]; @@ -323,8 +326,8 @@ public function viewsDataAlter(array &$data): void { $t_arguments = ['@entity_type_label' => $entity_type->getLabel()]; $data[$base_table]['translation_link'] = [ 'field' => [ - 'title' => t('Link to translate @entity_type_label', $t_arguments), - 'help' => t('Provide a translation link to the @entity_type_label.', $t_arguments), + 'title' => $this->t('Link to translate @entity_type_label', $t_arguments), + 'help' => $this->t('Provide a translation link to the @entity_type_label.', $t_arguments), 'id' => 'content_translation_link', ], ]; @@ -428,8 +431,8 @@ public function entityExtraFieldInfo(): array { foreach ($bundle_info_service->getBundleInfo($entity_type) as $bundle => $bundle_info) { if (\Drupal::service('content_translation.manager')->isEnabled($entity_type, $bundle)) { $extra[$entity_type][$bundle]['form']['translation'] = [ - 'label' => t('Translation'), - 'description' => t('Translation settings'), + 'label' => $this->t('Translation'), + 'description' => $this->t('Translation settings'), 'weight' => 10, ]; } @@ -447,7 +450,7 @@ public function formFieldConfigEditFormAlter(array &$form, FormStateInterface $f $bundle_is_translatable = \Drupal::service('content_translation.manager')->isEnabled($field->getTargetEntityTypeId(), $field->getTargetBundle()); $form['translatable'] = [ '#type' => 'checkbox', - '#title' => t('Users may translate this field'), + '#title' => $this->t('Users may translate this field'), '#default_value' => $field->isTranslatable(), '#weight' => -1, '#disabled' => !$bundle_is_translatable, @@ -456,7 +459,7 @@ public function formFieldConfigEditFormAlter(array &$form, FormStateInterface $f // Provide helpful pointers for administrators. if (\Drupal::currentUser()->hasPermission('administer content translation') && !$bundle_is_translatable) { $toggle_url = Url::fromRoute('language.content_settings_page', [], ['query' => \Drupal::destination()->getAsArray()])->toString(); - $form['translatable']['#description'] = t('To configure translation for this field, <a href=":language-settings-url">enable language support</a> for this type.', [':language-settings-url' => $toggle_url]); + $form['translatable']['#description'] = $this->t('To configure translation for this field, <a href=":language-settings-url">enable language support</a> for this type.', [':language-settings-url' => $toggle_url]); } if ($field->isTranslatable()) { \Drupal::moduleHandler()->loadInclude('content_translation', 'inc', 'content_translation.admin'); diff --git a/core/modules/contextual/src/Hook/ContextualHooks.php b/core/modules/contextual/src/Hook/ContextualHooks.php index afd97cb49f617f1d22e7bf4bcb12d6998044cfc9..f0d0c7efb9ab1555c9c3eff89a77c0b74db4d28d 100644 --- a/core/modules/contextual/src/Hook/ContextualHooks.php +++ b/core/modules/contextual/src/Hook/ContextualHooks.php @@ -3,6 +3,7 @@ namespace Drupal\contextual\Hook; use Drupal\Component\Serialization\Json; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class ContextualHooks { + use StringTranslationTrait; + /** * Implements hook_toolbar(). */ @@ -27,7 +30,7 @@ public function toolbar(): array { 'tab' => [ '#type' => 'html_tag', '#tag' => 'button', - '#value' => t('Edit'), + '#value' => $this->t('Edit'), '#attributes' => [ 'class' => [ 'toolbar-icon', @@ -76,28 +79,28 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.contextual': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Contextual links module gives users with the <em>Use contextual links</em> permission quick access to tasks associated with certain areas of pages on your site. For example, a menu displayed as a block has links to edit the menu and configure the block. For more information, see the <a href=":contextual">online documentation for the Contextual Links module</a>.', [':contextual' => 'https://www.drupal.org/docs/8/core/modules/contextual']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Contextual links module gives users with the <em>Use contextual links</em> permission quick access to tasks associated with certain areas of pages on your site. For example, a menu displayed as a block has links to edit the menu and configure the block. For more information, see the <a href=":contextual">online documentation for the Contextual Links module</a>.', [':contextual' => 'https://www.drupal.org/docs/8/core/modules/contextual']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Displaying contextual links') . '</dt>'; + $output .= '<dt>' . $this->t('Displaying contextual links') . '</dt>'; $output .= '<dd>'; - $output .= t('Contextual links for an area on a page are displayed using a contextual links button. There are two ways to make the contextual links button visible:'); + $output .= $this->t('Contextual links for an area on a page are displayed using a contextual links button. There are two ways to make the contextual links button visible:'); $output .= '<ol>'; $sample_picture = [ '#theme' => 'image', '#uri' => 'core/misc/icons/bebebe/pencil.svg', - '#alt' => t('contextual links button'), + '#alt' => $this->t('contextual links button'), ]; $sample_picture = \Drupal::service('renderer')->render($sample_picture); - $output .= '<li>' . t('Hovering over the area of interest will temporarily make the contextual links button visible (which looks like a pencil in most themes, and is normally displayed in the upper right corner of the area). The icon typically looks like this: @picture', ['@picture' => $sample_picture]) . '</li>'; - $output .= '<li>' . t('If you have the <a href=":toolbar">Toolbar module</a> installed, clicking the contextual links button in the toolbar (which looks like a pencil) will make all contextual links buttons on the page visible. Clicking this button again will toggle them to invisible.', [ + $output .= '<li>' . $this->t('Hovering over the area of interest will temporarily make the contextual links button visible (which looks like a pencil in most themes, and is normally displayed in the upper right corner of the area). The icon typically looks like this: @picture', ['@picture' => $sample_picture]) . '</li>'; + $output .= '<li>' . $this->t('If you have the <a href=":toolbar">Toolbar module</a> installed, clicking the contextual links button in the toolbar (which looks like a pencil) will make all contextual links buttons on the page visible. Clicking this button again will toggle them to invisible.', [ ':toolbar' => \Drupal::moduleHandler()->moduleExists('toolbar') ? Url::fromRoute('help.page', [ 'name' => 'toolbar', ])->toString() : '#', ]) . '</li>'; $output .= '</ol>'; - $output .= t('Once the contextual links button for the area of interest is visible, click the button to display the links.'); + $output .= $this->t('Once the contextual links button for the area of interest is visible, click the button to display the links.'); $output .= '</dd>'; $output .= '</dl>'; return $output; diff --git a/core/modules/contextual/src/Hook/ContextualViewsHooks.php b/core/modules/contextual/src/Hook/ContextualViewsHooks.php index 4ead3f6074779b8c19fa9db394d1129952d31006..21b8da1939ee3a9f9caaa8e07759c451357b8b76 100644 --- a/core/modules/contextual/src/Hook/ContextualViewsHooks.php +++ b/core/modules/contextual/src/Hook/ContextualViewsHooks.php @@ -3,20 +3,23 @@ namespace Drupal\contextual\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for contextual. */ class ContextualViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data_alter(). */ #[Hook('views_data_alter')] public function viewsDataAlter(&$data): void { $data['views']['contextual_links'] = [ - 'title' => t('Contextual Links'), - 'help' => t('Display fields in a contextual links menu.'), + 'title' => $this->t('Contextual Links'), + 'help' => $this->t('Display fields in a contextual links menu.'), 'field' => [ 'id' => 'contextual_links', ], diff --git a/core/modules/datetime/src/Hook/DatetimeHooks.php b/core/modules/datetime/src/Hook/DatetimeHooks.php index 2fe9e3eec71fba0d8a4edf9a3ad98edfa76bb62f..34b9eb81eb5d150f779426acf608b1be0ebe5c3a 100644 --- a/core/modules/datetime/src/Hook/DatetimeHooks.php +++ b/core/modules/datetime/src/Hook/DatetimeHooks.php @@ -2,6 +2,7 @@ namespace Drupal\datetime\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class DatetimeHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,8 +22,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.datetime': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Datetime module provides a Date field that stores dates and times. It also provides the Form API elements <em>datetime</em> and <em>datelist</em> for use in programming modules. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":datetime_do">online documentation for the Datetime module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Datetime module provides a Date field that stores dates and times. It also provides the Form API elements <em>datetime</em> and <em>datelist</em> for use in programming modules. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":datetime_do">online documentation for the Datetime module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -29,16 +32,16 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying date fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Displaying dates') . '</dt>'; - $output .= '<dd>' . t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href=":date_format_list">Date and time formats</a> page.', [ + $output .= '<dt>' . $this->t('Displaying dates') . '</dt>'; + $output .= '<dd>' . $this->t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href=":date_format_list">Date and time formats</a> page.', [ ':date_format_list' => Url::fromRoute('entity.date_format.collection')->toString(), ]) . '</dd>'; $output .= '</dl>'; diff --git a/core/modules/datetime_range/src/Hook/DatetimeRangeHooks.php b/core/modules/datetime_range/src/Hook/DatetimeRangeHooks.php index ab7e5fbc0266c47de062a5ac862b317b4510090c..2bc26e726c19a0b6abdc2688db502a5db7dea925 100644 --- a/core/modules/datetime_range/src/Hook/DatetimeRangeHooks.php +++ b/core/modules/datetime_range/src/Hook/DatetimeRangeHooks.php @@ -2,6 +2,7 @@ namespace Drupal\datetime_range\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class DatetimeRangeHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,8 +22,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.datetime_range': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Datetime Range module provides a Date field that stores start dates and times, as well as end dates and times. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":datetime_do">online documentation for the Datetime Range module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Datetime Range module provides a Date field that stores start dates and times, as well as end dates and times. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI module help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":datetime_do">online documentation for the Datetime Range module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -29,16 +32,16 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':datetime_do' => 'https://www.drupal.org/documentation/modules/datetime_range', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying date fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying date fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the Date field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Displaying dates') . '</dt>'; - $output .= '<dd>' . t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href=":date_format_list">Date and time formats</a> page.', [ + $output .= '<dt>' . $this->t('Displaying dates') . '</dt>'; + $output .= '<dd>' . $this->t('Dates can be displayed using the <em>Plain</em> or the <em>Default</em> formatter. The <em>Plain</em> formatter displays the date in the <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601</a> format. If you choose the <em>Default</em> formatter, you can choose a format from a predefined list that can be managed on the <a href=":date_format_list">Date and time formats</a> page.', [ ':date_format_list' => Url::fromRoute('entity.date_format.collection')->toString(), ]) . '</dd>'; $output .= '</dl>'; diff --git a/core/modules/dblog/src/Hook/DblogHooks.php b/core/modules/dblog/src/Hook/DblogHooks.php index 6bb6e1a46b2d04401552d5b74efa27c21c698279..d6675f88d353e02407f2afbb8df894c5293450f5 100644 --- a/core/modules/dblog/src/Hook/DblogHooks.php +++ b/core/modules/dblog/src/Hook/DblogHooks.php @@ -2,6 +2,7 @@ namespace Drupal\dblog\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\ViewExecutable; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; @@ -14,6 +15,8 @@ */ class DblogHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,21 +25,21 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.dblog': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Database Logging module logs system events in the Drupal database. For more information, see the <a href=":dblog">online documentation for the Database Logging module</a>.', [':dblog' => 'https://www.drupal.org/documentation/modules/dblog']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Database Logging module logs system events in the Drupal database. For more information, see the <a href=":dblog">online documentation for the Database Logging module</a>.', [':dblog' => 'https://www.drupal.org/documentation/modules/dblog']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Monitoring your site') . '</dt>'; - $output .= '<dd>' . t('The Database Logging module allows you to view an event log on the <a href=":dblog">Recent log messages</a> page. The log is a chronological list of recorded events containing usage data, performance data, errors, warnings and operational information. Administrators should check the log on a regular basis to ensure their site is working properly.', [':dblog' => Url::fromRoute('dblog.overview')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Debugging site problems') . '</dt>'; - $output .= '<dd>' . t('In case of errors or problems with the site, the <a href=":dblog">Recent log messages</a> page can be useful for debugging, since it shows the sequence of events. The log messages include usage information, warnings, and errors.', [':dblog' => Url::fromRoute('dblog.overview')->toString()]) . '</dd>'; - $output .= '<dt>' . t('This log is not persistent') . '</dt>'; - $output .= '<dd>' . t('The Database Logging module logs may be cleared by administrators and automated cron tasks, so they should not be used for <a href=":audit_trail_wiki">forensic logging</a>. For forensic purposes, use the Syslog module.', [':audit_trail_wiki' => 'https://en.wikipedia.org/wiki/Audit_trail']) . '</dd>'; + $output .= '<dt>' . $this->t('Monitoring your site') . '</dt>'; + $output .= '<dd>' . $this->t('The Database Logging module allows you to view an event log on the <a href=":dblog">Recent log messages</a> page. The log is a chronological list of recorded events containing usage data, performance data, errors, warnings and operational information. Administrators should check the log on a regular basis to ensure their site is working properly.', [':dblog' => Url::fromRoute('dblog.overview')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Debugging site problems') . '</dt>'; + $output .= '<dd>' . $this->t('In case of errors or problems with the site, the <a href=":dblog">Recent log messages</a> page can be useful for debugging, since it shows the sequence of events. The log messages include usage information, warnings, and errors.', [':dblog' => Url::fromRoute('dblog.overview')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('This log is not persistent') . '</dt>'; + $output .= '<dd>' . $this->t('The Database Logging module logs may be cleared by administrators and automated cron tasks, so they should not be used for <a href=":audit_trail_wiki">forensic logging</a>. For forensic purposes, use the Syslog module.', [':audit_trail_wiki' => 'https://en.wikipedia.org/wiki/Audit_trail']) . '</dd>'; $output .= '</dl>'; return $output; case 'dblog.overview': - return '<p>' . t('The Database Logging module logs system events in the Drupal database. Monitor your site or debug site problems on this page.') . '</p>'; + return '<p>' . $this->t('The Database Logging module logs system events in the Drupal database. Monitor your site or debug site problems on this page.') . '</p>'; } } @@ -86,12 +89,12 @@ public function formSystemLoggingSettingsAlter(&$form, FormStateInterface $form_ $row_limits = [100, 1000, 10000, 100000, 1000000]; $form['dblog_row_limit'] = [ '#type' => 'select', - '#title' => t('Database log messages to keep'), + '#title' => $this->t('Database log messages to keep'), '#config_target' => 'dblog.settings:row_limit', '#options' => [ - 0 => t('All'), + 0 => $this->t('All'), ] + array_combine($row_limits, $row_limits), - '#description' => t('The maximum number of messages to keep in the database log. Requires a <a href=":cron">cron maintenance task</a>.', [ + '#description' => $this->t('The maximum number of messages to keep in the database log. Requires a <a href=":cron">cron maintenance task</a>.', [ ':cron' => Url::fromRoute('system.status')->toString(), ]), ]; diff --git a/core/modules/dblog/src/Hook/DblogViewsHooks.php b/core/modules/dblog/src/Hook/DblogViewsHooks.php index 75aef6b0a3e18532671e66b7a6bd2fe0b3c05a27..165f76026fc7524ac1ca0171c3339c3a59156084 100644 --- a/core/modules/dblog/src/Hook/DblogViewsHooks.php +++ b/core/modules/dblog/src/Hook/DblogViewsHooks.php @@ -3,28 +3,31 @@ namespace Drupal\dblog\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for dblog. */ class DblogViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data(). */ #[Hook('views_data')] public function viewsData(): array { $data = []; - $data['watchdog']['table']['group'] = t('Watchdog'); + $data['watchdog']['table']['group'] = $this->t('Watchdog'); $data['watchdog']['table']['wizard_id'] = 'watchdog'; $data['watchdog']['table']['base'] = [ 'field' => 'wid', - 'title' => t('Log entries'), - 'help' => t('Contains a list of log entries.'), + 'title' => $this->t('Log entries'), + 'help' => $this->t('Contains a list of log entries.'), ]; $data['watchdog']['wid'] = [ - 'title' => t('WID'), - 'help' => t('Unique watchdog event ID.'), + 'title' => $this->t('WID'), + 'help' => $this->t('Unique watchdog event ID.'), 'field' => [ 'id' => 'standard', ], @@ -39,8 +42,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['uid'] = [ - 'title' => t('UID'), - 'help' => t('The user ID of the user on which the log entry was written.'), + 'title' => $this->t('UID'), + 'help' => $this->t('The user ID of the user on which the log entry was written.'), 'field' => [ 'id' => 'standard', ], @@ -51,16 +54,16 @@ public function viewsData(): array { 'id' => 'numeric', ], 'relationship' => [ - 'title' => t('User'), - 'help' => t('The user on which the log entry as written.'), + 'title' => $this->t('User'), + 'help' => $this->t('The user on which the log entry as written.'), 'base' => 'users_field_data', 'base field' => 'uid', 'id' => 'standard', ], ]; $data['watchdog']['type'] = [ - 'title' => t('Type'), - 'help' => t('The type of the log entry, for example "user" or "page not found".'), + 'title' => $this->t('Type'), + 'help' => $this->t('The type of the log entry, for example "user" or "page not found".'), 'field' => [ 'id' => 'standard', ], @@ -75,8 +78,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['message'] = [ - 'title' => t('Message'), - 'help' => t('The actual message of the log entry.'), + 'title' => $this->t('Message'), + 'help' => $this->t('The actual message of the log entry.'), 'field' => [ 'id' => 'dblog_message', ], @@ -91,8 +94,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['variables'] = [ - 'title' => t('Variables'), - 'help' => t('The variables of the log entry in a serialized format.'), + 'title' => $this->t('Variables'), + 'help' => $this->t('The variables of the log entry in a serialized format.'), 'field' => [ 'id' => 'serialized', 'click sortable' => FALSE, @@ -108,8 +111,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['severity'] = [ - 'title' => t('Severity level'), - 'help' => t('The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).'), + 'title' => $this->t('Severity level'), + 'help' => $this->t('The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).'), 'field' => [ 'id' => 'machine_name', 'options callback' => 'Drupal\dblog\Controller\DbLogController::getLogLevelClassMap', @@ -123,8 +126,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['link'] = [ - 'title' => t('Operations'), - 'help' => t('Operation links for the event.'), + 'title' => $this->t('Operations'), + 'help' => $this->t('Operation links for the event.'), 'field' => [ 'id' => 'dblog_operations', ], @@ -139,8 +142,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['location'] = [ - 'title' => t('Location'), - 'help' => t('URL of the origin of the event.'), + 'title' => $this->t('Location'), + 'help' => $this->t('URL of the origin of the event.'), 'field' => [ 'id' => 'standard', ], @@ -155,8 +158,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['referer'] = [ - 'title' => t('Referer'), - 'help' => t('URL of the previous page.'), + 'title' => $this->t('Referer'), + 'help' => $this->t('URL of the previous page.'), 'field' => [ 'id' => 'standard', ], @@ -171,8 +174,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['hostname'] = [ - 'title' => t('Hostname'), - 'help' => t('Hostname of the user who triggered the event.'), + 'title' => $this->t('Hostname'), + 'help' => $this->t('Hostname of the user who triggered the event.'), 'field' => [ 'id' => 'standard', ], @@ -187,8 +190,8 @@ public function viewsData(): array { ], ]; $data['watchdog']['timestamp'] = [ - 'title' => t('Timestamp'), - 'help' => t('Date when the event occurred.'), + 'title' => $this->t('Timestamp'), + 'help' => $this->t('Date when the event occurred.'), 'field' => [ 'id' => 'date', ], diff --git a/core/modules/dynamic_page_cache/src/Hook/DynamicPageCacheHooks.php b/core/modules/dynamic_page_cache/src/Hook/DynamicPageCacheHooks.php index 6ecdc26904a3e83cc46824cc675280291eb4490c..7eab2af3795e2eb7d9466e396ed720c05f09d967 100644 --- a/core/modules/dynamic_page_cache/src/Hook/DynamicPageCacheHooks.php +++ b/core/modules/dynamic_page_cache/src/Hook/DynamicPageCacheHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for dynamic_page_cache. */ class DynamicPageCacheHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -17,15 +20,15 @@ class DynamicPageCacheHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.dynamic_page_cache': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Internal Dynamic Page Cache module caches pages for all users in the database, handling dynamic content correctly. For more information, see the <a href=":dynamic_page_cache-documentation">online documentation for the Internal Dynamic Page Cache module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Internal Dynamic Page Cache module caches pages for all users in the database, handling dynamic content correctly. For more information, see the <a href=":dynamic_page_cache-documentation">online documentation for the Internal Dynamic Page Cache module</a>.', [ ':dynamic_page_cache-documentation' => 'https://www.drupal.org/documentation/modules/dynamic_page_cache', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Speeding up your site') . '</dt>'; - $output .= '<dd>' . t('Pages which are suitable for caching are cached the first time they are requested, then the cached version is served for all later requests. Dynamic content is handled automatically so that both cache correctness and hit ratio is maintained.') . '</dd>'; - $output .= '<dd>' . t('The module requires no configuration. Every part of the page contains metadata that allows Internal Dynamic Page Cache to figure this out on its own.') . '</dd>'; + $output .= '<dt>' . $this->t('Speeding up your site') . '</dt>'; + $output .= '<dd>' . $this->t('Pages which are suitable for caching are cached the first time they are requested, then the cached version is served for all later requests. Dynamic content is handled automatically so that both cache correctness and hit ratio is maintained.') . '</dd>'; + $output .= '<dd>' . $this->t('The module requires no configuration. Every part of the page contains metadata that allows Internal Dynamic Page Cache to figure this out on its own.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/editor/src/Hook/EditorHooks.php b/core/modules/editor/src/Hook/EditorHooks.php index cf1127aa18711e1543d3eb7e3d2a57ed850d887a..92958c468fff002583c4258df9a4721ca9f3d05e 100644 --- a/core/modules/editor/src/Hook/EditorHooks.php +++ b/core/modules/editor/src/Hook/EditorHooks.php @@ -2,6 +2,7 @@ namespace Drupal\editor\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\editor\Entity\Editor; use Drupal\filter\FilterFormatInterface; use Drupal\Core\Entity\FieldableEntityInterface; @@ -19,6 +20,8 @@ */ class EditorHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -27,28 +30,28 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.editor': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Text Editor module provides a framework that other modules (such as <a href=":ckeditor5">CKEditor5 module</a>) can use to provide toolbars and other functionality that allow users to format text more easily than typing HTML tags directly. For more information, see the <a href=":documentation">online documentation for the Text Editor module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Text Editor module provides a framework that other modules (such as <a href=":ckeditor5">CKEditor5 module</a>) can use to provide toolbars and other functionality that allow users to format text more easily than typing HTML tags directly. For more information, see the <a href=":documentation">online documentation for the Text Editor module</a>.', [ ':documentation' => 'https://www.drupal.org/documentation/modules/editor', ':ckeditor5' => \Drupal::moduleHandler()->moduleExists('ckeditor5') ? Url::fromRoute('help.page', [ 'name' => 'ckeditor5', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Installing text editors') . '</dt>'; - $output .= '<dd>' . t('The Text Editor module provides a framework for managing editors. To use it, you also need to install a text editor. This can either be the core <a href=":ckeditor5">CKEditor5 module</a>, which can be installed on the <a href=":extend">Extend page</a>, or a contributed module for any other text editor. When installing a contributed text editor module, be sure to check the installation instructions, because you will most likely need to download an external library as well as the Drupal module.', [ + $output .= '<dt>' . $this->t('Installing text editors') . '</dt>'; + $output .= '<dd>' . $this->t('The Text Editor module provides a framework for managing editors. To use it, you also need to install a text editor. This can either be the core <a href=":ckeditor5">CKEditor5 module</a>, which can be installed on the <a href=":extend">Extend page</a>, or a contributed module for any other text editor. When installing a contributed text editor module, be sure to check the installation instructions, because you will most likely need to download an external library as well as the Drupal module.', [ ':ckeditor5' => \Drupal::moduleHandler()->moduleExists('ckeditor5') ? Url::fromRoute('help.page', [ 'name' => 'ckeditor5', ])->toString() : '#', ':extend' => Url::fromRoute('system.modules_list')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Enabling a text editor for a text format') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":formats">Text formats and editors page</a> you can see which text editor is associated with each text format. You can change this by clicking on the <em>Configure</em> link, and then choosing a text editor or <em>none</em> from the <em>Text editor</em> drop-down list. The text editor will then be displayed with any text field for which this text format is chosen.', [':formats' => Url::fromRoute('filter.admin_overview')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Configuring a text editor') . '</dt>'; - $output .= '<dd>' . t('Once a text editor is associated with a text format, you can configure it by clicking on the <em>Configure</em> link for this format. Depending on the specific text editor, you can configure it for example by adding buttons to its toolbar. Typically these buttons provide formatting or editing tools, and they often insert HTML tags into the field source. For details, see the help page of the specific text editor.') . '</dd>'; - $output .= '<dt>' . t('Using different text editors and formats') . '</dt>'; - $output .= '<dd>' . t('If you change the text format on a text field, the text editor will change as well because the text editor configuration is associated with the individual text format. This allows the use of the same text editor with different options for different text formats. It also allows users to choose between text formats with different text editors if they are installed.') . '</dd>'; + $output .= '<dt>' . $this->t('Enabling a text editor for a text format') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":formats">Text formats and editors page</a> you can see which text editor is associated with each text format. You can change this by clicking on the <em>Configure</em> link, and then choosing a text editor or <em>none</em> from the <em>Text editor</em> drop-down list. The text editor will then be displayed with any text field for which this text format is chosen.', [':formats' => Url::fromRoute('filter.admin_overview')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Configuring a text editor') . '</dt>'; + $output .= '<dd>' . $this->t('Once a text editor is associated with a text format, you can configure it by clicking on the <em>Configure</em> link for this format. Depending on the specific text editor, you can configure it for example by adding buttons to its toolbar. Typically these buttons provide formatting or editing tools, and they often insert HTML tags into the field source. For details, see the help page of the specific text editor.') . '</dd>'; + $output .= '<dt>' . $this->t('Using different text editors and formats') . '</dt>'; + $output .= '<dd>' . $this->t('If you change the text format on a text field, the text editor will change as well because the text editor configuration is associated with the individual text format. This allows the use of the same text editor with different options for different text formats. It also allows users to choose between text formats with different text editors if they are installed.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -88,7 +91,7 @@ public function formFilterAdminOverviewAlter(&$form, FormStateInterface $form_st // @todo Cleanup column injection: https://www.drupal.org/node/1876718. // Splice in the column for "Text editor" into the header. $position = array_search('name', $form['formats']['#header']) + 1; - $start = array_splice($form['formats']['#header'], 0, $position, ['editor' => t('Text editor')]); + $start = array_splice($form['formats']['#header'], 0, $position, ['editor' => $this->t('Text editor')]); $form['formats']['#header'] = array_merge($start, $form['formats']['#header']); // Then splice in the name of each text editor for each text format. $editors = \Drupal::service('plugin.manager.editor')->getDefinitions(); @@ -120,9 +123,9 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state $form['editor'] = ['#weight' => -9]; $form['editor']['editor'] = [ '#type' => 'select', - '#title' => t('Text editor'), + '#title' => $this->t('Text editor'), '#options' => $editor_options, - '#empty_option' => t('None'), + '#empty_option' => $this->t('None'), '#default_value' => $editor ? $editor->getEditor() : '', '#ajax' => [ 'trigger_as' => [ @@ -136,7 +139,7 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state $form['editor']['configure'] = [ '#type' => 'submit', '#name' => 'editor_configure', - '#value' => t('Configure'), + '#value' => $this->t('Configure'), '#limit_validation_errors' => [ [ 'editor', @@ -159,7 +162,7 @@ public function formFilterFormatFormAlter(&$form, FormStateInterface $form_state // If there aren't any options (other than "None"), disable the select list. if (empty($editor_options)) { $form['editor']['editor']['#disabled'] = TRUE; - $form['editor']['editor']['#description'] = t('This option is disabled because no modules that provide a text editor are currently enabled.'); + $form['editor']['editor']['#description'] = $this->t('This option is disabled because no modules that provide a text editor are currently enabled.'); } $form['editor']['settings'] = [ '#tree' => TRUE, diff --git a/core/modules/field/src/Hook/FieldHooks.php b/core/modules/field/src/Hook/FieldHooks.php index b1c32d555286df798803071ff304406a3a52f7e5..888fd503acdc8473a293b3d26356ea5357126e43 100644 --- a/core/modules/field/src/Hook/FieldHooks.php +++ b/core/modules/field/src/Hook/FieldHooks.php @@ -2,6 +2,7 @@ namespace Drupal\field\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; use Drupal\field\EntityDisplayRebuilder; use Drupal\field\FieldConfigInterface; @@ -21,6 +22,9 @@ * Hook implementations for field. */ class FieldHooks { + + use StringTranslationTrait; + /** * @defgroup field Field API * @{ @@ -68,32 +72,32 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'help.page.field': $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'; $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href=":field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href=":field">online documentation for the Field module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Field module allows custom data fields to be defined for <em>entity</em> types (see below). The Field module takes care of storing, loading, editing, and rendering field data. Most users will not interact with the Field module directly, but will instead use the <a href=":field-ui-help">Field UI module</a> user interface. Module developers can use the Field API to make new entity types "fieldable" and thus allow fields to be attached to them. For more information, see the <a href=":field">online documentation for the Field module</a>.', [ ':field-ui-help' => $field_ui_url, ':field' => 'https://www.drupal.org/documentation/modules/field', ]) . '</p>'; - $output .= '<h2>' . t('Terminology') . '</h2>'; + $output .= '<h2>' . $this->t('Terminology') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Entities and entity types') . '</dt>'; - $output .= '<dd>' . t("The website's content and configuration is managed using <em>entities</em>, which are grouped into <em>entity types</em>. <em>Content entity types</em> are the entity types for site content (such as the main site content, comments, content blocks, taxonomy terms, and user accounts). <em>Configuration entity types</em> are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types.") . '</dd>'; - $output .= '<dt>' . t('Entity sub-types') . '</dt>'; - $output .= '<dd>' . t('Some content entity types are further grouped into sub-types (for example, you could have article and page content types within the main site content entity type, and tag and category vocabularies within the taxonomy term entity type); other entity types, such as user accounts, do not have sub-types. Programmers use the term <em>bundle</em> for entity sub-types.') . '</dd>'; - $output .= '<dt>' . t('Fields and field types') . '</dt>'; - $output .= '<dd>' . t('Content entity types and sub-types store most of their text, file, and other information in <em>fields</em>. Fields are grouped by <em>field type</em>; field types define what type of data can be stored in that field, such as text, images, or taxonomy term references.') . '</dd>'; - $output .= '<dt>' . t('Formatters and view modes') . '</dd>'; - $output .= '<dd>' . t('Content entity types and sub-types can have one or more <em>view modes</em>, used for displaying the entity items. For instance, a content item could be viewed in full content mode on its own page, teaser mode in a list, or RSS mode in a feed. In each view mode, each field can be hidden or displayed, and if it is displayed, you can choose and configure the <em>formatter</em> that is used to display the field. For instance, a long text field can be displayed trimmed or full-length, and taxonomy term reference fields can be displayed in plain text or linked to the taxonomy term page.') . '</dd>'; - $output .= '<dt>' . t('Widgets and form modes') . '</dd>'; - $output .= '<dd>' . t('Content entity types and sub-types can have one or more <em>form modes</em>, used for editing. For instance, a content item could be edited in a compact format with only some fields editable, or a full format that allows all fields to be edited. In each form mode, each field can be hidden or displayed, and if it is displayed, you can choose and configure the <em>widget</em> that is used to edit the field. For instance, a taxonomy term reference field can be edited using a select list, radio buttons, or an autocomplete widget.') . '</dd>'; + $output .= '<dt>' . $this->t('Entities and entity types') . '</dt>'; + $output .= '<dd>' . $this->t("The website's content and configuration is managed using <em>entities</em>, which are grouped into <em>entity types</em>. <em>Content entity types</em> are the entity types for site content (such as the main site content, comments, content blocks, taxonomy terms, and user accounts). <em>Configuration entity types</em> are used to store configuration information for your site, such as individual views in the Views module, and settings for your main site content types.") . '</dd>'; + $output .= '<dt>' . $this->t('Entity sub-types') . '</dt>'; + $output .= '<dd>' . $this->t('Some content entity types are further grouped into sub-types (for example, you could have article and page content types within the main site content entity type, and tag and category vocabularies within the taxonomy term entity type); other entity types, such as user accounts, do not have sub-types. Programmers use the term <em>bundle</em> for entity sub-types.') . '</dd>'; + $output .= '<dt>' . $this->t('Fields and field types') . '</dt>'; + $output .= '<dd>' . $this->t('Content entity types and sub-types store most of their text, file, and other information in <em>fields</em>. Fields are grouped by <em>field type</em>; field types define what type of data can be stored in that field, such as text, images, or taxonomy term references.') . '</dd>'; + $output .= '<dt>' . $this->t('Formatters and view modes') . '</dd>'; + $output .= '<dd>' . $this->t('Content entity types and sub-types can have one or more <em>view modes</em>, used for displaying the entity items. For instance, a content item could be viewed in full content mode on its own page, teaser mode in a list, or RSS mode in a feed. In each view mode, each field can be hidden or displayed, and if it is displayed, you can choose and configure the <em>formatter</em> that is used to display the field. For instance, a long text field can be displayed trimmed or full-length, and taxonomy term reference fields can be displayed in plain text or linked to the taxonomy term page.') . '</dd>'; + $output .= '<dt>' . $this->t('Widgets and form modes') . '</dd>'; + $output .= '<dd>' . $this->t('Content entity types and sub-types can have one or more <em>form modes</em>, used for editing. For instance, a content item could be edited in a compact format with only some fields editable, or a full format that allows all fields to be edited. In each form mode, each field can be hidden or displayed, and if it is displayed, you can choose and configure the <em>widget</em> that is used to edit the field. For instance, a taxonomy term reference field can be edited using a select list, radio buttons, or an autocomplete widget.') . '</dd>'; $output .= '</dl>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Enabling field types, widgets, and formatters') . '</dt>'; - $output .= '<dd>' . t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be installed from the <a href=":modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href=":contrib">contributed module section of Drupal.org</a>.', [ + $output .= '<dt>' . $this->t('Enabling field types, widgets, and formatters') . '</dt>'; + $output .= '<dd>' . $this->t('The Field module provides the infrastructure for fields; the field types, formatters, and widgets are provided by Drupal core or additional modules. Some of the modules are required; the optional modules can be installed from the <a href=":modules">Extend administration page</a>. Additional fields, formatters, and widgets may be provided by contributed modules, which you can find in the <a href=":contrib">contributed module section of Drupal.org</a>.', [ ':modules' => Url::fromRoute('system.modules_list')->toString(), ':contrib' => 'https://www.drupal.org/project/modules', ]) . '</dd>'; - $output .= '<h2>' . t('Field, widget, and formatter information') . '</h2>'; + $output .= '<h2>' . $this->t('Field, widget, and formatter information') . '</h2>'; // Make a list of all widget, formatter, and field modules currently // enabled, ordered by displayed module name (module names are not // translated). @@ -123,35 +127,35 @@ public function help($route_name, RouteMatchInterface $route_match) { } } if ($items) { - $output .= '<dt>' . t('Provided by modules') . '</dt>'; - $output .= '<dd>' . t('Here is a list of the currently installed field, formatter, and widget modules:'); + $output .= '<dt>' . $this->t('Provided by modules') . '</dt>'; + $output .= '<dd>' . $this->t('Here is a list of the currently installed field, formatter, and widget modules:'); $item_list = ['#theme' => 'item_list', '#items' => $items]; $output .= \Drupal::service('renderer')->renderInIsolation($item_list); $output .= '</dd>'; } - $output .= '<dt>' . t('Provided by Drupal core') . '</dt>'; - $output .= '<dd>' . t('As mentioned previously, some field types, widgets, and formatters are provided by Drupal core. Here are some notes on how to use some of these:'); + $output .= '<dt>' . $this->t('Provided by Drupal core') . '</dt>'; + $output .= '<dd>' . $this->t('As mentioned previously, some field types, widgets, and formatters are provided by Drupal core. Here are some notes on how to use some of these:'); $output .= '<ul>'; - $output .= '<li><p>' . t('<strong>Entity Reference</strong> fields allow you to create fields that contain links to other entities (such as content items, taxonomy terms, etc.) within the site. This allows you, for example, to include a link to a user within a content item. For more information, see <a href=":er_do">the online documentation for the Entity Reference module</a>.', [':er_do' => 'https://drupal.org/documentation/modules/entityreference']) . '</p>'; + $output .= '<li><p>' . $this->t('<strong>Entity Reference</strong> fields allow you to create fields that contain links to other entities (such as content items, taxonomy terms, etc.) within the site. This allows you, for example, to include a link to a user within a content item. For more information, see <a href=":er_do">the online documentation for the Entity Reference module</a>.', [':er_do' => 'https://drupal.org/documentation/modules/entityreference']) . '</p>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying entity reference fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the entity reference field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => $field_ui_url]) . '</dd>'; - $output .= '<dt>' . t('Selecting reference type') . '</dt>'; - $output .= '<dd>' . t('In the field settings you can select which entity type you want to create a reference to.') . '</dd>'; - $output .= '<dt>' . t('Filtering and sorting reference fields') . '</dt>'; - $output .= '<dd>' . t('Depending on the chosen entity type, additional filtering and sorting options are available for the list of entities that can be referred to, in the field settings. For example, the list of users can be filtered by role and sorted by name or ID.') . '</dd>'; - $output .= '<dt>' . t('Displaying a reference') . '</dt>'; - $output .= '<dd>' . t('An entity reference can be displayed as a simple label with or without a link to the entity. Alternatively, the referenced entity can be displayed as a teaser (or any other available view mode) inside the referencing entity.') . '</dd>'; - $output .= '<dt>' . t('Configuring form displays') . '</dt>'; - $output .= '<dd>' . t('Reference fields have several widgets available on the <em>Manage form display</em> page:'); + $output .= '<dt>' . $this->t('Managing and displaying entity reference fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the entity reference field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [':field_ui' => $field_ui_url]) . '</dd>'; + $output .= '<dt>' . $this->t('Selecting reference type') . '</dt>'; + $output .= '<dd>' . $this->t('In the field settings you can select which entity type you want to create a reference to.') . '</dd>'; + $output .= '<dt>' . $this->t('Filtering and sorting reference fields') . '</dt>'; + $output .= '<dd>' . $this->t('Depending on the chosen entity type, additional filtering and sorting options are available for the list of entities that can be referred to, in the field settings. For example, the list of users can be filtered by role and sorted by name or ID.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying a reference') . '</dt>'; + $output .= '<dd>' . $this->t('An entity reference can be displayed as a simple label with or without a link to the entity. Alternatively, the referenced entity can be displayed as a teaser (or any other available view mode) inside the referencing entity.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring form displays') . '</dt>'; + $output .= '<dd>' . $this->t('Reference fields have several widgets available on the <em>Manage form display</em> page:'); $output .= '<ul>'; - $output .= '<li>' . t('The <em>Check boxes/radio buttons</em> widget displays the existing entities for the entity type as check boxes or radio buttons based on the <em>Allowed number of values</em> set for the field.') . '</li>'; - $output .= '<li>' . t('The <em>Select list</em> widget displays the existing entities in a drop-down list or scrolling list box based on the <em>Allowed number of values</em> setting for the field.') . '</li>'; - $output .= '<li>' . t('The <em>Autocomplete</em> widget displays text fields in which users can type entity labels based on the <em>Allowed number of values</em>. The widget can be configured to display all entities that contain the typed characters or restricted to those starting with those characters.') . '</li>'; - $output .= '<li>' . t('The <em>Autocomplete (Tags style)</em> widget displays a multi-text field in which users can type in a comma-separated list of entity labels.') . '</li>'; + $output .= '<li>' . $this->t('The <em>Check boxes/radio buttons</em> widget displays the existing entities for the entity type as check boxes or radio buttons based on the <em>Allowed number of values</em> set for the field.') . '</li>'; + $output .= '<li>' . $this->t('The <em>Select list</em> widget displays the existing entities in a drop-down list or scrolling list box based on the <em>Allowed number of values</em> setting for the field.') . '</li>'; + $output .= '<li>' . $this->t('The <em>Autocomplete</em> widget displays text fields in which users can type entity labels based on the <em>Allowed number of values</em>. The widget can be configured to display all entities that contain the typed characters or restricted to those starting with those characters.') . '</li>'; + $output .= '<li>' . $this->t('The <em>Autocomplete (Tags style)</em> widget displays a multi-text field in which users can type in a comma-separated list of entity labels.') . '</li>'; $output .= '</ul></dd>'; $output .= '</dl></li>'; - $output .= '<li>' . t('<strong>Number fields</strong>: When you add a number field you can choose from three types: <em>decimal</em>, <em>float</em>, and <em>integer</em>. The <em>decimal</em> number field type allows users to enter exact decimal values, with fixed numbers of decimal places. The <em>float</em> number field type allows users to enter approximate decimal values. The <em>integer</em> number field type allows users to enter whole numbers, such as years (for example, 2012) or values (for example, 1, 2, 5, 305). It does not allow decimals.') . '</li>'; + $output .= '<li>' . $this->t('<strong>Number fields</strong>: When you add a number field you can choose from three types: <em>decimal</em>, <em>float</em>, and <em>integer</em>. The <em>decimal</em> number field type allows users to enter exact decimal values, with fixed numbers of decimal places. The <em>float</em> number field type allows users to enter approximate decimal values. The <em>integer</em> number field type allows users to enter whole numbers, such as years (for example, 2012) or values (for example, 1, 2, 5, 305). It does not allow decimals.') . '</li>'; $output .= '</ul></dd>'; $output .= '</dl>'; return $output; diff --git a/core/modules/field_layout/src/Hook/FieldLayoutHooks.php b/core/modules/field_layout/src/Hook/FieldLayoutHooks.php index 45bbad8af48dbbe85ee1567153dcd08cebf530ec..7d8b0b80145b6768590b2f5aaa99bae78d02985a 100644 --- a/core/modules/field_layout/src/Hook/FieldLayoutHooks.php +++ b/core/modules/field_layout/src/Hook/FieldLayoutHooks.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field_layout\FieldLayoutBuilder; use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; @@ -20,6 +21,8 @@ */ class FieldLayoutHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -27,9 +30,9 @@ class FieldLayoutHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.field_layout': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Field Layout module allows you to arrange fields into regions on forms and displays of entities such as nodes and users.') . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":field-layout-documentation">online documentation for the Field Layout module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Field Layout module allows you to arrange fields into regions on forms and displays of entities such as nodes and users.') . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":field-layout-documentation">online documentation for the Field Layout module</a>.', [ ':field-layout-documentation' => 'https://www.drupal.org/documentation/modules/field_layout', ]) . '</p>'; return $output; diff --git a/core/modules/field_ui/src/Hook/FieldUiHooks.php b/core/modules/field_ui/src/Hook/FieldUiHooks.php index 9bc09e0070e1ce36e17400c4b504bbbb897e8ca0..ff4a88dc8da1f0b2bb9dcf1383e78cf8fbacd352 100644 --- a/core/modules/field_ui/src/Hook/FieldUiHooks.php +++ b/core/modules/field_ui/src/Hook/FieldUiHooks.php @@ -3,6 +3,7 @@ namespace Drupal\field_ui\Hook; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field_ui\Plugin\Derivative\FieldUiLocalTask; use Drupal\Core\Entity\EntityFormModeInterface; use Drupal\Core\Entity\EntityViewModeInterface; @@ -18,6 +19,8 @@ */ class FieldUiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -26,30 +29,30 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.field_ui': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Field UI module provides an administrative user interface (UI) for managing and displaying fields. Fields can be attached to most content entity sub-types. Different field types, widgets, and formatters are provided by the modules installed on your site, and managed by the Field module. For background information and terminology related to fields and entities, see the <a href=":field">Field module help page</a>. For more information about the Field UI, see the <a href=":field_ui_docs">online documentation for the Field UI module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Field UI module provides an administrative user interface (UI) for managing and displaying fields. Fields can be attached to most content entity sub-types. Different field types, widgets, and formatters are provided by the modules installed on your site, and managed by the Field module. For background information and terminology related to fields and entities, see the <a href=":field">Field module help page</a>. For more information about the Field UI, see the <a href=":field_ui_docs">online documentation for the Field UI module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ':field_ui_docs' => 'https://www.drupal.org/docs/8/core/modules/field-ui', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating a field') . '</dt>'; - $output .= '<dd>' . t('On the <em>Manage fields</em> page for your entity type or sub-type, you can add, configure, and delete fields for that entity type or sub-type. Each field has a <em>machine name</em>, which is used internally to identify the field and must be unique across an entity type; once a field is created, you cannot change the machine name. Most fields have two types of settings. The field-level settings depend on the field type, and affect how the data in the field is stored. Once they are set, they can no longer be changed; examples include how many data values are allowed for the field and where files are stored. The sub-type-level settings are specific to each entity sub-type the field is used on, and they can be changed later; examples include the field label, help text, default value, and whether the field is required or not. You can return to these settings by choosing the <em>Edit</em> link for the field from the <em>Manage fields</em> page.'); - $output .= '<dt>' . t('Re-using fields') . '</dt>'; - $output .= '<dd>' . t('Once you have created a field, you can use it again in other sub-types of the same entity type. For instance, if you create a field for the article content type, you can also use it for the page content type, but you cannot use it for content blocks or taxonomy terms. If there are fields available for re-use, after clicking <em>Add field</em> from the <em>Manage fields</em> page, you will see a list of available fields for re-use. After selecting a field for re-use, you can configure the sub-type-level settings.') . '</dd>'; - $output .= '<dt>' . t('Configuring field editing') . '</dt>'; - $output .= '<dd>' . t('On the <em>Manage form display</em> page of your entity type or sub-type, you can configure how the field data is edited by default and in each form mode. If your entity type has multiple form modes (on most sites, most entities do not), you can toggle between the form modes at the top of the page, and you can toggle whether each form mode uses the default settings or custom settings in the <em>Custom display settings</em> section. For each field in each form mode, you can select the widget to use for editing; some widgets have additional configuration options, such as the size for a text field, and these can be edited using the Edit button (which looks like a wheel). You can also change the order of the fields on the form. You can exclude a field from a form by choosing <em>Hidden</em> from the widget drop-down list, or by dragging it into the <em>Disabled</em> section.') . '</dd>'; - $output .= '<dt>' . t('Configuring field display') . '</dt>'; - $output .= '<dd>' . t('On the <em>Manage display</em> page of your entity type or sub-type, you can configure how each field is displayed by default and in each view mode. If your entity type has multiple view modes, you can toggle between the view modes at the top of the page, and you can toggle whether each view mode uses the default settings or custom settings in the <em>Custom display settings</em> section. For each field in each view mode, you can choose whether and how to display the label of the field from the <em>Label</em> drop-down list. You can also select the formatter to use for display; some formatters have configuration options, which you can edit using the Edit button (which looks like a wheel). You can also change the display order of fields. You can exclude a field from a specific view mode by choosing <em>Hidden</em> from the formatter drop-down list, or by dragging it into the <em>Disabled</em> section.') . '</dd>'; - $output .= '<dt>' . t('Configuring view and form modes') . '</dt>'; - $output .= '<dd>' . t('You can add, edit, and delete view modes for entities on the <a href=":view_modes">View modes page</a>, and you can add, edit, and delete form modes for entities on the <a href=":form_modes">Form modes page</a>. Once you have defined a view mode or form mode for an entity type, it will be available on the Manage display or Manage form display page for each sub-type of that entity.', [ + $output .= '<dt>' . $this->t('Creating a field') . '</dt>'; + $output .= '<dd>' . $this->t('On the <em>Manage fields</em> page for your entity type or sub-type, you can add, configure, and delete fields for that entity type or sub-type. Each field has a <em>machine name</em>, which is used internally to identify the field and must be unique across an entity type; once a field is created, you cannot change the machine name. Most fields have two types of settings. The field-level settings depend on the field type, and affect how the data in the field is stored. Once they are set, they can no longer be changed; examples include how many data values are allowed for the field and where files are stored. The sub-type-level settings are specific to each entity sub-type the field is used on, and they can be changed later; examples include the field label, help text, default value, and whether the field is required or not. You can return to these settings by choosing the <em>Edit</em> link for the field from the <em>Manage fields</em> page.'); + $output .= '<dt>' . $this->t('Re-using fields') . '</dt>'; + $output .= '<dd>' . $this->t('Once you have created a field, you can use it again in other sub-types of the same entity type. For instance, if you create a field for the article content type, you can also use it for the page content type, but you cannot use it for content blocks or taxonomy terms. If there are fields available for re-use, after clicking <em>Add field</em> from the <em>Manage fields</em> page, you will see a list of available fields for re-use. After selecting a field for re-use, you can configure the sub-type-level settings.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring field editing') . '</dt>'; + $output .= '<dd>' . $this->t('On the <em>Manage form display</em> page of your entity type or sub-type, you can configure how the field data is edited by default and in each form mode. If your entity type has multiple form modes (on most sites, most entities do not), you can toggle between the form modes at the top of the page, and you can toggle whether each form mode uses the default settings or custom settings in the <em>Custom display settings</em> section. For each field in each form mode, you can select the widget to use for editing; some widgets have additional configuration options, such as the size for a text field, and these can be edited using the Edit button (which looks like a wheel). You can also change the order of the fields on the form. You can exclude a field from a form by choosing <em>Hidden</em> from the widget drop-down list, or by dragging it into the <em>Disabled</em> section.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring field display') . '</dt>'; + $output .= '<dd>' . $this->t('On the <em>Manage display</em> page of your entity type or sub-type, you can configure how each field is displayed by default and in each view mode. If your entity type has multiple view modes, you can toggle between the view modes at the top of the page, and you can toggle whether each view mode uses the default settings or custom settings in the <em>Custom display settings</em> section. For each field in each view mode, you can choose whether and how to display the label of the field from the <em>Label</em> drop-down list. You can also select the formatter to use for display; some formatters have configuration options, which you can edit using the Edit button (which looks like a wheel). You can also change the display order of fields. You can exclude a field from a specific view mode by choosing <em>Hidden</em> from the formatter drop-down list, or by dragging it into the <em>Disabled</em> section.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring view and form modes') . '</dt>'; + $output .= '<dd>' . $this->t('You can add, edit, and delete view modes for entities on the <a href=":view_modes">View modes page</a>, and you can add, edit, and delete form modes for entities on the <a href=":form_modes">Form modes page</a>. Once you have defined a view mode or form mode for an entity type, it will be available on the Manage display or Manage form display page for each sub-type of that entity.', [ ':view_modes' => Url::fromRoute('entity.entity_view_mode.collection')->toString(), ':form_modes' => Url::fromRoute('entity.entity_form_mode.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Listing fields') . '</dt>'; - $output .= '<dd>' . t('There are two reports available that list the fields defined on your site. The <a href=":entity-list" title="Entities field list report">Entities</a> report lists all your fields, showing the field machine names, types, and the entity types or sub-types they are used on (each sub-type links to the Manage fields page). If the <a href=":views">Views</a> and <a href=":views-ui">Views UI</a> modules are installed, the <a href=":views-list" title="Used in views field list report">Used in views</a> report lists each field that is used in a view, with a link to edit that view.', [ + $output .= '<dt>' . $this->t('Listing fields') . '</dt>'; + $output .= '<dd>' . $this->t('There are two reports available that list the fields defined on your site. The <a href=":entity-list" title="Entities field list report">Entities</a> report lists all your fields, showing the field machine names, types, and the entity types or sub-types they are used on (each sub-type links to the Manage fields page). If the <a href=":views">Views</a> and <a href=":views-ui">Views UI</a> modules are installed, the <a href=":views-list" title="Used in views field list report">Used in views</a> report lists each field that is used in a view, with a link to edit that view.', [ ':entity-list' => Url::fromRoute('entity.field_storage_config.collection')->toString(), ':views-list' => \Drupal::moduleHandler()->moduleExists('views_ui') ? Url::fromRoute('views_ui.reports_fields')->toString() : '#', ':views' => \Drupal::moduleHandler()->moduleExists('views') ? Url::fromRoute('help.page', [ @@ -63,7 +66,7 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.field_storage_config.collection': - return '<p>' . t('This list shows all fields currently in use for easy reference.') . '</p>'; + return '<p>' . $this->t('This list shows all fields currently in use for easy reference.') . '</p>'; } } @@ -157,7 +160,7 @@ public function entityOperation(EntityInterface $entity): array { $account = \Drupal::currentUser(); if ($account->hasPermission('administer ' . $bundle_of . ' fields')) { $operations['manage-fields'] = [ - 'title' => t('Manage fields'), + 'title' => $this->t('Manage fields'), 'weight' => 15, 'url' => Url::fromRoute("entity.{$bundle_of}.field_ui_fields", [ $entity->getEntityTypeId() => $entity->id(), @@ -166,7 +169,7 @@ public function entityOperation(EntityInterface $entity): array { } if ($account->hasPermission('administer ' . $bundle_of . ' form display')) { $operations['manage-form-display'] = [ - 'title' => t('Manage form display'), + 'title' => $this->t('Manage form display'), 'weight' => 20, 'url' => Url::fromRoute("entity.entity_form_display.{$bundle_of}.default", [ $entity->getEntityTypeId() => $entity->id(), @@ -175,7 +178,7 @@ public function entityOperation(EntityInterface $entity): array { } if ($account->hasPermission('administer ' . $bundle_of . ' display')) { $operations['manage-display'] = [ - 'title' => t('Manage display'), + 'title' => $this->t('Manage display'), 'weight' => 25, 'url' => Url::fromRoute("entity.entity_view_display.{$bundle_of}.default", [ $entity->getEntityTypeId() => $entity->id(), @@ -233,11 +236,11 @@ public function localTasksAlter(&$local_tasks): void { */ #[Hook('form_field_ui_field_storage_add_form_alter')] public function formFieldUiFieldStorageAddFormAlter(array &$form) : void { - $optgroup = (string) t('Reference'); + $optgroup = (string) $this->t('Reference'); // Move the "Entity reference" option to the end of the list and rename it to // "Other". unset($form['add']['new_storage_type']['#options'][$optgroup]['entity_reference']); - $form['add']['new_storage_type']['#options'][$optgroup]['entity_reference'] = t('Other…'); + $form['add']['new_storage_type']['#options'][$optgroup]['entity_reference'] = $this->t('Other…'); } /** @@ -265,7 +268,7 @@ public function formAlter(&$form, FormStateInterface $form_state, $form_id) : vo if ($form_state->getFormObject()->getEntity()->isNew()) { $form['actions']['save_continue'] = $form['actions']['submit']; unset($form['actions']['submit']['#button_type']); - $form['actions']['save_continue']['#value'] = t('Save and manage fields'); + $form['actions']['save_continue']['#value'] = $this->t('Save and manage fields'); $form['actions']['save_continue']['#weight'] = $form['actions']['save_continue']['#weight'] - 5; $form['actions']['save_continue']['#submit'][] = 'field_ui_form_manage_field_form_submit'; } diff --git a/core/modules/file/src/Hook/FileHooks.php b/core/modules/file/src/Hook/FileHooks.php index 2008a7a27e2026b5a20d7b67d7eb0be922f06743..a11bf0d3b79faa4d255622d3da56d5856e231d0f 100644 --- a/core/modules/file/src/Hook/FileHooks.php +++ b/core/modules/file/src/Hook/FileHooks.php @@ -3,6 +3,7 @@ namespace Drupal\file\Hook; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\file\Entity\File; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -14,6 +15,7 @@ class FileHooks { // cspell:ignore widthx + use StringTranslationTrait; /** * Implements hook_help(). @@ -23,8 +25,8 @@ public function help($route_name, RouteMatchInterface $route_match): string|arra switch ($route_name) { case 'help.page.file': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The File module allows you to create fields that contain files. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":file_documentation">online documentation for the File module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The File module allows you to create fields that contain files. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":file_documentation">online documentation for the File module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -33,27 +35,27 @@ public function help($route_name, RouteMatchInterface $route_match): string|arra ])->toString() : '#', ':file_documentation' => 'https://www.drupal.org/documentation/modules/file', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying file fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the file field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying file fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the file field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Allowing file extensions') . '</dt>'; - $output .= '<dd>' . t('In the field settings, you can define the allowed file extensions (for example <em>pdf docx psd</em>) for the files that will be uploaded with the file field.') . '</dd>'; - $output .= '<dt>' . t('Storing files') . '</dt>'; - $output .= '<dd>' . t('Uploaded files can either be stored as <em>public</em> or <em>private</em>, depending on the <a href=":file-system">File system settings</a>. For more information, see the <a href=":system-help">System module help page</a>.', [ + $output .= '<dt>' . $this->t('Allowing file extensions') . '</dt>'; + $output .= '<dd>' . $this->t('In the field settings, you can define the allowed file extensions (for example <em>pdf docx psd</em>) for the files that will be uploaded with the file field.') . '</dd>'; + $output .= '<dt>' . $this->t('Storing files') . '</dt>'; + $output .= '<dd>' . $this->t('Uploaded files can either be stored as <em>public</em> or <em>private</em>, depending on the <a href=":file-system">File system settings</a>. For more information, see the <a href=":system-help">System module help page</a>.', [ ':file-system' => Url::fromRoute('system.file_system_settings')->toString(), ':system-help' => Url::fromRoute('help.page', [ 'name' => 'system', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Restricting the maximum file size') . '</dt>'; - $output .= '<dd>' . t('The maximum file size that users can upload is limited by PHP settings of the server, but you can restrict by entering the desired value as the <em>Maximum upload size</em> setting. The maximum file size is automatically displayed to users in the help text of the file field.') . '</dd>'; - $output .= '<dt>' . t('Displaying files and descriptions') . '<dt>'; - $output .= '<dd>' . t('In the field settings, you can allow users to toggle whether individual files are displayed. In the display settings, you can then choose one of the following formats: <ul><li><em>Generic file</em> displays links to the files and adds icons that symbolize the file extensions. If <em>descriptions</em> are enabled and have been submitted, then the description is displayed instead of the file name.</li><li><em>URL to file</em> displays the full path to the file as plain text.</li><li><em>Table of files</em> lists links to the files and the file sizes in a table.</li><li><em>RSS enclosure</em> only displays the first file, and only in a RSS feed, formatted according to the RSS 2.0 syntax for enclosures.</li></ul> A file can still be linked to directly by its URI even if it is not displayed.') . '</dd>'; + $output .= '<dt>' . $this->t('Restricting the maximum file size') . '</dt>'; + $output .= '<dd>' . $this->t('The maximum file size that users can upload is limited by PHP settings of the server, but you can restrict by entering the desired value as the <em>Maximum upload size</em> setting. The maximum file size is automatically displayed to users in the help text of the file field.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying files and descriptions') . '<dt>'; + $output .= '<dd>' . $this->t('In the field settings, you can allow users to toggle whether individual files are displayed. In the display settings, you can then choose one of the following formats: <ul><li><em>Generic file</em> displays links to the files and adds icons that symbolize the file extensions. If <em>descriptions</em> are enabled and have been submitted, then the description is displayed instead of the file name.</li><li><em>URL to file</em> displays the full path to the file as plain text.</li><li><em>Table of files</em> lists links to the files and the file sizes in a table.</li><li><em>RSS enclosure</em> only displays the first file, and only in a RSS feed, formatted according to the RSS 2.0 syntax for enclosures.</li></ul> A file can still be linked to directly by its URI even if it is not displayed.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -138,46 +140,46 @@ public function formSystemFileSystemSettingsAlter(array &$form, FormStateInterfa $config = \Drupal::config('file.settings'); $form['filename_sanitization'] = [ '#type' => 'details', - '#title' => t('Sanitize filenames'), - '#description' => t('These settings only apply to new files as they are uploaded. Changes here do not affect existing file names.'), + '#title' => $this->t('Sanitize filenames'), + '#description' => $this->t('These settings only apply to new files as they are uploaded. Changes here do not affect existing file names.'), '#open' => TRUE, '#tree' => TRUE, ]; $form['filename_sanitization']['replacement_character'] = [ '#type' => 'select', - '#title' => t('Replacement character'), + '#title' => $this->t('Replacement character'), '#default_value' => $config->get('filename_sanitization.replacement_character'), '#options' => [ - '-' => t('Dash (-)'), - '_' => t('Underscore (_)'), + '-' => $this->t('Dash (-)'), + '_' => $this->t('Underscore (_)'), ], - '#description' => t('Used when replacing whitespace, replacing non-alphanumeric characters or transliterating unknown characters.'), + '#description' => $this->t('Used when replacing whitespace, replacing non-alphanumeric characters or transliterating unknown characters.'), ]; $form['filename_sanitization']['transliterate'] = [ '#type' => 'checkbox', - '#title' => t('Transliterate'), + '#title' => $this->t('Transliterate'), '#default_value' => $config->get('filename_sanitization.transliterate'), - '#description' => t('Transliteration replaces any characters that are not alphanumeric, underscores, periods or hyphens with the replacement character. It ensures filenames only contain ASCII characters. It is recommended to keep transliteration enabled.'), + '#description' => $this->t('Transliteration replaces any characters that are not alphanumeric, underscores, periods or hyphens with the replacement character. It ensures filenames only contain ASCII characters. It is recommended to keep transliteration enabled.'), ]; $form['filename_sanitization']['replace_whitespace'] = [ '#type' => 'checkbox', - '#title' => t('Replace whitespace with the replacement character'), + '#title' => $this->t('Replace whitespace with the replacement character'), '#default_value' => $config->get('filename_sanitization.replace_whitespace'), ]; $form['filename_sanitization']['replace_non_alphanumeric'] = [ '#type' => 'checkbox', - '#title' => t('Replace non-alphanumeric characters with the replacement character'), + '#title' => $this->t('Replace non-alphanumeric characters with the replacement character'), '#default_value' => $config->get('filename_sanitization.replace_non_alphanumeric'), - '#description' => t('Alphanumeric characters, dots <span aria-hidden="true">(.)</span>, underscores <span aria-hidden="true">(_)</span> and dashes <span aria-hidden="true">(-)</span> are preserved.'), + '#description' => $this->t('Alphanumeric characters, dots <span aria-hidden="true">(.)</span>, underscores <span aria-hidden="true">(_)</span> and dashes <span aria-hidden="true">(-)</span> are preserved.'), ]; $form['filename_sanitization']['deduplicate_separators'] = [ '#type' => 'checkbox', - '#title' => t('Replace sequences of dots, underscores and/or dashes with the replacement character'), + '#title' => $this->t('Replace sequences of dots, underscores and/or dashes with the replacement character'), '#default_value' => $config->get('filename_sanitization.deduplicate_separators'), ]; $form['filename_sanitization']['lowercase'] = [ '#type' => 'checkbox', - '#title' => t('Convert to lowercase'), + '#title' => $this->t('Convert to lowercase'), '#default_value' => $config->get('filename_sanitization.lowercase'), ]; $form['#submit'][] = 'file_system_settings_submit'; diff --git a/core/modules/file/src/Hook/FileViewsHooks.php b/core/modules/file/src/Hook/FileViewsHooks.php index 1149d5bd8b646ed62ebe17fc5da96065ba441d22..cdb764fdba5a8c77a48e4813b6b41cadce42142e 100644 --- a/core/modules/file/src/Hook/FileViewsHooks.php +++ b/core/modules/file/src/Hook/FileViewsHooks.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; use Drupal\views\FieldViewsDataProvider; @@ -15,6 +16,8 @@ */ class FileViewsHooks { + use StringTranslationTrait; + public function __construct( protected readonly EntityTypeManagerInterface $entityTypeManager, protected readonly EntityFieldManagerInterface $entityFieldManager, @@ -39,7 +42,7 @@ public function fieldViewsData(FieldStorageConfigInterface $field_storage): arra 'base' => 'file_managed', 'entity type' => 'file', 'base field' => 'fid', - 'label' => t('file from @field_name', [ + 'label' => $this->t('file from @field_name', [ '@field_name' => $field_storage->getName(), ]), ]; @@ -62,15 +65,15 @@ public function fieldViewsDataViewsDataAlter(array &$data, FieldStorageConfigInt $table_mapping = $this->entityTypeManager->getStorage($entity_type_id)->getTableMapping(); [$label] = $this->entityFieldManager->getFieldLabels($entity_type_id, $field_name); $data['file_managed'][$pseudo_field_name]['relationship'] = [ - 'title' => t('@entity using @field', [ + 'title' => $this->t('@entity using @field', [ '@entity' => $entity_type->getLabel(), '@field' => $label, ]), - 'label' => t('@field_name', [ + 'label' => $this->t('@field_name', [ '@field_name' => $field_name, ]), 'group' => $entity_type->getLabel(), - 'help' => t('Relate each @entity with a @field set to the file.', [ + 'help' => $this->t('Relate each @entity with a @field set to the file.', [ '@entity' => $entity_type->getLabel(), '@field' => $label, ]), diff --git a/core/modules/file/src/Hook/TokenHooks.php b/core/modules/file/src/Hook/TokenHooks.php index 80de5898260dbbe2f93b8cf4d461c7bd9ab230e6..6923858153a7414be9e17b0abbf71cca8d7036ab 100644 --- a/core/modules/file/src/Hook/TokenHooks.php +++ b/core/modules/file/src/Hook/TokenHooks.php @@ -10,6 +10,7 @@ use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\StringTranslation\ByteSizeMarkup; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Utility\Token; /** @@ -17,6 +18,8 @@ */ class TokenHooks { + use StringTranslationTrait; + public function __construct( private readonly Token $token, private readonly LanguageManagerInterface $languageManager, @@ -120,37 +123,37 @@ public function tokens($type, $tokens, array $data, array $options, BubbleableMe #[Hook('token_info')] public function tokenInfo(): array { $types['file'] = [ - 'name' => t("Files"), - 'description' => t("Tokens related to uploaded files."), + 'name' => $this->t("Files"), + 'description' => $this->t("Tokens related to uploaded files."), 'needs-data' => 'file', ]; // File related tokens. $file['fid'] = [ - 'name' => t("File ID"), - 'description' => t("The unique ID of the uploaded file."), + 'name' => $this->t("File ID"), + 'description' => $this->t("The unique ID of the uploaded file."), ]; - $file['uuid'] = ['name' => t('UUID'), 'description' => t('The UUID of the uploaded file.')]; - $file['name'] = ['name' => t("File name"), 'description' => t("The name of the file on disk.")]; + $file['uuid'] = ['name' => $this->t('UUID'), 'description' => $this->t('The UUID of the uploaded file.')]; + $file['name'] = ['name' => $this->t("File name"), 'description' => $this->t("The name of the file on disk.")]; $file['path'] = [ - 'name' => t("Path"), - 'description' => t("The location of the file relative to Drupal root."), + 'name' => $this->t("Path"), + 'description' => $this->t("The location of the file relative to Drupal root."), ]; - $file['mime'] = ['name' => t("MIME type"), 'description' => t("The MIME type of the file.")]; - $file['size'] = ['name' => t("File size"), 'description' => t("The size of the file.")]; - $file['url'] = ['name' => t("URL"), 'description' => t("The web-accessible URL for the file.")]; + $file['mime'] = ['name' => $this->t("MIME type"), 'description' => $this->t("The MIME type of the file.")]; + $file['size'] = ['name' => $this->t("File size"), 'description' => $this->t("The size of the file.")]; + $file['url'] = ['name' => $this->t("URL"), 'description' => $this->t("The web-accessible URL for the file.")]; $file['created'] = [ - 'name' => t("Created"), - 'description' => t("The date the file created."), + 'name' => $this->t("Created"), + 'description' => $this->t("The date the file created."), 'type' => 'date', ]; $file['changed'] = [ - 'name' => t("Changed"), - 'description' => t("The date the file was most recently changed."), + 'name' => $this->t("Changed"), + 'description' => $this->t("The date the file was most recently changed."), 'type' => 'date', ]; $file['owner'] = [ - 'name' => t("Owner"), - 'description' => t("The user who originally uploaded the file."), + 'name' => $this->t("Owner"), + 'description' => $this->t("The user who originally uploaded the file."), 'type' => 'user', ]; return ['types' => $types, 'tokens' => ['file' => $file]]; diff --git a/core/modules/filter/src/Hook/FilterHooks.php b/core/modules/filter/src/Hook/FilterHooks.php index bf779ce1e0a2240b7d022e84750f1a2afff6176e..e08779ad0be5034dcf77a2dc4ec563064d1b415a 100644 --- a/core/modules/filter/src/Hook/FilterHooks.php +++ b/core/modules/filter/src/Hook/FilterHooks.php @@ -2,6 +2,7 @@ namespace Drupal\filter\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class FilterHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,43 +22,43 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.filter': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Filter module allows administrators to configure text formats. Text formats change how HTML tags and other text will be <em>processed and displayed</em> in the site. They are used to transform text, and also help to defend your website against potentially damaging input from malicious users. Visual text editors can be associated with text formats by using the <a href=":editor_help">Text Editor module</a>. For more information, see the <a href=":filter_do">online documentation for the Filter module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Filter module allows administrators to configure text formats. Text formats change how HTML tags and other text will be <em>processed and displayed</em> in the site. They are used to transform text, and also help to defend your website against potentially damaging input from malicious users. Visual text editors can be associated with text formats by using the <a href=":editor_help">Text Editor module</a>. For more information, see the <a href=":filter_do">online documentation for the Filter module</a>.', [ ':filter_do' => 'https://www.drupal.org/documentation/modules/filter/', ':editor_help' => \Drupal::moduleHandler()->moduleExists('editor') ? Url::fromRoute('help.page', [ 'name' => 'editor', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing text formats') . '</dt>'; - $output .= '<dd>' . t('You can create and edit text formats on the <a href=":formats">Text formats page</a> (if the Text Editor module is installed, this page is named Text formats and editors). One text format is included by default: Plain text (which removes all HTML tags). Additional text formats may be created during installation. You can create a text format by clicking "<a href=":add_format">Add text format</a>".', [ + $output .= '<dt>' . $this->t('Managing text formats') . '</dt>'; + $output .= '<dd>' . $this->t('You can create and edit text formats on the <a href=":formats">Text formats page</a> (if the Text Editor module is installed, this page is named Text formats and editors). One text format is included by default: Plain text (which removes all HTML tags). Additional text formats may be created during installation. You can create a text format by clicking "<a href=":add_format">Add text format</a>".', [ ':formats' => Url::fromRoute('filter.admin_overview')->toString(), ':add_format' => Url::fromRoute('filter.format_add')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Assigning roles to text formats') . '</dt>'; - $output .= '<dd>' . t('You can define which users will be able to use each text format by selecting roles. To ensure security, anonymous and untrusted users should only have access to text formats that restrict them to either plain text or a safe set of HTML tags. This is because HTML tags can allow embedding malicious links or scripts in text. More trusted registered users may be granted permission to use less restrictive text formats in order to create rich text. <strong>Improper text format configuration is a security risk.</strong>') . '</dd>'; - $output .= '<dt>' . t('Selecting filters') . '</dt>'; - $output .= '<dd>' . t('Each text format uses filters that add, remove, or transform elements within user-entered text. For example, one filter removes unapproved HTML tags, while another transforms URLs into clickable links. Filters are applied in a specific order. They do not change the <em>stored</em> content: they define how it is processed and displayed.') . '</dd>'; - $output .= '<dd>' . t('Each filter can have additional configuration options. For example, for the "Limit allowed HTML tags" filter you need to define the list of HTML tags that the filter leaves in the text.') . '</dd>'; - $output .= '<dt>' . t('Using text fields with text formats') . '</dt>'; - $output .= '<dd>' . t('Text fields that allow text formats are those with "formatted" in the description. These are <em>Text (formatted, long, with summary)</em>, <em>Text (formatted)</em>, and <em>Text (formatted, long)</em>. You cannot change the type of field once a field has been created.') . '</dd>'; - $output .= '<dt>' . t('Choosing a text format') . '</dt>'; - $output .= '<dd>' . t('When creating or editing data in a field that has text formats enabled, users can select the format under the field from the Text format select list.') . '</dd>'; + $output .= '<dt>' . $this->t('Assigning roles to text formats') . '</dt>'; + $output .= '<dd>' . $this->t('You can define which users will be able to use each text format by selecting roles. To ensure security, anonymous and untrusted users should only have access to text formats that restrict them to either plain text or a safe set of HTML tags. This is because HTML tags can allow embedding malicious links or scripts in text. More trusted registered users may be granted permission to use less restrictive text formats in order to create rich text. <strong>Improper text format configuration is a security risk.</strong>') . '</dd>'; + $output .= '<dt>' . $this->t('Selecting filters') . '</dt>'; + $output .= '<dd>' . $this->t('Each text format uses filters that add, remove, or transform elements within user-entered text. For example, one filter removes unapproved HTML tags, while another transforms URLs into clickable links. Filters are applied in a specific order. They do not change the <em>stored</em> content: they define how it is processed and displayed.') . '</dd>'; + $output .= '<dd>' . $this->t('Each filter can have additional configuration options. For example, for the "Limit allowed HTML tags" filter you need to define the list of HTML tags that the filter leaves in the text.') . '</dd>'; + $output .= '<dt>' . $this->t('Using text fields with text formats') . '</dt>'; + $output .= '<dd>' . $this->t('Text fields that allow text formats are those with "formatted" in the description. These are <em>Text (formatted, long, with summary)</em>, <em>Text (formatted)</em>, and <em>Text (formatted, long)</em>. You cannot change the type of field once a field has been created.') . '</dd>'; + $output .= '<dt>' . $this->t('Choosing a text format') . '</dt>'; + $output .= '<dd>' . $this->t('When creating or editing data in a field that has text formats enabled, users can select the format under the field from the Text format select list.') . '</dd>'; $output .= '</dl>'; return $output; case 'filter.admin_overview': - $output = '<p>' . t('Text formats define how text is filtered for output and how HTML tags and other text is displayed, replaced, or removed. <strong>Improper text format configuration is a security risk.</strong> Learn more on the <a href=":filter_help">Filter module help page</a>.', [ + $output = '<p>' . $this->t('Text formats define how text is filtered for output and how HTML tags and other text is displayed, replaced, or removed. <strong>Improper text format configuration is a security risk.</strong> Learn more on the <a href=":filter_help">Filter module help page</a>.', [ ':filter_help' => Url::fromRoute('help.page', [ 'name' => 'filter', ])->toString(), ]) . '</p>'; - $output .= '<p>' . t('Text formats are presented on content editing pages in the order defined on this page. The first format available to a user will be selected by default.') . '</p>'; + $output .= '<p>' . $this->t('Text formats are presented on content editing pages in the order defined on this page. The first format available to a user will be selected by default.') . '</p>'; return $output; case 'entity.filter_format.edit_form': - $output = '<p>' . t('A text format contains filters that change the display of user input; for example, stripping out malicious HTML or making URLs clickable. Filters are executed from top to bottom and the order is important, since one filter may prevent another filter from doing its job. For example, when URLs are converted into links before disallowed HTML tags are removed, all links may be removed. When this happens, the order of filters may need to be rearranged.') . '</p>'; + $output = '<p>' . $this->t('A text format contains filters that change the display of user input; for example, stripping out malicious HTML or making URLs clickable. Filters are executed from top to bottom and the order is important, since one filter may prevent another filter from doing its job. For example, when URLs are converted into links before disallowed HTML tags are removed, all links may be removed. When this happens, the order of filters may need to be rearranged.') . '</p>'; return $output; } } @@ -106,8 +109,8 @@ public function theme() : array { public function filterSecureImageAlter(&$image): void { // Turn an invalid image into an error indicator. $image->setAttribute('src', base_path() . 'core/misc/icons/e32700/error.svg'); - $image->setAttribute('alt', t('Image removed.')); - $image->setAttribute('title', t('This image has been removed. For security reasons, only images from the local domain are allowed.')); + $image->setAttribute('alt', $this->t('Image removed.')); + $image->setAttribute('title', $this->t('This image has been removed. For security reasons, only images from the local domain are allowed.')); $image->setAttribute('height', '16'); $image->setAttribute('width', '16'); // Add a CSS class to aid in styling. diff --git a/core/modules/help/src/Hook/HelpHooks.php b/core/modules/help/src/Hook/HelpHooks.php index 55cb076775b17f3588d87bfd9c958099988aac53..b2367f7debb618dc3c6b76f4813124a1ee234138 100644 --- a/core/modules/help/src/Hook/HelpHooks.php +++ b/core/modules/help/src/Hook/HelpHooks.php @@ -3,6 +3,7 @@ namespace Drupal\help\Hook; use Drupal\Core\Block\BlockPluginInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class HelpHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,28 +22,28 @@ class HelpHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.main': - $output = '<h2>' . t('Getting Started') . '</h2>'; - $output .= '<p>' . t('Follow these steps to set up and start using your website:') . '</p>'; + $output = '<h2>' . $this->t('Getting Started') . '</h2>'; + $output .= '<p>' . $this->t('Follow these steps to set up and start using your website:') . '</p>'; $output .= '<ol>'; - $output .= '<li>' . t('<strong>Configure your website</strong> Once logged in, visit the <a href=":admin">Administration page</a>, where you may <a href=":config">customize and configure</a> all aspects of your website.', [ + $output .= '<li>' . $this->t('<strong>Configure your website</strong> Once logged in, visit the <a href=":admin">Administration page</a>, where you may <a href=":config">customize and configure</a> all aspects of your website.', [ ':admin' => Url::fromRoute('system.admin')->toString(), ':config' => Url::fromRoute('system.admin_config')->toString(), ]) . '</li>'; - $output .= '<li>' . t('<strong>Enable additional functionality</strong> Next, visit the <a href=":modules">Extend page</a> and install modules that suit your specific needs. You can find additional modules at the <a href=":download_modules">Drupal.org modules page</a>.', [ + $output .= '<li>' . $this->t('<strong>Enable additional functionality</strong> Next, visit the <a href=":modules">Extend page</a> and install modules that suit your specific needs. You can find additional modules at the <a href=":download_modules">Drupal.org modules page</a>.', [ ':modules' => Url::fromRoute('system.modules_list')->toString(), ':download_modules' => 'https://www.drupal.org/project/modules', ]) . '</li>'; - $output .= '<li>' . t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href=":themes">Appearance page</a>. You may choose from one of the included themes or download additional themes from the <a href=":download_themes">Drupal.org themes page</a>.', [ + $output .= '<li>' . $this->t('<strong>Customize your website design</strong> To change the "look and feel" of your website, visit the <a href=":themes">Appearance page</a>. You may choose from one of the included themes or download additional themes from the <a href=":download_themes">Drupal.org themes page</a>.', [ ':themes' => Url::fromRoute('system.themes_page')->toString(), ':download_themes' => 'https://www.drupal.org/project/themes', ]) . '</li>'; // Display a link to the create content page if Node module is // installed. if (\Drupal::moduleHandler()->moduleExists('node')) { - $output .= '<li>' . t('<strong>Start posting content</strong> Finally, you may <a href=":content">add new content</a> to your website.', [':content' => Url::fromRoute('node.add_page')->toString()]) . '</li>'; + $output .= '<li>' . $this->t('<strong>Start posting content</strong> Finally, you may <a href=":content">add new content</a> to your website.', [':content' => Url::fromRoute('node.add_page')->toString()]) . '</li>'; } $output .= '</ol>'; - $output .= '<p>' . t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', [ + $output .= '<p>' . $this->t('For more information, refer to the help listed on this page or to the <a href=":docs">online documentation</a> and <a href=":support">support</a> pages at <a href=":drupal">drupal.org</a>.', [ ':docs' => 'https://www.drupal.org/documentation', ':support' => 'https://www.drupal.org/support', ':drupal' => 'https://www.drupal.org', @@ -52,37 +55,37 @@ public function help($route_name, RouteMatchInterface $route_match) { $module_handler = \Drupal::moduleHandler(); $locale_help = $module_handler->moduleExists('locale') ? Url::fromRoute('help.page', ['name' => 'locale'])->toString() : '#'; $search_help = $module_handler->moduleExists('search') ? Url::fromRoute('help.page', ['name' => 'search'])->toString() : '#'; - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Help module generates <a href=":help-page">Help topics and reference pages</a> to guide you through the use and configuration of modules, and provides a Help block with page-level help. The reference pages are a starting point for <a href=":handbook">Drupal.org online documentation</a> pages that contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the <a href=":help">online documentation for the Help module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Help module generates <a href=":help-page">Help topics and reference pages</a> to guide you through the use and configuration of modules, and provides a Help block with page-level help. The reference pages are a starting point for <a href=":handbook">Drupal.org online documentation</a> pages that contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the <a href=":help">online documentation for the Help module</a>.', [ ':help' => 'https://www.drupal.org/documentation/modules/help/', ':handbook' => 'https://www.drupal.org/documentation', ':help-page' => Url::fromRoute('help.main')->toString(), ]) . '</p>'; - $output .= '<p>' . t('Help topics provided by modules and themes are also part of the Help module. If the core Search module is installed, these topics are searchable. For more information, see the <a href=":online">online documentation, Help Topic Standards</a>.', [ + $output .= '<p>' . $this->t('Help topics provided by modules and themes are also part of the Help module. If the core Search module is installed, these topics are searchable. For more information, see the <a href=":online">online documentation, Help Topic Standards</a>.', [ ':online' => 'https://www.drupal.org/docs/develop/managing-a-drupalorg-theme-module-or-distribution-project/documenting-your-project/help-topic-standards', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Providing a help reference') . '</dt>'; - $output .= '<dd>' . t('The Help module displays explanations for using each module listed on the main <a href=":help">Help reference page</a>.', [':help' => Url::fromRoute('help.main')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Providing page-specific help') . '</dt>'; - $output .= '<dd>' . t('Page-specific help text provided by modules is displayed in the Help block. This block can be placed and configured on the <a href=":blocks">Block layout page</a>.', [ + $output .= '<dt>' . $this->t('Providing a help reference') . '</dt>'; + $output .= '<dd>' . $this->t('The Help module displays explanations for using each module listed on the main <a href=":help">Help reference page</a>.', [':help' => Url::fromRoute('help.main')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Providing page-specific help') . '</dt>'; + $output .= '<dd>' . $this->t('Page-specific help text provided by modules is displayed in the Help block. This block can be placed and configured on the <a href=":blocks">Block layout page</a>.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Viewing help topics') . '</dt>'; - $output .= '<dd>' . t('The top-level help topics are listed on the main <a href=":help_page">Help page</a>. Links to other topics, including non-top-level help topics, can be found under the "Related" heading when viewing a topic page.', [':help_page' => $help_home]) . '</dd>'; - $output .= '<dt>' . t('Providing help topics') . '</dt>'; - $output .= '<dd>' . t("Modules and themes can provide help topics as Twig-file-based plugins in a project sub-directory called <em>help_topics</em>; plugin meta-data is provided in YAML front matter within each Twig file. Plugin-based help topics provided by modules and themes will automatically be updated when a module or theme is updated. Use the plugins in <em>core/modules/help/help_topics</em> as a guide when writing and formatting a help topic plugin for your theme or module.") . '</dd>'; - $output .= '<dt>' . t('Translating help topics') . '</dt>'; - $output .= '<dd>' . t('The title and body text of help topics provided by contributed modules and themes are translatable using the <a href=":locale_help">Interface Translation module</a>. Topics provided by custom modules and themes are also translatable if they have been viewed at least once in a non-English language, which triggers putting their translatable text into the translation database.', [':locale_help' => $locale_help]) . '</dd>'; - $output .= '<dt>' . t('Configuring help search') . '</dt>'; - $output .= '<dd>' . t('To search help, you will need to install the core Search module, configure a search page, and add a search block to the Help page or another administrative page. (A search page is provided automatically, and if you use the core Claro administrative theme, a help search block is shown on the main Help page.) Then users with search permissions, and permission to view help, will be able to search help. See the <a href=":search_help">Search module help page</a> for more information.', [':search_help' => $search_help]) . '</dd>'; + $output .= '<dt>' . $this->t('Viewing help topics') . '</dt>'; + $output .= '<dd>' . $this->t('The top-level help topics are listed on the main <a href=":help_page">Help page</a>. Links to other topics, including non-top-level help topics, can be found under the "Related" heading when viewing a topic page.', [':help_page' => $help_home]) . '</dd>'; + $output .= '<dt>' . $this->t('Providing help topics') . '</dt>'; + $output .= '<dd>' . $this->t("Modules and themes can provide help topics as Twig-file-based plugins in a project sub-directory called <em>help_topics</em>; plugin meta-data is provided in YAML front matter within each Twig file. Plugin-based help topics provided by modules and themes will automatically be updated when a module or theme is updated. Use the plugins in <em>core/modules/help/help_topics</em> as a guide when writing and formatting a help topic plugin for your theme or module.") . '</dd>'; + $output .= '<dt>' . $this->t('Translating help topics') . '</dt>'; + $output .= '<dd>' . $this->t('The title and body text of help topics provided by contributed modules and themes are translatable using the <a href=":locale_help">Interface Translation module</a>. Topics provided by custom modules and themes are also translatable if they have been viewed at least once in a non-English language, which triggers putting their translatable text into the translation database.', [':locale_help' => $locale_help]) . '</dd>'; + $output .= '<dt>' . $this->t('Configuring help search') . '</dt>'; + $output .= '<dd>' . $this->t('To search help, you will need to install the core Search module, configure a search page, and add a search block to the Help page or another administrative page. (A search page is provided automatically, and if you use the core Claro administrative theme, a help search block is shown on the main Help page.) Then users with search permissions, and permission to view help, will be able to search help. See the <a href=":search_help">Search module help page</a> for more information.', [':search_help' => $search_help]) . '</dd>'; $output .= '</dl>'; return ['#markup' => $output]; case 'help.help_topic': $help_home = Url::fromRoute('help.main')->toString(); - return '<p>' . t('See the <a href=":help_page">Help page</a> for more topics.', [':help_page' => $help_home]) . '</p>'; + return '<p>' . $this->t('See the <a href=":help_page">Help page</a> for more topics.', [':help_page' => $help_home]) . '</p>'; } } diff --git a/core/modules/history/src/Hook/HistoryHooks.php b/core/modules/history/src/Hook/HistoryHooks.php index 56831e2a354ba6529754792b732646ff04ad7545..7508305f705dd7f33ef990d4274ffcccf74e376c 100644 --- a/core/modules/history/src/Hook/HistoryHooks.php +++ b/core/modules/history/src/Hook/HistoryHooks.php @@ -2,6 +2,7 @@ namespace Drupal\history\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\UserInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; @@ -14,6 +15,8 @@ */ class HistoryHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -21,8 +24,8 @@ class HistoryHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.history': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The History module keeps track of which content a user has read. It marks content as <em>new</em> or <em>updated</em> depending on the last time the user viewed it. History records that are older than one month are removed during cron, which means that content older than one month is always considered <em>read</em>. The History module does not have a user interface but it provides a filter to <a href=":views-help">Views</a> to show new or updated content. For more information, see the <a href=":url">online documentation for the History module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The History module keeps track of which content a user has read. It marks content as <em>new</em> or <em>updated</em> depending on the last time the user viewed it. History records that are older than one month are removed during cron, which means that content older than one month is always considered <em>read</em>. The History module does not have a user interface but it provides a filter to <a href=":views-help">Views</a> to show new or updated content. For more information, see the <a href=":url">online documentation for the History module</a>.', [ ':views-help' => \Drupal::moduleHandler()->moduleExists('views') ? Url::fromRoute('help.page', [ 'name' => 'views', ])->toString() : '#', diff --git a/core/modules/history/src/Hook/HistoryViewsHooks.php b/core/modules/history/src/Hook/HistoryViewsHooks.php index 6f79d176a4c066922d0df2a66f193ee2ce9f4e0d..35d018263240bdac4a81c721da3f8553312354eb 100644 --- a/core/modules/history/src/Hook/HistoryViewsHooks.php +++ b/core/modules/history/src/Hook/HistoryViewsHooks.php @@ -3,12 +3,15 @@ namespace Drupal\history\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for history. */ class HistoryViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data(). */ @@ -18,7 +21,7 @@ public function viewsData(): array { // We're actually defining a specific instance of the table, so let's // alias it so that we can later add the real table for other purposes if we // need it. - $data['history']['table']['group'] = t('Content'); + $data['history']['table']['group'] = $this->t('Content'); // Explain how this table joins to others. $data['history']['table']['join'] = [ // Directly links to node table. @@ -36,13 +39,13 @@ public function viewsData(): array { ], ]; $data['history']['timestamp'] = [ - 'title' => t('Has new content'), + 'title' => $this->t('Has new content'), 'field' => [ 'id' => 'history_user_timestamp', - 'help' => t('Show a marker if the content is new or updated.'), + 'help' => $this->t('Show a marker if the content is new or updated.'), ], 'filter' => [ - 'help' => t('Show only content that is new or updated.'), + 'help' => $this->t('Show only content that is new or updated.'), 'id' => 'history_user_timestamp', ], ]; diff --git a/core/modules/image/src/Hook/ImageHooks.php b/core/modules/image/src/Hook/ImageHooks.php index c65fd59d3b604d710d3a7625636b6009ba6aa358..f864ee9a06a22c914b91ddcc63ee80dfdb152090 100644 --- a/core/modules/image/src/Hook/ImageHooks.php +++ b/core/modules/image/src/Hook/ImageHooks.php @@ -3,6 +3,7 @@ namespace Drupal\image\Hook; use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldConfigInterface; use Drupal\field\FieldStorageConfigInterface; use Drupal\Core\Entity\EntityInterface; @@ -18,6 +19,8 @@ */ class ImageHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -27,8 +30,8 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'help.page.image': $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'; $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Image module allows you to create fields that contain image files and to configure <a href=":image_styles">Image styles</a> that can be used to manipulate the display of images. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for terminology and general information on entities, fields, and how to create and manage fields. For more information, see the <a href=":image_documentation">online documentation for the Image module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Image module allows you to create fields that contain image files and to configure <a href=":image_styles">Image styles</a> that can be used to manipulate the display of images. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for terminology and general information on entities, fields, and how to create and manage fields. For more information, see the <a href=":image_documentation">online documentation for the Image module</a>.', [ ':image_styles' => Url::fromRoute('entity.image_style.collection')->toString(), ':field' => Url::fromRoute('help.page', [ 'name' => 'field', @@ -36,32 +39,32 @@ public function help($route_name, RouteMatchInterface $route_match) { ':field_ui' => $field_ui_url, ':image_documentation' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/image-module/working-with-images', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; - $output .= '<dt>' . t('Defining image styles') . '</dt>'; - $output .= '<dd>' . t('The concept of image styles is that you can upload a single image but display it in several ways; each display variation, or <em>image style</em>, is the result of applying one or more <em>effects</em> to the original image. As an example, you might upload a high-resolution image with a 4:3 aspect ratio, and display it scaled down, square cropped, or black-and-white (or any combination of these effects). The Image module provides a way to do this efficiently: you configure an image style with the desired effects on the <a href=":image">Image styles page</a>, and the first time a particular image is requested in that style, the effects are applied. The resulting image is saved, and the next time that same style is requested, the saved image is retrieved without the need to recalculate the effects. Drupal core provides several effects that you can use to define styles; others may be provided by contributed modules.', [ + $output .= '<h2>' . $this->t('Uses') . '</h2>'; + $output .= '<dt>' . $this->t('Defining image styles') . '</dt>'; + $output .= '<dd>' . $this->t('The concept of image styles is that you can upload a single image but display it in several ways; each display variation, or <em>image style</em>, is the result of applying one or more <em>effects</em> to the original image. As an example, you might upload a high-resolution image with a 4:3 aspect ratio, and display it scaled down, square cropped, or black-and-white (or any combination of these effects). The Image module provides a way to do this efficiently: you configure an image style with the desired effects on the <a href=":image">Image styles page</a>, and the first time a particular image is requested in that style, the effects are applied. The resulting image is saved, and the next time that same style is requested, the saved image is retrieved without the need to recalculate the effects. Drupal core provides several effects that you can use to define styles; others may be provided by contributed modules.', [ ':image' => Url::fromRoute('entity.image_style.collection')->toString(), ]); - $output .= '<dt>' . t('Naming image styles') . '</dt>'; - $output .= '<dd>' . t('When you define an image style, you will need to choose a displayed name and a machine name. The displayed name is shown in administrative pages, and the machine name is used to generate the URL for accessing an image processed in that style. There are two common approaches to naming image styles: either based on the effects being applied (for example, <em>Square 85x85</em>), or based on where you plan to use it (for example, <em>Profile picture</em>).') . '</dd>'; - $output .= '<dt>' . t('Configuring image fields') . '</dt>'; - $output .= '<dd>' . t('A few of the settings for image fields are defined once when you create the field and cannot be changed later; these include the choice of public or private file storage and the number of images that can be stored in the field. The rest of the settings can be edited later; these settings include the field label, help text, allowed file extensions, image dimensions restrictions, and the subdirectory in the public or private file storage where the images will be stored. The editable settings can also have different values for different entity sub-types; for instance, if your image field is used on both Page and Article content types, you can store the files in a different subdirectory for the two content types.') . '</dd>'; - $output .= '<dd>' . t('For accessibility and search engine optimization, all images that convey meaning on websites should have alternate text. Drupal also allows entry of title text for images, but it can lead to confusion for screen reader users and its use is not recommended. Image fields can be configured so that alternate and title text fields are enabled or disabled; if enabled, the fields can be set to be required. The recommended setting is to enable and require alternate text and disable title text.') . '</dd>'; - $output .= '<dd>' . t('When you create an image field, you will need to choose whether the uploaded images will be stored in the public or private file directory defined in your settings.php file and shown on the <a href=":file-system">File system page</a>. This choice cannot be changed later. You can also configure your field to store files in a subdirectory of the public or private directory; this setting can be changed later and can be different for each entity sub-type using the field. For more information on file storage, see the <a href=":system-help">System module help page</a>.', [ + $output .= '<dt>' . $this->t('Naming image styles') . '</dt>'; + $output .= '<dd>' . $this->t('When you define an image style, you will need to choose a displayed name and a machine name. The displayed name is shown in administrative pages, and the machine name is used to generate the URL for accessing an image processed in that style. There are two common approaches to naming image styles: either based on the effects being applied (for example, <em>Square 85x85</em>), or based on where you plan to use it (for example, <em>Profile picture</em>).') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring image fields') . '</dt>'; + $output .= '<dd>' . $this->t('A few of the settings for image fields are defined once when you create the field and cannot be changed later; these include the choice of public or private file storage and the number of images that can be stored in the field. The rest of the settings can be edited later; these settings include the field label, help text, allowed file extensions, image dimensions restrictions, and the subdirectory in the public or private file storage where the images will be stored. The editable settings can also have different values for different entity sub-types; for instance, if your image field is used on both Page and Article content types, you can store the files in a different subdirectory for the two content types.') . '</dd>'; + $output .= '<dd>' . $this->t('For accessibility and search engine optimization, all images that convey meaning on websites should have alternate text. Drupal also allows entry of title text for images, but it can lead to confusion for screen reader users and its use is not recommended. Image fields can be configured so that alternate and title text fields are enabled or disabled; if enabled, the fields can be set to be required. The recommended setting is to enable and require alternate text and disable title text.') . '</dd>'; + $output .= '<dd>' . $this->t('When you create an image field, you will need to choose whether the uploaded images will be stored in the public or private file directory defined in your settings.php file and shown on the <a href=":file-system">File system page</a>. This choice cannot be changed later. You can also configure your field to store files in a subdirectory of the public or private directory; this setting can be changed later and can be different for each entity sub-type using the field. For more information on file storage, see the <a href=":system-help">System module help page</a>.', [ ':file-system' => Url::fromRoute('system.file_system_settings')->toString(), ':system-help' => Url::fromRoute('help.page', [ 'name' => 'system', ])->toString(), ]) . '</dd>'; - $output .= '<dd>' . t('The maximum file size that can be uploaded is limited by PHP settings of the server, but you can restrict it further by configuring a <em>Maximum upload size</em> in the field settings (this setting can be changed later). The maximum file size, either from PHP server settings or field configuration, is automatically displayed to users in the help text of the image field.') . '</dd>'; - $output .= '<dd>' . t('You can also configure a minimum and/or maximum dimensions for uploaded images. Images that are too small will be rejected. Images that are to large will be resized. During the resizing the <a href="http://wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image will be lost.') . '</dd>'; - $output .= '<dd>' . t('You can also configure a default image that will be used if no image is uploaded in an image field. This default can be defined for all instances of the field in the field storage settings when you create a field, and the setting can be overridden for each entity sub-type that uses the field.') . '</dd>'; - $output .= '<dt>' . t('Configuring displays and form displays') . '</dt>'; - $output .= '<dd>' . t('On the <em>Manage display</em> page, you can choose the image formatter, which determines the image style used to display the image in each display mode and whether or not to display the image as a link. On the <em>Manage form display</em> page, you can configure the image upload widget, including setting the preview image style shown on the entity edit form.') . '</dd>'; + $output .= '<dd>' . $this->t('The maximum file size that can be uploaded is limited by PHP settings of the server, but you can restrict it further by configuring a <em>Maximum upload size</em> in the field settings (this setting can be changed later). The maximum file size, either from PHP server settings or field configuration, is automatically displayed to users in the help text of the image field.') . '</dd>'; + $output .= '<dd>' . $this->t('You can also configure a minimum and/or maximum dimensions for uploaded images. Images that are too small will be rejected. Images that are to large will be resized. During the resizing the <a href="http://wikipedia.org/wiki/Exchangeable_image_file_format">EXIF data</a> in the image will be lost.') . '</dd>'; + $output .= '<dd>' . $this->t('You can also configure a default image that will be used if no image is uploaded in an image field. This default can be defined for all instances of the field in the field storage settings when you create a field, and the setting can be overridden for each entity sub-type that uses the field.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring displays and form displays') . '</dt>'; + $output .= '<dd>' . $this->t('On the <em>Manage display</em> page, you can choose the image formatter, which determines the image style used to display the image in each display mode and whether or not to display the image as a link. On the <em>Manage form display</em> page, you can configure the image upload widget, including setting the preview image style shown on the entity edit form.') . '</dd>'; $output .= '</dl>'; return $output; case 'entity.image_style.collection': - return '<p>' . t('Image styles commonly provide thumbnail sizes by scaling and cropping images, but can also add various effects before an image is displayed. When an image is displayed with a style, a new file is created and the original image is left unchanged.') . '</p>'; + return '<p>' . $this->t('Image styles commonly provide thumbnail sizes by scaling and cropping images, but can also add various effects before an image is displayed. When an image is displayed with a style, a new file is created and the original image is left unchanged.') . '</p>'; case 'image.effect_add_form': $effect = \Drupal::service('plugin.manager.image.effect')->getDefinition($route_match->getParameter('image_effect')); diff --git a/core/modules/image/src/Hook/ImageViewsHooks.php b/core/modules/image/src/Hook/ImageViewsHooks.php index 484cbe71712dfe7b0e342c855d4e088ca233b612..1e68f581c2b1f962a86bfa38e7ae42c376c7d0b2 100644 --- a/core/modules/image/src/Hook/ImageViewsHooks.php +++ b/core/modules/image/src/Hook/ImageViewsHooks.php @@ -4,6 +4,7 @@ use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; /** @@ -11,6 +12,8 @@ */ class ImageViewsHooks { + use StringTranslationTrait; + public function __construct( protected readonly EntityFieldManagerInterface $entityFieldManager, ) {} @@ -33,7 +36,7 @@ public function fieldViewsData(FieldStorageConfigInterface $field_storage): arra 'base' => 'file_managed', 'entity type' => 'file', 'base field' => 'fid', - 'label' => t('image from @field_name', [ + 'label' => $this->t('image from @field_name', [ '@field_name' => $field_storage->getName(), ]), ]; @@ -57,14 +60,14 @@ public function fieldViewsDataViewsDataAlter(array &$data, FieldStorageConfigInt $table_mapping = $entity_type_manager->getStorage($entity_type_id)->getTableMapping(); [$label] = $this->entityFieldManager->getFieldLabels($entity_type_id, $field_name); $data['file_managed'][$pseudo_field_name]['relationship'] = [ - 'title' => t('@entity using @field', [ + 'title' => $this->t('@entity using @field', [ '@entity' => $entity_type->getLabel(), '@field' => $label, ]), - 'label' => t('@field_name', [ + 'label' => $this->t('@field_name', [ '@field_name' => $field_name, ]), - 'help' => t('Relate each @entity with a @field set to the image.', [ + 'help' => $this->t('Relate each @entity with a @field set to the image.', [ '@entity' => $entity_type->getLabel(), '@field' => $label, ]), diff --git a/core/modules/inline_form_errors/src/Hook/InlineFormErrorsHooks.php b/core/modules/inline_form_errors/src/Hook/InlineFormErrorsHooks.php index 30d06564440b5a2b5b88eb186d4ba50271ca8b91..97df9077f85f2ae389f4e3944ebf7e95bf5a1fa7 100644 --- a/core/modules/inline_form_errors/src/Hook/InlineFormErrorsHooks.php +++ b/core/modules/inline_form_errors/src/Hook/InlineFormErrorsHooks.php @@ -2,6 +2,7 @@ namespace Drupal\inline_form_errors\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\inline_form_errors\RenderElementHelper; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class InlineFormErrorsHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,16 +22,16 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.inline_form_errors': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Inline Form Errors module makes it easier for users to identify which errors need to be resolved by providing a summary of all errors and by placing the individual error messages next to the form elements themselves. For more information, see the <a href=":inline_form_error">online documentation for the Inline Form Errors module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Inline Form Errors module makes it easier for users to identify which errors need to be resolved by providing a summary of all errors and by placing the individual error messages next to the form elements themselves. For more information, see the <a href=":inline_form_error">online documentation for the Inline Form Errors module</a>.', [ ':inline_form_error' => 'https://www.drupal.org/docs/8/core/modules/inline-form-errors', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Displaying error messages') . '</dt>'; - $output .= '<dd>' . t('When a form is not filled in correctly (for example, if a required field is left blank), a warning message is displayed at the top of the form. This message links to the affected form elements, and individual error messages are displayed next to each form element.') . '</dd>'; - $output .= '<dt>' . t('Displaying error messages in browsers with HTML5 form validation') . '</dt>'; - $output .= '<dd>' . t('In browsers that support HTML5 form validation, users will first see the error messages generated by their browser. In this case, the inline form error messages are only displayed after the HTML5 validation errors have been resolved.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying error messages') . '</dt>'; + $output .= '<dd>' . $this->t('When a form is not filled in correctly (for example, if a required field is left blank), a warning message is displayed at the top of the form. This message links to the affected form elements, and individual error messages are displayed next to each form element.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying error messages in browsers with HTML5 form validation') . '</dt>'; + $output .= '<dd>' . $this->t('In browsers that support HTML5 form validation, users will first see the error messages generated by their browser. In this case, the inline form error messages are only displayed after the HTML5 validation errors have been resolved.') . '</dd>'; return $output; } } diff --git a/core/modules/jsonapi/src/Hook/JsonapiHooks.php b/core/modules/jsonapi/src/Hook/JsonapiHooks.php index 1aecba2edd44081502a75ebc781a841e2fef4985..bafe5467a5b0d27a6a5411c6dd97883e1fc968e1 100644 --- a/core/modules/jsonapi/src/Hook/JsonapiHooks.php +++ b/core/modules/jsonapi/src/Hook/JsonapiHooks.php @@ -6,6 +6,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\jsonapi\Routing\Routes; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -15,6 +16,8 @@ */ class JsonapiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,21 +25,21 @@ class JsonapiHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.jsonapi': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The JSON:API module is a fully compliant implementation of the <a href=":spec">JSON:API Specification</a>. By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus on what matters: your application. Clients built around JSON:API are able to take advantage of features like efficient response caching, which can sometimes eliminate network requests entirely. For more information, see the <a href=":docs">online documentation for the JSON:API module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The JSON:API module is a fully compliant implementation of the <a href=":spec">JSON:API Specification</a>. By following shared conventions, you can increase productivity, take advantage of generalized tooling, and focus on what matters: your application. Clients built around JSON:API are able to take advantage of features like efficient response caching, which can sometimes eliminate network requests entirely. For more information, see the <a href=":docs">online documentation for the JSON:API module</a>.', [ ':spec' => 'https://jsonapi.org', ':docs' => 'https://www.drupal.org/docs/8/modules/json-api', ]) . '</p>'; $output .= '<dl>'; - $output .= '<dt>' . t('General') . '</dt>'; - $output .= '<dd>' . t('JSON:API is a particular implementation of REST that provides conventions for resource relationships, collections, filters, pagination, and sorting. These conventions help developers build clients faster and encourages reuse of code.') . '</dd>'; - $output .= '<dd>' . t('The <a href=":jsonapi-docs">JSON:API</a> and <a href=":rest-docs">RESTful Web Services</a> modules serve similar purposes. <a href=":comparison">Read the comparison of the RESTFul Web Services and JSON:API modules</a> to determine the best choice for your site.', [ + $output .= '<dt>' . $this->t('General') . '</dt>'; + $output .= '<dd>' . $this->t('JSON:API is a particular implementation of REST that provides conventions for resource relationships, collections, filters, pagination, and sorting. These conventions help developers build clients faster and encourages reuse of code.') . '</dd>'; + $output .= '<dd>' . $this->t('The <a href=":jsonapi-docs">JSON:API</a> and <a href=":rest-docs">RESTful Web Services</a> modules serve similar purposes. <a href=":comparison">Read the comparison of the RESTFul Web Services and JSON:API modules</a> to determine the best choice for your site.', [ ':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/json-api', ':rest-docs' => 'https://www.drupal.org/docs/8/core/modules/rest', ':comparison' => 'https://www.drupal.org/docs/8/modules/jsonapi/jsonapi-vs-cores-rest-module', ]) . '</dd>'; - $output .= '<dd>' . t('Some multilingual features currently do not work well with JSON:API. See the <a href=":jsonapi-docs">JSON:API multilingual support documentation</a> for more information on the current status of multilingual support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/translations']) . '</dd>'; - $output .= '<dd>' . t('Revision support is currently read-only and only for the "Content" and "Media" entity types in JSON:API. See the <a href=":jsonapi-docs">JSON:API revision support documentation</a> for more information on the current status of revision support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/revisions']) . '</dd>'; + $output .= '<dd>' . $this->t('Some multilingual features currently do not work well with JSON:API. See the <a href=":jsonapi-docs">JSON:API multilingual support documentation</a> for more information on the current status of multilingual support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/translations']) . '</dd>'; + $output .= '<dd>' . $this->t('Revision support is currently read-only and only for the "Content" and "Media" entity types in JSON:API. See the <a href=":jsonapi-docs">JSON:API revision support documentation</a> for more information on the current status of revision support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/revisions']) . '</dd>'; $output .= '</dl>'; return $output; } @@ -50,7 +53,7 @@ public function help($route_name, RouteMatchInterface $route_match) { public function modulesInstalled($modules): void { $potential_conflicts = ['content_translation', 'config_translation', 'language']; if (!empty(array_intersect($modules, $potential_conflicts))) { - \Drupal::messenger()->addWarning(t('Some multilingual features currently do not work well with JSON:API. See the <a href=":jsonapi-docs">JSON:API multilingual support documentation</a> for more information on the current status of multilingual support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/translations'])); + \Drupal::messenger()->addWarning($this->t('Some multilingual features currently do not work well with JSON:API. See the <a href=":jsonapi-docs">JSON:API multilingual support documentation</a> for more information on the current status of multilingual support.', [':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/jsonapi/translations'])); } } diff --git a/core/modules/language/src/Hook/LanguageHooks.php b/core/modules/language/src/Hook/LanguageHooks.php index 0f68d75dc6e7ec99ec3af9e88c903e23f2575101..ef0b7c84861ef2f168604f307845af0b81e5026e 100644 --- a/core/modules/language/src/Hook/LanguageHooks.php +++ b/core/modules/language/src/Hook/LanguageHooks.php @@ -3,6 +3,7 @@ namespace Drupal\language\Hook; use Drupal\Core\Access\AccessResultInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrlFallback; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; @@ -27,6 +28,8 @@ */ class LanguageHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -35,8 +38,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.language': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Language module allows you to configure the languages used on your site, and provides information for the <a href=":content">Content Translation</a>, <a href=":interface">Interface Translation</a>, and <a href=":configuration">Configuration Translation</a> modules, if they are installed. For more information, see the <a href=":doc_url">online documentation for the Language module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Language module allows you to configure the languages used on your site, and provides information for the <a href=":content">Content Translation</a>, <a href=":interface">Interface Translation</a>, and <a href=":configuration">Configuration Translation</a> modules, if they are installed. For more information, see the <a href=":doc_url">online documentation for the Language module</a>.', [ ':doc_url' => 'https://www.drupal.org/documentation/modules/language', ':content' => \Drupal::moduleHandler()->moduleExists('content_translation') ? Url::fromRoute('help.page', [ 'name' => 'content_translation', @@ -48,90 +51,90 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'config_translation', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Adding languages') . '</dt>'; - $output .= '<dd>' . t('You can add languages on the <a href=":language_list">Languages</a> page by selecting <em>Add language</em> and choosing a language from the drop-down menu. This language is then displayed in the languages list, where it can be configured further. If the <a href=":interface">Interface translation module</a> is installed, and the <em>translation server</em> is set as a translation source, then the interface translation for this language is automatically downloaded as well.', [ + $output .= '<dt>' . $this->t('Adding languages') . '</dt>'; + $output .= '<dd>' . $this->t('You can add languages on the <a href=":language_list">Languages</a> page by selecting <em>Add language</em> and choosing a language from the drop-down menu. This language is then displayed in the languages list, where it can be configured further. If the <a href=":interface">Interface translation module</a> is installed, and the <em>translation server</em> is set as a translation source, then the interface translation for this language is automatically downloaded as well.', [ ':language_list' => Url::fromRoute('entity.configurable_language.collection')->toString(), ':interface' => \Drupal::moduleHandler()->moduleExists('locale') ? Url::fromRoute('help.page', [ 'name' => 'locale', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Adding custom languages') . '</dt>'; - $output .= '<dd>' . t('You can add a language that is not provided in the drop-down list by choosing <em>Custom language</em> at the end of the list. You then have to configure its language code, name, and direction in the form provided.') . '</dd>'; - $output .= '<dt>' . t('Configuring content languages') . '</dt>'; - $output .= '<dd>' . t('By default, content is created in the site\'s default language and no language selector is displayed on content creation pages. On the <a href=":content_language">Content language</a> page you can customize the language configuration for any supported content entity on your site (for example for content types or menu links). After choosing an entity, you are provided with a drop-down menu to set the default language and a check-box to display language selectors.', [ + $output .= '<dt>' . $this->t('Adding custom languages') . '</dt>'; + $output .= '<dd>' . $this->t('You can add a language that is not provided in the drop-down list by choosing <em>Custom language</em> at the end of the list. You then have to configure its language code, name, and direction in the form provided.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring content languages') . '</dt>'; + $output .= '<dd>' . $this->t('By default, content is created in the site\'s default language and no language selector is displayed on content creation pages. On the <a href=":content_language">Content language</a> page you can customize the language configuration for any supported content entity on your site (for example for content types or menu links). After choosing an entity, you are provided with a drop-down menu to set the default language and a check-box to display language selectors.', [ ':content_language' => Url::fromRoute('language.content_settings_page')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Adding a language switcher block') . '</dt>'; - $output .= '<dd>' . t('If the Block module is installed, then you can add a language switcher block on the <a href=":blocks">Block layout</a> page to allow users to switch between languages.', [ + $output .= '<dt>' . $this->t('Adding a language switcher block') . '</dt>'; + $output .= '<dd>' . $this->t('If the Block module is installed, then you can add a language switcher block on the <a href=":blocks">Block layout</a> page to allow users to switch between languages.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Making a block visible per language') . '</dt>'; - $output .= '<dd>' . t('If the Block module is installed, then the Language module allows you to set the visibility of a block based on selected languages on the <a href=":blocks">Block layout</a> page.', [ + $output .= '<dt>' . $this->t('Making a block visible per language') . '</dt>'; + $output .= '<dd>' . $this->t('If the Block module is installed, then the Language module allows you to set the visibility of a block based on selected languages on the <a href=":blocks">Block layout</a> page.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Choosing user languages') . '</dt>'; - $output .= '<dd>' . t("Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user's language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user's profile page if the <em>Account administration pages</em> method is enabled (see below).") . '</dd>'; - $output .= '<dt>' . t('Language detection and selection') . '</dt>'; - $output .= '<dd>' . t('The <a href=":detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', [':detection' => Url::fromRoute('language.negotiation')->toString()]); - $output .= '<ul><li>' . t('<em>URL</em> sets the interface language based on a path prefix or domain (for example specifying <em>de</em> for German would result in URLs like <em>example.com/de/contact</em>). The default language does not require a path prefix, but can have one assigned as well. If the language detection is done by domain name, a domain needs to be specified for each language.') . '</li>'; - $output .= '<li>' . t('<em>Session</em> determines the interface language from a request or session parameter (for example <em>example.com?language=de</em> would set the interface language to German based on the use of <em>de</em> as the <em>language</em> parameter).') . '</li>'; - $output .= '<li>' . t("<em>User</em> follows the language configuration set on the user's profile page.") . '</li>'; - $output .= '<li>' . t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href=":language_list">language codes</a> used on your site.', [ + $output .= '<dt>' . $this->t('Choosing user languages') . '</dt>'; + $output .= '<dd>' . $this->t("Users can choose a <em>Site language</em> on their profile page. This language is used for email messages, and can be used by modules to determine a user's language. It can also be used for interface text, if the <em>User</em> method is enabled as a <em>Detection and selection</em> method (see below). Administrative users can choose a separate <em>Administration pages language</em> for the interface text on administration pages. This configuration is only available on the user's profile page if the <em>Account administration pages</em> method is enabled (see below).") . '</dd>'; + $output .= '<dt>' . $this->t('Language detection and selection') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":detection">Detection and selection</a> page provides several methods for deciding which language is used for displaying interface text. When a method detects and selects an interface language, then the following methods in the list are not applied. You can order them by importance, with your preferred method at the top of the list, followed by one or several fall-back methods.', [':detection' => Url::fromRoute('language.negotiation')->toString()]); + $output .= '<ul><li>' . $this->t('<em>URL</em> sets the interface language based on a path prefix or domain (for example specifying <em>de</em> for German would result in URLs like <em>example.com/de/contact</em>). The default language does not require a path prefix, but can have one assigned as well. If the language detection is done by domain name, a domain needs to be specified for each language.') . '</li>'; + $output .= '<li>' . $this->t('<em>Session</em> determines the interface language from a request or session parameter (for example <em>example.com?language=de</em> would set the interface language to German based on the use of <em>de</em> as the <em>language</em> parameter).') . '</li>'; + $output .= '<li>' . $this->t("<em>User</em> follows the language configuration set on the user's profile page.") . '</li>'; + $output .= '<li>' . $this->t('<em>Browser</em> sets the interface language based on the browser\'s language settings. Since browsers use different language codes to refer to the same languages, you can add and edit languages codes to map the browser language codes to the <a href=":language_list">language codes</a> used on your site.', [ ':language_list' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</li>'; - $output .= '<li>' . t('<em>Account administration pages</em> follows the configuration set as <em>Administration pages language</em> on the profile page of an administrative user. This method is similar to the <em>User</em> method, but only sets the interface text language on administration pages, independent of the interface text language on other pages.') . '</li>'; - $output .= '<li>' . t("<em>Selected language</em> allows you to specify the site's default language or a specific language as the fall-back language. This method should be listed last.") . '</li></ul></dd>'; + $output .= '<li>' . $this->t('<em>Account administration pages</em> follows the configuration set as <em>Administration pages language</em> on the profile page of an administrative user. This method is similar to the <em>User</em> method, but only sets the interface text language on administration pages, independent of the interface text language on other pages.') . '</li>'; + $output .= '<li>' . $this->t("<em>Selected language</em> allows you to specify the site's default language or a specific language as the fall-back language. This method should be listed last.") . '</li></ul></dd>'; $output .= '</dl>'; return $output; case 'entity.configurable_language.collection': - $output = '<p>' . t('Reorder the configured languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact <a href=":detection">detection and selection</a>.', [':detection' => Url::fromRoute('language.negotiation')->toString()]) . '</p>'; - $output .= '<p>' . t('The site default language can also be set. It is not recommended to change the default language on a working site. <a href=":language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', [ + $output = '<p>' . $this->t('Reorder the configured languages to set their order in the language switcher block and, when editing content, in the list of selectable languages. This ordering does not impact <a href=":detection">detection and selection</a>.', [':detection' => Url::fromRoute('language.negotiation')->toString()]) . '</p>'; + $output .= '<p>' . $this->t('The site default language can also be set. It is not recommended to change the default language on a working site. <a href=":language-detection">Configure the Selected language</a> setting on the detection and selection page to change the fallback language for language selection.', [ ':language-detection' => Url::fromRoute('language.negotiation')->toString(), ]) . '</p>'; return $output; case 'language.add': - return '<p>' . t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>'; + return '<p>' . $this->t('Add a language to be supported by your site. If your desired language is not available, pick <em>Custom language...</em> at the end and provide a language code and other details manually.') . '</p>'; case 'language.negotiation': - $output = '<p>' . t('Define how to decide which language is used to display page elements (primarily text provided by modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Be aware that some language detection methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the <a href=":admin-change-language">list of languages</a>.', [ + $output = '<p>' . $this->t('Define how to decide which language is used to display page elements (primarily text provided by modules, such as field labels and help text). This decision is made by evaluating a series of detection methods for languages; the first detection method that gets a result will determine which language is used for that type of text. Be aware that some language detection methods are unreliable under certain conditions, such as browser detection when page-caching is enabled and a user is not currently logged in. Define the order of evaluation of language detection methods on this page. The default language can be changed in the <a href=":admin-change-language">list of languages</a>.', [ ':admin-change-language' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</p>'; return $output; case 'language.negotiation_session': - $output = '<p>' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>'; + $output = '<p>' . $this->t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '</p>'; return $output; case 'language.negotiation_browser': - $output = '<p>' . t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to <a href=":configure-languages">site languages</a>.', [ + $output = '<p>' . $this->t('Browsers use different language codes to refer to the same languages. Internally, a best effort is made to determine the correct language based on the code that the browser sends. You can add and edit additional mappings from browser language codes to <a href=":configure-languages">site languages</a>.', [ ':configure-languages' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</p>'; return $output; case 'language.negotiation_selected': - $output = '<p>' . t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (e.g., when using an empty path prefix or using the default domain). <a href=":admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.', [ + $output = '<p>' . $this->t('Changing the selected language here (and leaving this option as the last among the detection and selection options) is the easiest way to change the fallback language for the website, if you need to change how your site works by default (e.g., when using an empty path prefix or using the default domain). <a href=":admin-change-language">Changing the site\'s default language</a> itself might have other undesired side effects.', [ ':admin-change-language' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</p>'; return $output; case 'entity.block.edit_form': if (($block = $route_match->getParameter('block')) && $block->getPluginId() == 'language_block:language_interface') { - return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>'; + return '<p>' . $this->t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>'; } break; case 'block.admin_add': if ($route_match->getParameter('plugin_id') == 'language_block:language_interface') { - return '<p>' . t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>'; + return '<p>' . $this->t('With multiple languages configured, registered users can select their preferred language and authors can assign a specific language to content.') . '</p>'; } break; case 'language.content_settings_page': - return '<p>' . t("Change language settings for <em>content types</em>, <em>taxonomy vocabularies</em>, <em>user profiles</em>, or any other supported element on your site. By default, language settings hide the language selector and the language is the site's default language.") . '</p>'; + return '<p>' . $this->t("Change language settings for <em>content types</em>, <em>taxonomy vocabularies</em>, <em>user profiles</em>, or any other supported element on your site. By default, language settings hide the language selector and the language is the site's default language.") . '</p>'; } } @@ -329,10 +332,10 @@ public function tourTipsAlter(array &$tour_tips, EntityInterface $entity): void if ($tour_tip->get('id') == 'language-overview') { $additional_overview = ''; if (\Drupal::service('module_handler')->moduleExists('locale')) { - $additional_overview = t("This page also provides an overview of how much of the site's interface has been translated for each configured language."); + $additional_overview = $this->t("This page also provides an overview of how much of the site's interface has been translated for each configured language."); } else { - $additional_overview = t("If the Interface Translation module is installed, this page will provide an overview of how much of the site's interface has been translated for each configured language."); + $additional_overview = $this->t("If the Interface Translation module is installed, this page will provide an overview of how much of the site's interface has been translated for each configured language."); } $tour_tip->set('body', $tour_tip->get('body') . '<p>' . $additional_overview . '</p>'); } @@ -346,7 +349,7 @@ public function tourTipsAlter(array &$tour_tips, EntityInterface $entity): void $additional_modules[] = $module_extension_list->getName('content_translation'); } if (!empty($additional_modules)) { - $additional_continue = t('Depending on your site features, additional modules that you might want to install are:') . '<ul>'; + $additional_continue = $this->t('Depending on your site features, additional modules that you might want to install are:') . '<ul>'; foreach ($additional_modules as $additional_module) { $additional_continue .= '<li>' . $additional_module . '</li>'; } diff --git a/core/modules/layout_builder/modules/layout_builder_expose_all_field_blocks/src/Hook/LayoutBuilderExposeAllFieldBlocksHooks.php b/core/modules/layout_builder/modules/layout_builder_expose_all_field_blocks/src/Hook/LayoutBuilderExposeAllFieldBlocksHooks.php index c2d569ba893496c8e3634f26050f55c80509e041..6b213b2dc702037de15e4a141648455c030aa6bc 100644 --- a/core/modules/layout_builder/modules/layout_builder_expose_all_field_blocks/src/Hook/LayoutBuilderExposeAllFieldBlocksHooks.php +++ b/core/modules/layout_builder/modules/layout_builder_expose_all_field_blocks/src/Hook/LayoutBuilderExposeAllFieldBlocksHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for layout_builder_expose_all_field_blocks. */ class LayoutBuilderExposeAllFieldBlocksHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -17,12 +20,12 @@ class LayoutBuilderExposeAllFieldBlocksHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.layout_builder_expose_all_field_blocks': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Layout Builder Expose All Field Blocks module is a Feature Flag module which exposes all fields on all bundles as field blocks for use in Layout Builder.') . '</p>'; - $output .= '<p>' . t('Using this feature can significantly reduce the performance of medium to large sites due to the number of Field Block plugins that will be created. It is recommended to uninstall this module, if possible.') . '</p>'; - $output .= '<p>' . t('While it is recommended to uninstall this module, doing so may remove blocks that are being used in your site.') . '</p>'; - $output .= '<p>' . t("For example, if Layout Builder is enabled on a Node bundle (Content type), and that bundle's display is using field blocks from the User entity (e.g. the Author's name), but Layout Builder is not enabled for the User bundle, then that field block would no longer exist after uninstalling this module.") . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":href">online documentation for the Layout Builder Expose All Field Blocks module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Layout Builder Expose All Field Blocks module is a Feature Flag module which exposes all fields on all bundles as field blocks for use in Layout Builder.') . '</p>'; + $output .= '<p>' . $this->t('Using this feature can significantly reduce the performance of medium to large sites due to the number of Field Block plugins that will be created. It is recommended to uninstall this module, if possible.') . '</p>'; + $output .= '<p>' . $this->t('While it is recommended to uninstall this module, doing so may remove blocks that are being used in your site.') . '</p>'; + $output .= '<p>' . $this->t("For example, if Layout Builder is enabled on a Node bundle (Content type), and that bundle's display is using field blocks from the User entity (e.g. the Author's name), but Layout Builder is not enabled for the User bundle, then that field block would no longer exist after uninstalling this module.") . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":href">online documentation for the Layout Builder Expose All Field Blocks module</a>.', [ ':href' => 'https://www.drupal.org/node/3223395#s-layout-builder-expose-all-field-blocks', ]) . '</p>'; return $output; diff --git a/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php b/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php index 2529c5fbaecd97b0a1fba7e51e94e1a5e4dee67b..7f30060ad3fdfca0283274ce0e5dc42b67f2ba7a 100644 --- a/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php +++ b/core/modules/layout_builder/src/Hook/LayoutBuilderHooks.php @@ -8,6 +8,7 @@ use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Access\AccessResult; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\layout_builder\InlineBlockEntityOperations; use Drupal\layout_builder\Plugin\Block\ExtraFieldBlock; use Drupal\Core\Render\Element; @@ -31,6 +32,8 @@ */ class LayoutBuilderHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -38,39 +41,39 @@ class LayoutBuilderHooks { public function help($route_name, RouteMatchInterface $route_match) { // Add help text to the Layout Builder UI. if ($route_match->getRouteObject()->getOption('_layout_builder')) { - $output = '<p>' . t('This layout builder tool allows you to configure the layout of the main content area.') . '</p>'; + $output = '<p>' . $this->t('This layout builder tool allows you to configure the layout of the main content area.') . '</p>'; if (\Drupal::currentUser()->hasPermission('administer blocks')) { - $output .= '<p>' . t('To manage other areas of the page, use the <a href="@block-ui">block administration page</a>.', ['@block-ui' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; + $output .= '<p>' . $this->t('To manage other areas of the page, use the <a href="@block-ui">block administration page</a>.', ['@block-ui' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; } else { - $output .= '<p>' . t('To manage other areas of the page, use the block administration page.') . '</p>'; + $output .= '<p>' . $this->t('To manage other areas of the page, use the block administration page.') . '</p>'; } - $output .= '<p>' . t('Forms and links inside the content of the layout builder tool have been disabled.') . '</p>'; + $output .= '<p>' . $this->t('Forms and links inside the content of the layout builder tool have been disabled.') . '</p>'; return $output; } switch ($route_name) { case 'help.page.layout_builder': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('Layout Builder allows you to use layouts to customize how content, content blocks, and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a> are displayed.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('Layout Builder allows you to use layouts to customize how content, content blocks, and other <a href=":field_help" title="Field module help, with background on content entities">content entities</a> are displayed.', [ ':field_help' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ]) . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":layout-builder-documentation">online documentation for the Layout Builder module</a>.', [ + $output .= '<p>' . $this->t('For more information, see the <a href=":layout-builder-documentation">online documentation for the Layout Builder module</a>.', [ ':layout-builder-documentation' => 'https://www.drupal.org/docs/8/core/modules/layout-builder', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Default layouts') . '</dt>'; - $output .= '<dd>' . t('Layout Builder can be selectively enabled on the "Manage Display" page in the <a href=":field_ui">Field UI</a>. This allows you to control the output of each type of display individually. For example, a "Basic page" might have view modes such as Full and Teaser, with each view mode having different layouts selected.', [ + $output .= '<dt>' . $this->t('Default layouts') . '</dt>'; + $output .= '<dd>' . $this->t('Layout Builder can be selectively enabled on the "Manage Display" page in the <a href=":field_ui">Field UI</a>. This allows you to control the output of each type of display individually. For example, a "Basic page" might have view modes such as Full and Teaser, with each view mode having different layouts selected.', [ ':field_ui' => Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Overridden layouts') . '</dt>'; - $output .= '<dd>' . t('If enabled, each individual content item can have a custom layout. Once the layout for an individual content item is overridden, changes to the Default layout will no longer affect it. Overridden layouts may be reverted to return to matching and being synchronized to their Default layout.') . '</dd>'; - $output .= '<dt>' . t('User permissions') . '</dt>'; - $output .= '<dd>' . t('The Layout Builder module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>. For more information, see the <a href=":layout-builder-permissions">Configuring Layout Builder permissions</a> online documentation.', [ + $output .= '<dt>' . $this->t('Overridden layouts') . '</dt>'; + $output .= '<dd>' . $this->t('If enabled, each individual content item can have a custom layout. Once the layout for an individual content item is overridden, changes to the Default layout will no longer affect it. Overridden layouts may be reverted to return to matching and being synchronized to their Default layout.') . '</dd>'; + $output .= '<dt>' . $this->t('User permissions') . '</dt>'; + $output .= '<dd>' . $this->t('The Layout Builder module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>. For more information, see the <a href=":layout-builder-permissions">Configuring Layout Builder permissions</a> online documentation.', [ ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'layout_builder', ])->toString(), diff --git a/core/modules/layout_discovery/src/Hook/LayoutDiscoveryHooks.php b/core/modules/layout_discovery/src/Hook/LayoutDiscoveryHooks.php index a9efe3b10d4b528bd3ea0ec73c2e61a81d75cc8c..bc127e6257f08b8da34e35451559727396e7a1cb 100644 --- a/core/modules/layout_discovery/src/Hook/LayoutDiscoveryHooks.php +++ b/core/modules/layout_discovery/src/Hook/LayoutDiscoveryHooks.php @@ -3,12 +3,15 @@ namespace Drupal\layout_discovery\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for layout_discovery. */ class LayoutDiscoveryHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -16,9 +19,9 @@ class LayoutDiscoveryHooks { public function help($route_name) { switch ($route_name) { case 'help.page.layout_discovery': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('Layout Discovery allows modules or themes to register layouts, and for other modules to list the available layouts and render them.') . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":layout-discovery-documentation">online documentation for the Layout Discovery module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('Layout Discovery allows modules or themes to register layouts, and for other modules to list the available layouts and render them.') . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":layout-discovery-documentation">online documentation for the Layout Discovery module</a>.', [ ':layout-discovery-documentation' => 'https://www.drupal.org/docs/8/api/layout-api', ]) . '</p>'; return $output; diff --git a/core/modules/link/src/Hook/LinkHooks.php b/core/modules/link/src/Hook/LinkHooks.php index 6221190bcf76db65afd61b25ac879df545aefc27..8bfe2cb7ab1135b72743fb9ef809793a287a7729 100644 --- a/core/modules/link/src/Hook/LinkHooks.php +++ b/core/modules/link/src/Hook/LinkHooks.php @@ -3,6 +3,7 @@ namespace Drupal\link\Hook; use Drupal\Core\Field\FieldTypeCategoryManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class LinkHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -20,8 +23,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.link': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Link module allows you to create fields that contain internal or external URLs and optional link text. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":link_documentation">online documentation for the Link module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Link module allows you to create fields that contain internal or external URLs and optional link text. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":link_documentation">online documentation for the Link module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -30,24 +33,24 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':link_documentation' => 'https://www.drupal.org/documentation/modules/link', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying link fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the link field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying link fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the link field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Setting the allowed link type') . '</dt>'; - $output .= '<dd>' . t('In the field settings you can define the allowed link type to be <em>internal links only</em>, <em>external links only</em>, or <em>both internal and external links</em>. <em>Internal links only</em> and <em>both internal and external links</em> options enable an autocomplete widget for internal links, so a user does not have to copy or remember a URL.') . '</dd>'; - $output .= '<dt>' . t('Adding link text') . '</dt>'; - $output .= '<dd>' . t('In the field settings you can define additional link text to be <em>optional</em> or <em>required</em> in any link field.') . '</dd>'; - $output .= '<dt>' . t('Displaying link text') . '</dt>'; - $output .= '<dd>' . t('If link text has been submitted for a URL, then by default this link text is displayed as a link to the URL. If you want to display both the link text <em>and</em> the URL, choose the appropriate link format from the drop-down menu in the <em>Manage display</em> page. If you only want to display the URL even if link text has been submitted, choose <em>Link</em> as the format, and then change its <em>Format settings</em> to display <em>URL only</em>.') . '</dd>'; - $output .= '<dt>' . t('Adding attributes to links') . '</dt>'; - $output .= '<dd>' . t('You can add attributes to links, by changing the <em>Format settings</em> in the <em>Manage display</em> page. Adding <em>rel="nofollow"</em> notifies search engines that links should not be followed.') . '</dd>'; - $output .= '<dt>' . t('Validating URLs') . '</dt>'; - $output .= '<dd>' . t('All links are validated after a link field is filled in. They can include anchors or query strings.') . '</dd>'; + $output .= '<dt>' . $this->t('Setting the allowed link type') . '</dt>'; + $output .= '<dd>' . $this->t('In the field settings you can define the allowed link type to be <em>internal links only</em>, <em>external links only</em>, or <em>both internal and external links</em>. <em>Internal links only</em> and <em>both internal and external links</em> options enable an autocomplete widget for internal links, so a user does not have to copy or remember a URL.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding link text') . '</dt>'; + $output .= '<dd>' . $this->t('In the field settings you can define additional link text to be <em>optional</em> or <em>required</em> in any link field.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying link text') . '</dt>'; + $output .= '<dd>' . $this->t('If link text has been submitted for a URL, then by default this link text is displayed as a link to the URL. If you want to display both the link text <em>and</em> the URL, choose the appropriate link format from the drop-down menu in the <em>Manage display</em> page. If you only want to display the URL even if link text has been submitted, choose <em>Link</em> as the format, and then change its <em>Format settings</em> to display <em>URL only</em>.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding attributes to links') . '</dt>'; + $output .= '<dd>' . $this->t('You can add attributes to links, by changing the <em>Format settings</em> in the <em>Manage display</em> page. Adding <em>rel="nofollow"</em> notifies search engines that links should not be followed.') . '</dd>'; + $output .= '<dt>' . $this->t('Validating URLs') . '</dt>'; + $output .= '<dd>' . $this->t('All links are validated after a link field is filled in. They can include anchors or query strings.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/locale/src/Hook/LocaleHooks.php b/core/modules/locale/src/Hook/LocaleHooks.php index 545326f4e5e21a8931bf71516bb4a509180c8165..cb8268439f467d37a44cdf47844462c6bf91b702 100644 --- a/core/modules/locale/src/Hook/LocaleHooks.php +++ b/core/modules/locale/src/Hook/LocaleHooks.php @@ -6,6 +6,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Asset\AttachedAssetsInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\ConfigurableLanguageInterface; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -16,6 +17,8 @@ */ class LocaleHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -24,36 +27,36 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.locale': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Interface Translation module allows you to translate interface text (<em>strings</em>) into different languages, and to switch between them for the display of interface text. It uses the functionality provided by the <a href=":language">Language module</a>. For more information, see the <a href=":doc-url">online documentation for the Interface Translation module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Interface Translation module allows you to translate interface text (<em>strings</em>) into different languages, and to switch between them for the display of interface text. It uses the functionality provided by the <a href=":language">Language module</a>. For more information, see the <a href=":doc-url">online documentation for the Interface Translation module</a>.', [ ':doc-url' => 'https://www.drupal.org/documentation/modules/locale/', ':language' => Url::fromRoute('help.page', [ 'name' => 'language', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Importing translation files') . '</dt>'; - $output .= '<dd>' . t('Translation files with translated interface text are imported automatically when languages are added on the <a href=":languages">Languages</a> page, or when modules or themes are installed. On the <a href=":locale-settings">Interface translation settings</a> page, the <em>Translation source</em> can be restricted to local files only, or to include the <a href=":server">Drupal translation server</a>. Although modules and themes may not be fully translated in all languages, new translations become available frequently. You can specify whether and how often to check for translation file updates and whether to overwrite existing translations on the <a href=":locale-settings">Interface translation settings</a> page. You can also manually import a translation file on the <a href=":import">Interface translation import</a> page.', [ + $output .= '<dt>' . $this->t('Importing translation files') . '</dt>'; + $output .= '<dd>' . $this->t('Translation files with translated interface text are imported automatically when languages are added on the <a href=":languages">Languages</a> page, or when modules or themes are installed. On the <a href=":locale-settings">Interface translation settings</a> page, the <em>Translation source</em> can be restricted to local files only, or to include the <a href=":server">Drupal translation server</a>. Although modules and themes may not be fully translated in all languages, new translations become available frequently. You can specify whether and how often to check for translation file updates and whether to overwrite existing translations on the <a href=":locale-settings">Interface translation settings</a> page. You can also manually import a translation file on the <a href=":import">Interface translation import</a> page.', [ ':import' => Url::fromRoute('locale.translate_import')->toString(), ':locale-settings' => Url::fromRoute('locale.settings')->toString(), ':languages' => Url::fromRoute('entity.configurable_language.collection')->toString(), ':server' => 'https://localize.drupal.org', ]) . '</dd>'; - $output .= '<dt>' . t('Checking the translation status') . '</dt>'; - $output .= '<dd>' . t('You can check how much of the interface on your site is translated into which language on the <a href=":languages">Languages</a> page. On the <a href=":translation-updates">Available translation updates</a> page, you can check whether interface translation updates are available on the <a href=":server">Drupal translation server</a>.', [ + $output .= '<dt>' . $this->t('Checking the translation status') . '</dt>'; + $output .= '<dd>' . $this->t('You can check how much of the interface on your site is translated into which language on the <a href=":languages">Languages</a> page. On the <a href=":translation-updates">Available translation updates</a> page, you can check whether interface translation updates are available on the <a href=":server">Drupal translation server</a>.', [ ':languages' => Url::fromRoute('entity.configurable_language.collection')->toString(), ':translation-updates' => Url::fromRoute('locale.translate_status')->toString(), ':server' => 'https://localize.drupal.org', ]) . '<dd>'; - $output .= '<dt>' . t('Translating individual strings') . '</dt>'; - $output .= '<dd>' . t('You can translate individual strings directly on the <a href=":translate">User interface translation</a> page, or download the currently-used translation file for a specific language on the <a href=":export">Interface translation export</a> page. Once you have edited the translation file, you can then import it again on the <a href=":import">Interface translation import</a> page.', [ + $output .= '<dt>' . $this->t('Translating individual strings') . '</dt>'; + $output .= '<dd>' . $this->t('You can translate individual strings directly on the <a href=":translate">User interface translation</a> page, or download the currently-used translation file for a specific language on the <a href=":export">Interface translation export</a> page. Once you have edited the translation file, you can then import it again on the <a href=":import">Interface translation import</a> page.', [ ':translate' => Url::fromRoute('locale.translate_page')->toString(), ':export' => Url::fromRoute('locale.translate_export')->toString(), ':import' => Url::fromRoute('locale.translate_import')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Overriding default English strings') . '</dt>'; - $output .= '<dd>' . t('If translation is enabled for English, you can <em>override</em> the default English interface text strings in your site with other English text strings on the <a href=":translate">User interface translation</a> page. Translation is off by default for English, but you can turn it on by visiting the <em>Edit language</em> page for <em>English</em> from the <a href=":languages">Languages</a> page.', [ + $output .= '<dt>' . $this->t('Overriding default English strings') . '</dt>'; + $output .= '<dd>' . $this->t('If translation is enabled for English, you can <em>override</em> the default English interface text strings in your site with other English text strings on the <a href=":translate">User interface translation</a> page. Translation is off by default for English, but you can turn it on by visiting the <em>Edit language</em> page for <em>English</em> from the <a href=":languages">Languages</a> page.', [ ':translate' => Url::fromRoute('locale.translate_page')->toString(), ':languages' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</dd>'; @@ -61,28 +64,28 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.configurable_language.collection': - return '<p>' . t('Interface translations are automatically imported when a language is added, or when new modules or themes are installed. The report <a href=":update">Available translation updates</a> shows the status. Interface text can be customized in the <a href=":translate">user interface translation</a> page.', [ + return '<p>' . $this->t('Interface translations are automatically imported when a language is added, or when new modules or themes are installed. The report <a href=":update">Available translation updates</a> shows the status. Interface text can be customized in the <a href=":translate">user interface translation</a> page.', [ ':update' => Url::fromRoute('locale.translate_status')->toString(), ':translate' => Url::fromRoute('locale.translate_page')->toString(), ]) . '</p>'; case 'locale.translate_page': - $output = '<p>' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: Because translation tasks involve many strings, it may be more convenient to <a title="User interface translation export" href=":export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings in a specific language.', [':export' => Url::fromRoute('locale.translate_export')->toString()]) . '</p>'; + $output = '<p>' . $this->t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: Because translation tasks involve many strings, it may be more convenient to <a title="User interface translation export" href=":export">export</a> strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings in a specific language.', [':export' => Url::fromRoute('locale.translate_export')->toString()]) . '</p>'; return $output; case 'locale.translate_import': - $output = '<p>' . t('Translation files are automatically downloaded and imported when <a title="Languages" href=":language">languages</a> are added, or when modules or themes are installed.', [ + $output = '<p>' . $this->t('Translation files are automatically downloaded and imported when <a title="Languages" href=":language">languages</a> are added, or when modules or themes are installed.', [ ':language' => Url::fromRoute('entity.configurable_language.collection')->toString(), ]) . '</p>'; - $output .= '<p>' . t('This page allows translators to manually import translated strings contained in a Gettext Portable Object (.po) file. Manual import may be used for customized translations or for the translation of custom modules and themes. To customize translations you can download a translation file from the <a href=":url">Drupal translation server</a> or <a title="User interface translation export" href=":export">export</a> translations from the site, customize the translations using a Gettext translation editor, and import the result using this page.', [ + $output .= '<p>' . $this->t('This page allows translators to manually import translated strings contained in a Gettext Portable Object (.po) file. Manual import may be used for customized translations or for the translation of custom modules and themes. To customize translations you can download a translation file from the <a href=":url">Drupal translation server</a> or <a title="User interface translation export" href=":export">export</a> translations from the site, customize the translations using a Gettext translation editor, and import the result using this page.', [ ':url' => 'https://localize.drupal.org', ':export' => Url::fromRoute('locale.translate_export')->toString(), ]) . '</p>'; - $output .= '<p>' . t('Note that importing large .po files may take several minutes.') . '</p>'; + $output .= '<p>' . $this->t('Note that importing large .po files may take several minutes.') . '</p>'; return $output; case 'locale.translate_export': - return '<p>' . t('This page exports the translated strings used by your site. An export file may be in Gettext Portable Object (<em>.po</em>) form, which includes both the original string and the translation (used to share translations with others), or in Gettext Portable Object Template (<em>.pot</em>) form, which includes the original strings only (used to create new translations with a Gettext translation editor).') . '</p>'; + return '<p>' . $this->t('This page exports the translated strings used by your site. An export file may be in Gettext Portable Object (<em>.po</em>) form, which includes both the original string and the translation (used to share translations with others), or in Gettext Portable Object Template (<em>.pot</em>) form, which includes the original strings only (used to create new translations with a Gettext translation editor).') . '</p>'; } } @@ -281,18 +284,18 @@ public function formLanguageAdminOverviewFormAlter(&$form, FormStateInterface $f } } } - array_splice($form['languages']['#header'], -1, 0, ['translation-interface' => t('Interface translation')]); + array_splice($form['languages']['#header'], -1, 0, ['translation-interface' => $this->t('Interface translation')]); foreach ($languages as $langcode => $language) { $stats[$langcode] += ['translated' => 0, 'ratio' => 0]; if (!$language->isLocked() && locale_is_translatable($langcode)) { - $form['languages'][$langcode]['locale_statistics'] = Link::fromTextAndUrl(t('@translated/@total (@ratio%)', [ + $form['languages'][$langcode]['locale_statistics'] = Link::fromTextAndUrl($this->t('@translated/@total (@ratio%)', [ '@translated' => $stats[$langcode]['translated'], '@total' => $total_strings, '@ratio' => $stats[$langcode]['ratio'], ]), Url::fromRoute('locale.translate_page', [], ['query' => ['langcode' => $langcode]]))->toRenderable(); } else { - $form['languages'][$langcode]['locale_statistics'] = ['#markup' => t('not applicable')]; + $form['languages'][$langcode]['locale_statistics'] = ['#markup' => $this->t('not applicable')]; } // #type = link doesn't work with #weight on table. // reset and set it back after locale_statistics to get it at the right @@ -321,7 +324,7 @@ public function formLanguageAdminEditFormAlter(&$form, FormStateInterface $form_ $language = $form_state->getFormObject()->getEntity(); if ($language->id() == 'en') { $form['locale_translate_english'] = [ - '#title' => t('Enable interface translation to English'), + '#title' => $this->t('Enable interface translation to English'), '#type' => 'checkbox', '#default_value' => \Drupal::configFactory()->getEditable('locale.settings')->get('translate_english'), ]; @@ -338,10 +341,10 @@ public function formLanguageAdminEditFormAlter(&$form, FormStateInterface $form_ public function formSystemFileSystemSettingsAlter(&$form, FormStateInterface $form_state) : void { $form['translation_path'] = [ '#type' => 'textfield', - '#title' => t('Interface translations directory'), + '#title' => $this->t('Interface translations directory'), '#default_value' => \Drupal::configFactory()->getEditable('locale.settings')->get('translation.path'), '#maxlength' => 255, - '#description' => t('A local file system path where interface translation files will be stored.'), + '#description' => $this->t('A local file system path where interface translation files will be stored.'), '#required' => TRUE, '#after_build' => [ 'system_check_directory', diff --git a/core/modules/media/src/Hook/MediaHooks.php b/core/modules/media/src/Hook/MediaHooks.php index 25e9383e81c570e8bb9445b57cf94a271daa278d..1e45715a88215e32208aaa1d716416f1a39f4d3b 100644 --- a/core/modules/media/src/Hook/MediaHooks.php +++ b/core/modules/media/src/Hook/MediaHooks.php @@ -3,6 +3,7 @@ namespace Drupal\media\Hook; use Drupal\Core\Access\AccessResultInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\ViewExecutable; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Field\FieldTypeCategoryManagerInterface; @@ -19,6 +20,8 @@ */ class MediaHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -26,46 +29,46 @@ class MediaHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.media': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Media module manages the creation, editing, deletion, settings, and display of media. Items are typically images, documents, slideshows, YouTube videos, tweets, Instagram photos, etc. You can reference media items from any other content on your site. For more information, see the <a href=":media">online documentation for the Media module</a>.', [':media' => 'https://www.drupal.org/docs/8/core/modules/media']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Media module manages the creation, editing, deletion, settings, and display of media. Items are typically images, documents, slideshows, YouTube videos, tweets, Instagram photos, etc. You can reference media items from any other content on your site. For more information, see the <a href=":media">online documentation for the Media module</a>.', [':media' => 'https://www.drupal.org/docs/8/core/modules/media']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating media items') . '</dt>'; - $output .= '<dd>' . t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the <a href=":media-type">media type</a>. It also manages the <em>publishing options</em>, which define whether or not the item is published. Default settings can be configured for each type of media on your site.', [ + $output .= '<dt>' . $this->t('Creating media items') . '</dt>'; + $output .= '<dd>' . $this->t('When a new media item is created, the Media module records basic information about it, including the author, date of creation, and the <a href=":media-type">media type</a>. It also manages the <em>publishing options</em>, which define whether or not the item is published. Default settings can be configured for each type of media on your site.', [ ':media-type' => Url::fromRoute('entity.media_type.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Listing media items') . '</dt>'; - $output .= '<dd>' . t('Media items are listed at the <a href=":media-collection">media administration page</a>.', [ + $output .= '<dt>' . $this->t('Listing media items') . '</dt>'; + $output .= '<dd>' . $this->t('Media items are listed at the <a href=":media-collection">media administration page</a>.', [ ':media-collection' => Url::fromRoute('entity.media.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Creating custom media types') . '</dt>'; - $output .= '<dd>' . t('The Media module gives users with the <em>Administer media types</em> permission the ability to <a href=":media-new">create new media types</a> in addition to the default ones already configured. Each media type has an associated media source (such as the image source) which support thumbnail generation and metadata extraction. Fields managed by the <a href=":field">Field module</a> may be added for storing that metadata, such as width and height, as well as any other associated values.', [ + $output .= '<dt>' . $this->t('Creating custom media types') . '</dt>'; + $output .= '<dd>' . $this->t('The Media module gives users with the <em>Administer media types</em> permission the ability to <a href=":media-new">create new media types</a> in addition to the default ones already configured. Each media type has an associated media source (such as the image source) which support thumbnail generation and metadata extraction. Fields managed by the <a href=":field">Field module</a> may be added for storing that metadata, such as width and height, as well as any other associated values.', [ ':media-new' => Url::fromRoute('entity.media_type.add_form')->toString(), ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Creating revisions') . '</dt>'; - $output .= '<dd>' . t('The Media module also enables you to create multiple versions of any media item, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>'; - $output .= '<dt>' . t('User permissions') . '</dt>'; - $output .= '<dd>' . t('The Media module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>.', [ + $output .= '<dt>' . $this->t('Creating revisions') . '</dt>'; + $output .= '<dd>' . $this->t('The Media module also enables you to create multiple versions of any media item, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>'; + $output .= '<dt>' . $this->t('User permissions') . '</dt>'; + $output .= '<dd>' . $this->t('The Media module makes a number of permissions available, which can be set by role on the <a href=":permissions">permissions page</a>.', [ ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'media', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Adding media to other content') . '</dt>'; - $output .= '<dd>' . t('Users with permission to administer content types can add media support by adding a media reference field to the content type on the content type administration page. (The same is true of block types, taxonomy terms, user profiles, and other content that supports fields.) A media reference field can refer to any configured media type. It is possible to allow multiple media types in the same field.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding media to other content') . '</dt>'; + $output .= '<dd>' . $this->t('Users with permission to administer content types can add media support by adding a media reference field to the content type on the content type administration page. (The same is true of block types, taxonomy terms, user profiles, and other content that supports fields.) A media reference field can refer to any configured media type. It is possible to allow multiple media types in the same field.') . '</dd>'; $output .= '</dl>'; - $output .= '<h2>' . t('Differences between Media, File, and Image reference fields') . '</h2>'; - $output .= '<p>' . t('<em>Media</em> reference fields offer several advantages over basic <em>File</em> and <em>Image</em> references:') . '</p>'; + $output .= '<h2>' . $this->t('Differences between Media, File, and Image reference fields') . '</h2>'; + $output .= '<p>' . $this->t('<em>Media</em> reference fields offer several advantages over basic <em>File</em> and <em>Image</em> references:') . '</p>'; $output .= '<ul>'; - $output .= '<li>' . t('Media reference fields can reference multiple media types in the same field.') . '</li>'; - $output .= '<li>' . t('Fields can also be added to media types themselves, which means that custom metadata like descriptions and taxonomy tags can be added for the referenced media. (Basic file and image fields do not support this.)') . '</li>'; - $output .= '<li>' . t('Media types for audio and video files are provided by default, so there is no need for additional configuration to upload these media.') . '</li>'; - $output .= '<li>' . t('Contributed or custom projects can provide additional media sources (such as third-party websites, Twitter, etc.).') . '</li>'; - $output .= '<li>' . t('Existing media items can be reused on any other content items with a media reference field.') . '</li>'; + $output .= '<li>' . $this->t('Media reference fields can reference multiple media types in the same field.') . '</li>'; + $output .= '<li>' . $this->t('Fields can also be added to media types themselves, which means that custom metadata like descriptions and taxonomy tags can be added for the referenced media. (Basic file and image fields do not support this.)') . '</li>'; + $output .= '<li>' . $this->t('Media types for audio and video files are provided by default, so there is no need for additional configuration to upload these media.') . '</li>'; + $output .= '<li>' . $this->t('Contributed or custom projects can provide additional media sources (such as third-party websites, Twitter, etc.).') . '</li>'; + $output .= '<li>' . $this->t('Existing media items can be reused on any other content items with a media reference field.') . '</li>'; $output .= '</ul>'; - $output .= '<p>' . t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before installing the Media module.') . '</p>'; + $output .= '<p>' . $this->t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before installing the Media module.') . '</p>'; return $output; } } @@ -127,7 +130,7 @@ public function fieldUiPreconfiguredOptionsAlter(array &$options, $field_type): // Set the default formatter for media in entity reference fields to be the // "Rendered entity" formatter. if (!empty($options['media'])) { - $options['media']['description'] = t('Field to reference media. Allows uploading and selecting from uploaded media.'); + $options['media']['description'] = $this->t('Field to reference media. Allows uploading and selecting from uploaded media.'); $options['media']['weight'] = -25; $options['media']['category'] = FieldTypeCategoryManagerInterface::FALLBACK_CATEGORY; $options['media']['entity_view_display']['type'] = 'entity_reference_entity_view'; @@ -141,9 +144,9 @@ public function fieldUiPreconfiguredOptionsAlter(array &$options, $field_type): public function formFieldUiFieldStorageAddFormAlter(&$form, FormStateInterface $form_state, $form_id) : void { // Provide some help text to aid users decide whether they need a Media, // File, or Image reference field. - $description_text = t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before installing the Media module.'); + $description_text = $this->t('Use <em>Media</em> reference fields for most files, images, audio, videos, and remote media. Use <em>File</em> or <em>Image</em> reference fields when creating your own media types, or for legacy files and images created before installing the Media module.'); if (\Drupal::moduleHandler()->moduleExists('help')) { - $description_text .= ' ' . t('For more information, see the <a href="@help_url">Media help page</a>.', [ + $description_text .= ' ' . $this->t('For more information, see the <a href="@help_url">Media help page</a>.', [ '@help_url' => Url::fromRoute('help.page', [ 'name' => 'media', ])->toString(), @@ -188,7 +191,7 @@ public function fieldWidgetCompleteFormAlter(array &$field_widget_complete_form, $allowed_bundles = !empty($settings['target_bundles']) ? $settings['target_bundles'] : []; $add_url = _media_get_add_url($allowed_bundles); if ($add_url) { - $elements['#media_help']['#media_add_help'] = t('Create your media on the <a href=":add_page" target="_blank">media add page</a> (opens a new window), then add it by name to the field below.', [':add_page' => $add_url]); + $elements['#media_help']['#media_add_help'] = $this->t('Create your media on the <a href=":add_page" target="_blank">media add page</a> (opens a new window), then add it by name to the field below.', [':add_page' => $add_url]); } $elements['#theme'] = 'media_reference_help'; // @todo template_preprocess_field_multiple_value_form() assumes this key @@ -204,7 +207,7 @@ public function fieldWidgetCompleteFormAlter(array &$field_widget_complete_form, $elements['#media_help']['#original_label'] = $elements['#title'] ?? $context['items']->getFieldDefinition()->getLabel(); // Customize the label for the field widget. // @todo Research a better approach https://www.drupal.org/node/2943024. - $use_existing_label = t('Use existing media'); + $use_existing_label = $this->t('Use existing media'); if (!empty($elements[0]['target_id']['#title'])) { $elements[0]['target_id']['#title'] = $use_existing_label; } @@ -218,16 +221,16 @@ public function fieldWidgetCompleteFormAlter(array &$field_widget_complete_form, // is presented with options, they don't need to type anything or know what // types of media are allowed. if ($is_autocomplete) { - $elements['#media_help']['#media_list_help'] = t('Type part of the media name.'); + $elements['#media_help']['#media_list_help'] = $this->t('Type part of the media name.'); $overview_url = Url::fromRoute('entity.media.collection'); if ($overview_url->access()) { - $elements['#media_help']['#media_list_link'] = t('See the <a href=":list_url" target="_blank">media list</a> (opens a new window) to help locate media.', [':list_url' => $overview_url->toString()]); + $elements['#media_help']['#media_list_link'] = $this->t('See the <a href=":list_url" target="_blank">media list</a> (opens a new window) to help locate media.', [':list_url' => $overview_url->toString()]); } $all_bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('media'); $bundle_labels = array_map(function ($bundle) use ($all_bundles) { return $all_bundles[$bundle]['label']; }, $allowed_bundles); - $elements['#media_help']['#allowed_types_help'] = t('Allowed media types: %types', ['%types' => implode(", ", $bundle_labels)]); + $elements['#media_help']['#allowed_types_help'] = $this->t('Allowed media types: %types', ['%types' => implode(", ", $bundle_labels)]); } } diff --git a/core/modules/media_library/src/Hook/MediaLibraryHooks.php b/core/modules/media_library/src/Hook/MediaLibraryHooks.php index 248cdcc30a4e8d0b2afe17a2b1fda5d15fbb11c8..0d0435006518f63a33fe403b6bd5a09d84489327 100644 --- a/core/modules/media_library/src/Hook/MediaLibraryHooks.php +++ b/core/modules/media_library/src/Hook/MediaLibraryHooks.php @@ -7,6 +7,7 @@ use Drupal\Core\Session\AccountInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\media\MediaTypeForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\UrlHelper; @@ -25,6 +26,8 @@ */ class MediaLibraryHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -32,42 +35,42 @@ class MediaLibraryHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.media_library': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Media Library module provides a rich, visual interface for managing media, and allows media to be reused in entity reference fields or embedded into text content. It overrides the <a href=":media-collection">media administration page</a>, allowing users to toggle between the existing table-style interface and a new grid-style interface for browsing and performing administrative operations on media.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Media Library module provides a rich, visual interface for managing media, and allows media to be reused in entity reference fields or embedded into text content. It overrides the <a href=":media-collection">media administration page</a>, allowing users to toggle between the existing table-style interface and a new grid-style interface for browsing and performing administrative operations on media.', [ ':media-collection' => Url::fromRoute('entity.media.collection')->toString(), ]) . '</p>'; - $output .= '<p>' . t('To learn more about media management, begin by reviewing the <a href=":media-help">documentation for the Media module</a>. For more information about the media library and related functionality, see the <a href=":media-library-handbook">online documentation for the Media Library module</a>.', [ + $output .= '<p>' . $this->t('To learn more about media management, begin by reviewing the <a href=":media-help">documentation for the Media module</a>. For more information about the media library and related functionality, see the <a href=":media-library-handbook">online documentation for the Media Library module</a>.', [ ':media-help' => Url::fromRoute('help.page', [ 'name' => 'media', ])->toString(), ':media-library-handbook' => 'https://www.drupal.org/docs/8/core/modules/media-library-module', ]) . '</p>'; - $output .= '<h2>' . t('Selection dialog') . '</h2>'; - $output .= '<p>' . t('When selecting media for an entity reference field or a text editor, Media Library opens a modal dialog to help users easily find and select media. The modal dialog can toggle between a grid-style and table-style interface, and new media items can be uploaded directly into it.') . '</p>'; - $output .= '<p>' . t('Within the dialog, media items are divided up by type. If more than one media type can be selected by the user, the available types will be displayed as a set of vertical tabs. To users who have appropriate permissions, each media type may also present a short form allowing you to upload or create new media items of that type.') . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Selection dialog') . '</h2>'; + $output .= '<p>' . $this->t('When selecting media for an entity reference field or a text editor, Media Library opens a modal dialog to help users easily find and select media. The modal dialog can toggle between a grid-style and table-style interface, and new media items can be uploaded directly into it.') . '</p>'; + $output .= '<p>' . $this->t('Within the dialog, media items are divided up by type. If more than one media type can be selected by the user, the available types will be displayed as a set of vertical tabs. To users who have appropriate permissions, each media type may also present a short form allowing you to upload or create new media items of that type.') . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Grid-style vs. table-style interface') . '</dt>'; - $output .= '<dd>' . t('The Media Library module provides a new grid-style interface for the media administration page that displays media as thumbnails, with minimal textual information, allowing users to visually browse media in their site. The existing table-style interface is better suited to displaying additional information about media items, in addition to being more accessible to users with assistive technology.') . '</dd>'; - $output .= '<dt>' . t('Reusing media in entity reference fields') . '</dt>'; - $output .= '<dd>' . t('Any entity reference field that references media can use the media library. To enable, configure the form display for the field to use the "Media library" widget.') . '</dd>'; - $output .= '<dt>' . t('Embedding media in text content') . '</dt>'; - $output .= '<dd>' . t('To use the media library within CKEditor, you must add the "Insert from Media Library" button to the CKEditor toolbar, and enable the "Embed media" filter in the text format associated with the text editor.') . '</dd>'; + $output .= '<dt>' . $this->t('Grid-style vs. table-style interface') . '</dt>'; + $output .= '<dd>' . $this->t('The Media Library module provides a new grid-style interface for the media administration page that displays media as thumbnails, with minimal textual information, allowing users to visually browse media in their site. The existing table-style interface is better suited to displaying additional information about media items, in addition to being more accessible to users with assistive technology.') . '</dd>'; + $output .= '<dt>' . $this->t('Reusing media in entity reference fields') . '</dt>'; + $output .= '<dd>' . $this->t('Any entity reference field that references media can use the media library. To enable, configure the form display for the field to use the "Media library" widget.') . '</dd>'; + $output .= '<dt>' . $this->t('Embedding media in text content') . '</dt>'; + $output .= '<dd>' . $this->t('To use the media library within CKEditor, you must add the "Insert from Media Library" button to the CKEditor toolbar, and enable the "Embed media" filter in the text format associated with the text editor.') . '</dd>'; $output .= '</dl>'; - $output .= '<h2>' . t('Customize') . '</h2>'; + $output .= '<h2>' . $this->t('Customize') . '</h2>'; $output .= '<ul>'; $output .= '<li>'; if (\Drupal::moduleHandler()->moduleExists('views_ui') && \Drupal::currentUser()->hasPermission('administer views')) { - $output .= t('Both the table-style and grid-style interfaces are regular views and can be customized via the <a href=":views-ui">Views UI</a>, including sorting and filtering. This is the case for both the administration page and the modal dialog.', [':views_ui' => Url::fromRoute('entity.view.collection')->toString()]); + $output .= $this->t('Both the table-style and grid-style interfaces are regular views and can be customized via the <a href=":views-ui">Views UI</a>, including sorting and filtering. This is the case for both the administration page and the modal dialog.', [':views_ui' => Url::fromRoute('entity.view.collection')->toString()]); } else { - $output .= t('Both the table-style and grid-style interfaces are regular views and can be customized via the Views UI, including sorting and filtering. This is the case for both the administration page and the modal dialog.'); + $output .= $this->t('Both the table-style and grid-style interfaces are regular views and can be customized via the Views UI, including sorting and filtering. This is the case for both the administration page and the modal dialog.'); } $output .= '</li>'; - $output .= '<li>' . t('In the grid-style interface, the fields that are displayed (including which image style is used for images) can be customized by configuring the "Media library" view mode for each of your <a href=":media-types">media types</a>. The thumbnail images in the grid-style interface can be customized by configuring the "Media Library thumbnail (220×220)" image style.', [ + $output .= '<li>' . $this->t('In the grid-style interface, the fields that are displayed (including which image style is used for images) can be customized by configuring the "Media library" view mode for each of your <a href=":media-types">media types</a>. The thumbnail images in the grid-style interface can be customized by configuring the "Media Library thumbnail (220×220)" image style.', [ ':media-types' => Url::fromRoute('entity.media_type.collection')->toString(), ]) . '</li>'; - $output .= '<li>' . t('When adding new media items within the modal dialog, the fields that are displayed can be customized by configuring the "Media library" form mode for each of your <a href=":media-types">media types</a>.', [ + $output .= '<li>' . $this->t('When adding new media items within the modal dialog, the fields that are displayed can be customized by configuring the "Media library" form mode for each of your <a href=":media-types">media types</a>.', [ ':media-types' => Url::fromRoute('entity.media_type.collection')->toString(), ]) . '</li>'; $output .= '</ul>'; @@ -224,7 +227,7 @@ public function formViewsFormMediaLibraryPageAlter(array &$form, FormStateInterf foreach (Element::getVisibleChildren($form['media_bulk_form']) as $key) { if (isset($view->result[$key])) { $media = $view->field['media_bulk_form']->getEntity($view->result[$key]); - $form['media_bulk_form'][$key]['#title'] = $media ? t('Select @label', ['@label' => $media->label()]) : ''; + $form['media_bulk_form'][$key]['#title'] = $media ? $this->t('Select @label', ['@label' => $media->label()]) : ''; } } } diff --git a/core/modules/media_library/src/Hook/MediaLibraryViewsHooks.php b/core/modules/media_library/src/Hook/MediaLibraryViewsHooks.php index aa56ed28a2d037e3b14869df2d7ddad8151b9985..32137ab0a813f36bfadeb52a105c593c25024dba 100644 --- a/core/modules/media_library/src/Hook/MediaLibraryViewsHooks.php +++ b/core/modules/media_library/src/Hook/MediaLibraryViewsHooks.php @@ -3,12 +3,15 @@ namespace Drupal\media_library\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for media_library. */ class MediaLibraryViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data(). */ @@ -16,8 +19,8 @@ class MediaLibraryViewsHooks { public function viewsData(): array { $data = []; $data['media']['media_library_select_form'] = [ - 'title' => t('Select media'), - 'help' => t('Provides a field for selecting media entities in our media library view'), + 'title' => $this->t('Select media'), + 'help' => $this->t('Provides a field for selecting media entities in our media library view'), 'real field' => 'mid', 'field' => [ 'id' => 'media_library_select_form', diff --git a/core/modules/menu_link_content/src/Hook/MenuLinkContentHooks.php b/core/modules/menu_link_content/src/Hook/MenuLinkContentHooks.php index d79542bca1953e602010ac6a91df04d4b6430266..e696519b68a8528a4252848198dbc7db3416bde8 100644 --- a/core/modules/menu_link_content/src/Hook/MenuLinkContentHooks.php +++ b/core/modules/menu_link_content/src/Hook/MenuLinkContentHooks.php @@ -3,6 +3,7 @@ namespace Drupal\menu_link_content\Hook; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\path_alias\PathAliasInterface; use Drupal\system\MenuInterface; use Drupal\Core\Url; @@ -14,6 +15,8 @@ */ class MenuLinkContentHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,10 +25,10 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.menu_link_content': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Custom Menu Links module allows users to create menu links. These links can be translated if multiple languages are used for the site.'); + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Custom Menu Links module allows users to create menu links. These links can be translated if multiple languages are used for the site.'); if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { - $output .= ' ' . t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. For more information, see the <a href=":menu-help">Menu UI module help page</a> and the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>.', [ + $output .= ' ' . $this->t('It is required by the Menu UI module, which provides an interface for managing menus and menu links. For more information, see the <a href=":menu-help">Menu UI module help page</a> and the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>.', [ ':menu-help' => Url::fromRoute('help.page', [ 'name' => 'menu_ui', ])->toString(), @@ -33,7 +36,7 @@ public function help($route_name, RouteMatchInterface $route_match) { ]); } else { - $output .= ' ' . t('For more information, see the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>. If you install the Menu UI module, it provides an interface for managing menus and menu links.', [':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']); + $output .= ' ' . $this->t('For more information, see the <a href=":drupal-org-help">online documentation for the Custom Menu Links module</a>. If you install the Menu UI module, it provides an interface for managing menus and menu links.', [':drupal-org-help' => 'https://www.drupal.org/documentation/modules/menu_link']); } $output .= '</p>'; return $output; diff --git a/core/modules/menu_ui/src/Hook/MenuUiHooks.php b/core/modules/menu_ui/src/Hook/MenuUiHooks.php index beefde3947b63da0940fa0ddea07acadbad942b2..572c554c317f1ab17059992089e558a37f68a5ae 100644 --- a/core/modules/menu_ui/src/Hook/MenuUiHooks.php +++ b/core/modules/menu_ui/src/Hook/MenuUiHooks.php @@ -8,6 +8,7 @@ use Drupal\Core\Menu\MenuLinkInterface; use Drupal\Core\Breadcrumb\Breadcrumb; use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\system\MenuInterface; use Drupal\system\Entity\Menu; use Drupal\Core\Form\FormStateInterface; @@ -21,6 +22,8 @@ */ class MenuUiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -29,21 +32,21 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.menu_ui': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Menu UI module provides an interface for managing menus. A menu is a hierarchical collection of links, which can be within or external to the site, generally used for navigation. For more information, see the <a href=":menu">online documentation for the Menu UI module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Menu UI module provides an interface for managing menus. A menu is a hierarchical collection of links, which can be within or external to the site, generally used for navigation. For more information, see the <a href=":menu">online documentation for the Menu UI module</a>.', [ ':menu' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/menu-ui-module', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing menus') . '</dt>'; - $output .= '<dd>' . t('Users with the <em>Administer menus and menu links</em> permission can add, edit, and delete custom menus on the <a href=":menu">Menus page</a>. Custom menus can be special site menus, menus of external links, or any combination of internal and external links. You may create an unlimited number of additional menus, each of which will automatically have an associated block (if you have the <a href=":block_help">Block module</a> installed). By selecting <em>Edit menu</em>, you can add, edit, or delete links for a given menu. The links listing page provides a drag-and-drop interface for controlling the order of links, and creating a hierarchy within the menu.', [ + $output .= '<dt>' . $this->t('Managing menus') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the <em>Administer menus and menu links</em> permission can add, edit, and delete custom menus on the <a href=":menu">Menus page</a>. Custom menus can be special site menus, menus of external links, or any combination of internal and external links. You may create an unlimited number of additional menus, each of which will automatically have an associated block (if you have the <a href=":block_help">Block module</a> installed). By selecting <em>Edit menu</em>, you can add, edit, or delete links for a given menu. The links listing page provides a drag-and-drop interface for controlling the order of links, and creating a hierarchy within the menu.', [ ':block_help' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('help.page', [ 'name' => 'block', ])->toString() : '#', ':menu' => Url::fromRoute('entity.menu.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Displaying menus') . '</dt>'; - $output .= '<dd>' . t('If you have the Block module installed, then each menu that you create is rendered in a block that you enable and position on the <a href=":blocks">Block layout page</a>. In some <a href=":themes">themes</a>, the main menu and possibly the secondary menu will be output automatically; you may be able to disable this behavior on the <a href=":themes">theme\'s settings page</a>.', [ + $output .= '<dt>' . $this->t('Displaying menus') . '</dt>'; + $output .= '<dd>' . $this->t('If you have the Block module installed, then each menu that you create is rendered in a block that you enable and position on the <a href=":blocks">Block layout page</a>. In some <a href=":themes">themes</a>, the main menu and possibly the secondary menu will be output automatically; you may be able to disable this behavior on the <a href=":themes">theme\'s settings page</a>.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ':themes' => Url::fromRoute('system.themes_page')->toString(), ':theme_settings' => Url::fromRoute('system.theme_settings')->toString(), @@ -52,10 +55,10 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; } if ($route_name == 'entity.menu.add_form' && \Drupal::moduleHandler()->moduleExists('block') && \Drupal::currentUser()->hasPermission('administer blocks')) { - return '<p>' . t('You can enable the newly-created block for this menu on the <a href=":blocks">Block layout page</a>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; + return '<p>' . $this->t('You can enable the newly-created block for this menu on the <a href=":blocks">Block layout page</a>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; } elseif ($route_name == 'entity.menu.collection' && \Drupal::moduleHandler()->moduleExists('block') && \Drupal::currentUser()->hasPermission('administer blocks')) { - return '<p>' . t('Each menu has a corresponding block that is managed on the <a href=":blocks">Block layout page</a>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; + return '<p>' . $this->t('Each menu has a corresponding block that is managed on the <a href=":blocks">Block layout page</a>.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; } } @@ -123,7 +126,7 @@ public function formNodeFormAlter(&$form, FormStateInterface $form_state) : void } $form['menu'] = [ '#type' => 'details', - '#title' => t('Menu settings'), + '#title' => $this->t('Menu settings'), '#access' => \Drupal::currentUser()->hasPermission('administer menu'), '#open' => (bool) $defaults['id'], '#group' => 'advanced', @@ -142,7 +145,7 @@ public function formNodeFormAlter(&$form, FormStateInterface $form_state) : void ]; $form['menu']['enabled'] = [ '#type' => 'checkbox', - '#title' => t('Provide a menu link'), + '#title' => $this->t('Provide a menu link'), '#default_value' => (int) (bool) $defaults['id'], ]; $form['menu']['link'] = [ @@ -164,25 +167,25 @@ public function formNodeFormAlter(&$form, FormStateInterface $form_state) : void } $form['menu']['link']['title'] = [ '#type' => 'textfield', - '#title' => t('Menu link title'), + '#title' => $this->t('Menu link title'), '#default_value' => $defaults['title'], '#maxlength' => $defaults['title_max_length'], ]; $form['menu']['link']['description'] = [ '#type' => 'textfield', - '#title' => t('Description'), + '#title' => $this->t('Description'), '#default_value' => $defaults['description'], - '#description' => t('Shown when hovering over the menu link.'), + '#description' => $this->t('Shown when hovering over the menu link.'), '#maxlength' => $defaults['description_max_length'], ]; $form['menu']['link']['menu_parent'] = $parent_element; - $form['menu']['link']['menu_parent']['#title'] = t('Parent link'); + $form['menu']['link']['menu_parent']['#title'] = $this->t('Parent link'); $form['menu']['link']['menu_parent']['#attributes']['class'][] = 'menu-parent-select'; $form['menu']['link']['weight'] = [ '#type' => 'number', - '#title' => t('Weight'), + '#title' => $this->t('Weight'), '#default_value' => $defaults['weight'], - '#description' => t('Menu links with lower weights are displayed before links with higher weights.'), + '#description' => $this->t('Menu links with lower weights are displayed before links with higher weights.'), ]; foreach (array_keys($form['actions']) as $action) { if ($action != 'preview' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') { @@ -212,7 +215,7 @@ public function formNodeTypeFormAlter(&$form, FormStateInterface $form_state) : $type = $form_state->getFormObject()->getEntity(); $form['menu'] = [ '#type' => 'details', - '#title' => t('Menu settings'), + '#title' => $this->t('Menu settings'), '#attached' => [ 'library' => [ 'menu_ui/drupal.menu_ui.admin', @@ -222,12 +225,12 @@ public function formNodeTypeFormAlter(&$form, FormStateInterface $form_state) : ]; $form['menu']['menu_options'] = [ '#type' => 'checkboxes', - '#title' => t('Available menus'), + '#title' => $this->t('Available menus'), '#default_value' => $type->getThirdPartySetting('menu_ui', 'available_menus', [ 'main', ]), '#options' => $menu_options, - '#description' => t('Content of this type can be placed in the selected menus.'), + '#description' => $this->t('Content of this type can be placed in the selected menus.'), ]; // @todo See if we can avoid pre-loading all options by changing the form or // using a #process callback. https://www.drupal.org/node/2310319 To avoid @@ -238,10 +241,10 @@ public function formNodeTypeFormAlter(&$form, FormStateInterface $form_state) : $options = $menu_parent_selector->getParentSelectOptions('', NULL, $options_cacheability); $form['menu']['menu_parent'] = [ '#type' => 'select', - '#title' => t('Default parent link'), + '#title' => $this->t('Default parent link'), '#default_value' => $type->getThirdPartySetting('menu_ui', 'parent', 'main:'), '#options' => $options, - '#description' => t('Choose the menu link to be the default parent for a new link in the content authoring form.'), + '#description' => $this->t('Choose the menu link to be the default parent for a new link in the content authoring form.'), '#attributes' => [ 'class' => [ 'menu-title-select', @@ -288,7 +291,7 @@ public function entityOperation(EntityInterface $entity) : array { if ($plugin->getBaseId() === 'system_menu_block') { $menu = Menu::load($plugin->getDerivativeId()); if ($menu && $menu->access('edit')) { - $operations['menu-edit'] = ['title' => t('Edit menu'), 'url' => $menu->toUrl('edit-form'), 'weight' => 50]; + $operations['menu-edit'] = ['title' => $this->t('Edit menu'), 'url' => $menu->toUrl('edit-form'), 'weight' => 50]; } } } diff --git a/core/modules/migrate/src/Hook/MigrateHooks.php b/core/modules/migrate/src/Hook/MigrateHooks.php index d1db2505a85abc617134298966a36f8ec320d4e3..4f54ec1979221ca0b091fdd5983dca00956012cb 100644 --- a/core/modules/migrate/src/Hook/MigrateHooks.php +++ b/core/modules/migrate/src/Hook/MigrateHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for migrate. */ class MigrateHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -17,9 +20,9 @@ class MigrateHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.migrate': - $output = '<h2>' . t('About') . '</h2>'; + $output = '<h2>' . $this->t('About') . '</h2>'; $output .= '<p>'; - $output .= t('The Migrate module provides a framework for migrating data, usually from an external source into your site. It does not provide a user interface. For more information, see the <a href=":migrate">online documentation for the Migrate module</a>.', [':migrate' => 'https://www.drupal.org/documentation/modules/migrate']); + $output .= $this->t('The Migrate module provides a framework for migrating data, usually from an external source into your site. It does not provide a user interface. For more information, see the <a href=":migrate">online documentation for the Migrate module</a>.', [':migrate' => 'https://www.drupal.org/documentation/modules/migrate']); $output .= '</p>'; return $output; } diff --git a/core/modules/migrate_drupal/src/Hook/MigrateDrupalHooks.php b/core/modules/migrate_drupal/src/Hook/MigrateDrupalHooks.php index aa4d7e7718d0fb4117d5391324fafdd5fdd96dd2..1fbeeda44bc4212460638bc07752f400ec9a8c08 100644 --- a/core/modules/migrate_drupal/src/Hook/MigrateDrupalHooks.php +++ b/core/modules/migrate_drupal/src/Hook/MigrateDrupalHooks.php @@ -2,6 +2,7 @@ namespace Drupal\migrate_drupal\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\migrate_drupal\NodeMigrateType; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\migrate\Exception\RequirementsException; @@ -16,6 +17,8 @@ */ class MigrateDrupalHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -24,8 +27,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.migrate_drupal': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Migrate Drupal module provides a framework based on the <a href=":migrate">Migrate module</a> to facilitate migration from a Drupal (6, 7, or 8) site to your website. It does not provide a user interface. For more information, see the <a href=":migrate_drupal">online documentation for the Migrate Drupal module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Migrate Drupal module provides a framework based on the <a href=":migrate">Migrate module</a> to facilitate migration from a Drupal (6, 7, or 8) site to your website. It does not provide a user interface. For more information, see the <a href=":migrate_drupal">online documentation for the Migrate Drupal module</a>.', [ ':migrate' => Url::fromRoute('help.page', [ 'name' => 'migrate', ])->toString(), @@ -115,7 +118,7 @@ public function migrationPluginsAlter(array &$definitions): void { $version = NodeMigrateType::getLegacyDrupalVersion($source_connection); } catch (\Exception $e) { - \Drupal::messenger()->addError(t('Failed to connect to your database server. The server reports the following message: %error.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname?</li></ul>', ['%error' => $e->getMessage()])); + \Drupal::messenger()->addError($this->t('Failed to connect to your database server. The server reports the following message: %error.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname?</li></ul>', ['%error' => $e->getMessage()])); } } // If this is a complete node migration then for all migrations, except the diff --git a/core/modules/migrate_drupal_ui/src/Hook/MigrateDrupalUiHooks.php b/core/modules/migrate_drupal_ui/src/Hook/MigrateDrupalUiHooks.php index 48b045806d7e7618aff66735ed43f1b35128a7ae..5ff282cd0995cc39fbf8e5a01c52890fb3799bfe 100644 --- a/core/modules/migrate_drupal_ui/src/Hook/MigrateDrupalUiHooks.php +++ b/core/modules/migrate_drupal_ui/src/Hook/MigrateDrupalUiHooks.php @@ -2,6 +2,7 @@ namespace Drupal\migrate_drupal_ui\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class MigrateDrupalUiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,28 +22,28 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.migrate_drupal_ui': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Migrate Drupal UI module provides a simple user interface to perform an upgrade from an earlier version of Drupal. For more information, see the <a href=":migrate">online documentation for the Migrate Drupal UI module</a>.', [':migrate' => 'https://www.drupal.org/upgrade/migrate']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Migrate Drupal UI module provides a simple user interface to perform an upgrade from an earlier version of Drupal. For more information, see the <a href=":migrate">online documentation for the Migrate Drupal UI module</a>.', [':migrate' => 'https://www.drupal.org/upgrade/migrate']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Preparing the site') . '</dt>'; - $output .= '<dd>' . t('You need to install all modules on this site that are installed on the previous site. For example, if you have used the Book module on the previous site then you must install the Book module on this site for that data to be available on this site.') . '</dd>'; - $output .= '<dt>' . t('Performing the upgrade') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":upgrade">Upgrade</a> page, you are guided through performing the upgrade in several steps.', [ + $output .= '<dt>' . $this->t('Preparing the site') . '</dt>'; + $output .= '<dd>' . $this->t('You need to install all modules on this site that are installed on the previous site. For example, if you have used the Book module on the previous site then you must install the Book module on this site for that data to be available on this site.') . '</dd>'; + $output .= '<dt>' . $this->t('Performing the upgrade') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":upgrade">Upgrade</a> page, you are guided through performing the upgrade in several steps.', [ ':upgrade' => Url::fromRoute('migrate_drupal_ui.upgrade')->toString(), ]) . '</dd>'; - $output .= '<dd><ol><li>' . t('If an upgrade has been performed on this site, you will be informed.') . '</li>'; - $output .= '<li>' . t('You need to enter the database credentials of the Drupal site that you want to upgrade. You can also include its files directory in the upgrade. For example local files, /var/www/docroot, or remote files http://www.example.com.') . '</li>'; - $output .= '<li>' . t('If there is existing content on the site that may be overwritten by this upgrade, you will be informed.') . '</li>'; - $output .= '<li>' . t('The next page provides an overview of the modules that will be upgraded and those that will not be upgraded, before you proceed to perform the upgrade.') . '</li>'; - $output .= '<li>' . t('Finally, a message is displayed about the number of upgrade tasks that were successful or failed.') . '</li></ol></dd>'; - $output .= '<dt>' . t('Reviewing the upgrade log') . '</dt>'; - $output .= '<dd>' . t('You can review a <a href=":log">log of upgrade messages</a> by clicking the link in the message provided after the upgrade or by filtering the messages for the type <em>migrate_drupal_ui</em> on the <a href=":messages">Recent log messages</a> page.', [ + $output .= '<dd><ol><li>' . $this->t('If an upgrade has been performed on this site, you will be informed.') . '</li>'; + $output .= '<li>' . $this->t('You need to enter the database credentials of the Drupal site that you want to upgrade. You can also include its files directory in the upgrade. For example local files, /var/www/docroot, or remote files http://www.example.com.') . '</li>'; + $output .= '<li>' . $this->t('If there is existing content on the site that may be overwritten by this upgrade, you will be informed.') . '</li>'; + $output .= '<li>' . $this->t('The next page provides an overview of the modules that will be upgraded and those that will not be upgraded, before you proceed to perform the upgrade.') . '</li>'; + $output .= '<li>' . $this->t('Finally, a message is displayed about the number of upgrade tasks that were successful or failed.') . '</li></ol></dd>'; + $output .= '<dt>' . $this->t('Reviewing the upgrade log') . '</dt>'; + $output .= '<dd>' . $this->t('You can review a <a href=":log">log of upgrade messages</a> by clicking the link in the message provided after the upgrade or by filtering the messages for the type <em>migrate_drupal_ui</em> on the <a href=":messages">Recent log messages</a> page.', [ ':log' => Url::fromRoute('migrate_drupal_ui.log')->toString(), ':messages' => Url::fromRoute('dblog.overview')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Rolling back an upgrade') . '</dt>'; - $output .= '<dd>' . t('Rolling back an upgrade is not yet supported through the user interface.') . '</dd>'; + $output .= '<dt>' . $this->t('Rolling back an upgrade') . '</dt>'; + $output .= '<dd>' . $this->t('Rolling back an upgrade is not yet supported through the user interface.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/mysql/src/Hook/MysqlHooks.php b/core/modules/mysql/src/Hook/MysqlHooks.php index 4b7e2db531cc0f76e65986de319477d3adb5ed6a..c1ada0bf743208fef908c65335dbb9c9cb74c332 100644 --- a/core/modules/mysql/src/Hook/MysqlHooks.php +++ b/core/modules/mysql/src/Hook/MysqlHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for mysql. */ class MysqlHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -18,8 +21,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.mysql': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The MySQL module provides the connection between Drupal and a MySQL, MariaDB or equivalent database. For more information, see the <a href=":mysql">online documentation for the MySQL module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The MySQL module provides the connection between Drupal and a MySQL, MariaDB or equivalent database. For more information, see the <a href=":mysql">online documentation for the MySQL module</a>.', [ ':mysql' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/mysql-module', ]) . '</p>'; return $output; diff --git a/core/modules/navigation/modules/navigation_top_bar/src/Hook/NavigationTopBarHooks.php b/core/modules/navigation/modules/navigation_top_bar/src/Hook/NavigationTopBarHooks.php index 2d7f10f03dd62211ec80f6cb56482a7f0ce2cc35..459fe60dc6046c9e8066af1bf6aced956963a266 100644 --- a/core/modules/navigation/modules/navigation_top_bar/src/Hook/NavigationTopBarHooks.php +++ b/core/modules/navigation/modules/navigation_top_bar/src/Hook/NavigationTopBarHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for navigation_top_bar. */ class NavigationTopBarHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -17,12 +20,12 @@ class NavigationTopBarHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.navigation_top_bar': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Navigation Top Bar module is a Feature Flag module which, when enabled, renders the experimental navigation top bar.') . '</p>'; - $output .= '<p>' . t('The top bar provides relevant administrative information and tasks for the current page. It is not feature complete nor fully functional.') . '</p>'; - $output .= '<p>' . t('Leaving this module enabled can affect both admin and front-end pages layouts and blocks like Primary admin actions, whose content might be moved to te top bar.') . '</p>'; - $output .= '<p>' . t('It is recommended to leave this module off while it is under active development and experimental phase.') . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":docs">online documentation for the Navigation Top Bar module</a>.', [':docs' => 'https://www.drupal.org/project/navigation']) . '</p>'; + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Navigation Top Bar module is a Feature Flag module which, when enabled, renders the experimental navigation top bar.') . '</p>'; + $output .= '<p>' . $this->t('The top bar provides relevant administrative information and tasks for the current page. It is not feature complete nor fully functional.') . '</p>'; + $output .= '<p>' . $this->t('Leaving this module enabled can affect both admin and front-end pages layouts and blocks like Primary admin actions, whose content might be moved to te top bar.') . '</p>'; + $output .= '<p>' . $this->t('It is recommended to leave this module off while it is under active development and experimental phase.') . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":docs">online documentation for the Navigation Top Bar module</a>.', [':docs' => 'https://www.drupal.org/project/navigation']) . '</p>'; return $output; } } diff --git a/core/modules/navigation/src/Hook/NavigationHooks.php b/core/modules/navigation/src/Hook/NavigationHooks.php index 024c1607dd53901023431daca9cf606e7a235a99..740ac71add28cc83133bb3d308f05dfd3eb3e1f3 100644 --- a/core/modules/navigation/src/Hook/NavigationHooks.php +++ b/core/modules/navigation/src/Hook/NavigationHooks.php @@ -41,9 +41,9 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.navigation': $output = ''; - $output .= '<h3>' . t('About') . '</h3>'; - $output .= '<p>' . t('The Navigation module provides a left-aligned, collapsible, vertical sidebar navigation.') . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":docs">online documentation for the Navigation module</a>.', [':docs' => 'https://www.drupal.org/project/navigation']) . '</p>'; + $output .= '<h3>' . $this->t('About') . '</h3>'; + $output .= '<p>' . $this->t('The Navigation module provides a left-aligned, collapsible, vertical sidebar navigation.') . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":docs">online documentation for the Navigation module</a>.', [':docs' => 'https://www.drupal.org/project/navigation']) . '</p>'; return $output; } $configuration_route = 'layout_builder.navigation.'; @@ -51,8 +51,8 @@ public function help($route_name, RouteMatchInterface $route_match) { return \Drupal::moduleHandler()->invoke('layout_builder', 'help', [$route_name, $route_match]); } if (str_starts_with($route_name, $configuration_route)) { - $output = '<p>' . t('This layout builder tool allows you to configure the blocks in the navigation toolbar.') . '</p>'; - $output .= '<p>' . t('Forms and links inside the content of the layout builder tool have been disabled.') . '</p>'; + $output = '<p>' . $this->t('This layout builder tool allows you to configure the blocks in the navigation toolbar.') . '</p>'; + $output .= '<p>' . $this->t('Forms and links inside the content of the layout builder tool have been disabled.') . '</p>'; return $output; } } diff --git a/core/modules/node/src/Hook/NodeHooks1.php b/core/modules/node/src/Hook/NodeHooks1.php index a2f032c75c8b85e5a0664f41f16ae44411a06e7e..7f8bdd8c1872a4c4434a14e0077607332954276a 100644 --- a/core/modules/node/src/Hook/NodeHooks1.php +++ b/core/modules/node/src/Hook/NodeHooks1.php @@ -3,6 +3,7 @@ namespace Drupal\node\Hook; use Drupal\Core\Access\AccessResultInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\language\ConfigurableLanguageInterface; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\AlterableInterface; @@ -23,6 +24,8 @@ */ class NodeHooks1 { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -33,10 +36,10 @@ public function help($route_name, RouteMatchInterface $route_match) { // while the rebuild is being processed. if ($route_name != 'node.configure_rebuild_confirm' && $route_name != 'system.batch_page.html' && $route_name != 'help.page.node' && $route_name != 'help.main' && \Drupal::currentUser()->hasPermission('administer nodes') && node_access_needs_rebuild()) { if ($route_name == 'system.status') { - $message = t('The content access permissions need to be rebuilt.'); + $message = $this->t('The content access permissions need to be rebuilt.'); } else { - $message = t('The content access permissions need to be rebuilt. <a href=":node_access_rebuild">Rebuild permissions</a>.', [ + $message = $this->t('The content access permissions need to be rebuilt. <a href=":node_access_rebuild">Rebuild permissions</a>.', [ ':node_access_rebuild' => Url::fromRoute('node.configure_rebuild_confirm')->toString(), ]); } @@ -45,32 +48,32 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.node': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href=":field">Field module</a>). For more information, see the <a href=":node">online documentation for the Node module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Node module manages the creation, editing, deletion, settings, and display of the main site content. Content items managed by the Node module are typically displayed as pages on your site, and include a title, some meta-data (author, creation time, content type, etc.), and optional fields containing text or other data (fields are managed by the <a href=":field">Field module</a>). For more information, see the <a href=":node">online documentation for the Node module</a>.', [ ':node' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/node-module', ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating content') . '</dt>'; - $output .= '<dd>' . t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href=":content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href=":content-type">type of content</a> on your site.', [ + $output .= '<dt>' . $this->t('Creating content') . '</dt>'; + $output .= '<dd>' . $this->t('When new content is created, the Node module records basic information about the content, including the author, date of creation, and the <a href=":content-type">Content type</a>. It also manages the <em>publishing options</em>, which define whether or not the content is published, promoted to the front page of the site, and/or sticky at the top of content lists. Default settings can be configured for each <a href=":content-type">type of content</a> on your site.', [ ':content-type' => Url::fromRoute('entity.node_type.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Creating custom content types') . '</dt>'; - $output .= '<dd>' . t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href=":content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types gives you the flexibility to add <a href=":field">fields</a> and configure default settings that suit the differing needs of various site content.', [ + $output .= '<dt>' . $this->t('Creating custom content types') . '</dt>'; + $output .= '<dd>' . $this->t('The Node module gives users with the <em>Administer content types</em> permission the ability to <a href=":content-new">create new content types</a> in addition to the default ones already configured. Creating custom content types gives you the flexibility to add <a href=":field">fields</a> and configure default settings that suit the differing needs of various site content.', [ ':content-new' => Url::fromRoute('node.type_add')->toString(), ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Administering content') . '</dt>'; - $output .= '<dd>' . t('The <a href=":content">Content</a> page lists your content, allowing you add new content, filter, edit or delete existing content, or perform bulk operations on existing content.', [':content' => Url::fromRoute('system.admin_content')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Creating revisions') . '</dt>'; - $output .= '<dd>' . t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>'; - $output .= '<dt>' . t('User permissions') . '</dt>'; - $output .= '<dd>' . t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href=":permissions">permissions page</a>.', [ + $output .= '<dt>' . $this->t('Administering content') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":content">Content</a> page lists your content, allowing you add new content, filter, edit or delete existing content, or perform bulk operations on existing content.', [':content' => Url::fromRoute('system.admin_content')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Creating revisions') . '</dt>'; + $output .= '<dd>' . $this->t('The Node module also enables you to create multiple versions of any content, and revert to older versions using the <em>Revision information</em> settings.') . '</dd>'; + $output .= '<dt>' . $this->t('User permissions') . '</dt>'; + $output .= '<dd>' . $this->t('The Node module makes a number of permissions available for each content type, which can be set by role on the <a href=":permissions">permissions page</a>.', [ ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'node', ])->toString(), @@ -79,20 +82,20 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'node.type_add': - return '<p>' . t('Individual content types can have different fields, behaviors, and permissions assigned to them.') . '</p>'; + return '<p>' . $this->t('Individual content types can have different fields, behaviors, and permissions assigned to them.') . '</p>'; case 'entity.entity_form_display.node.default': case 'entity.entity_form_display.node.form_mode': $type = $route_match->getParameter('node_type'); - return '<p>' . t('Content items can be edited using different form modes. Here, you can define which fields are shown and hidden when %type content is edited in each form mode, and define how the field form widgets are displayed in each form mode.', ['%type' => $type->label()]) . '</p>'; + return '<p>' . $this->t('Content items can be edited using different form modes. Here, you can define which fields are shown and hidden when %type content is edited in each form mode, and define how the field form widgets are displayed in each form mode.', ['%type' => $type->label()]) . '</p>'; case 'entity.entity_view_display.node.default': case 'entity.entity_view_display.node.view_mode': $type = $route_match->getParameter('node_type'); - return '<p>' . t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.') . '</p>' . '<p>' . t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', ['%type' => $type->label()]) . '</p>'; + return '<p>' . $this->t('Content items can be displayed using different view modes: Teaser, Full content, Print, RSS, etc. <em>Teaser</em> is a short format that is typically used in lists of multiple content items. <em>Full content</em> is typically used when the content is displayed on its own page.') . '</p>' . '<p>' . $this->t('Here, you can define which fields are shown and hidden when %type content is displayed in each view mode, and define how the fields are displayed in each view mode.', ['%type' => $type->label()]) . '</p>'; case 'entity.node.version_history': - return '<p>' . t('Revisions allow you to track differences between multiple versions of your content, and revert to older versions.') . '</p>'; + return '<p>' . $this->t('Revisions allow you to track differences between multiple versions of your content, and revert to older versions.') . '</p>'; case 'entity.node.edit_form': $node = $route_match->getParameter('node'); @@ -174,10 +177,10 @@ public function localTasksAlter(&$local_tasks) : void { #[Hook('entity_extra_field_info')] public function entityExtraFieldInfo(): array { $extra = []; - $description = t('Node module element'); + $description = $this->t('Node module element'); foreach (NodeType::loadMultiple() as $bundle) { $extra['node'][$bundle->id()]['display']['links'] = [ - 'label' => t('Links'), + 'label' => $this->t('Links'), 'description' => $description, 'weight' => 100, 'visible' => TRUE, @@ -214,17 +217,17 @@ public function ranking(): array { // Create the ranking array and add the basic ranking options. $ranking = [ 'relevance' => [ - 'title' => t('Keyword relevance'), + 'title' => $this->t('Keyword relevance'), // Average relevance values hover around 0.15 'score' => 'i.relevance', ], 'sticky' => [ - 'title' => t('Content is sticky at top of lists'), + 'title' => $this->t('Content is sticky at top of lists'), // The sticky flag is either 0 or 1, which is automatically normalized. 'score' => 'n.sticky', ], 'promote' => [ - 'title' => t('Content is promoted to the front page'), + 'title' => $this->t('Content is promoted to the front page'), // The promote flag is either 0 or 1, which is automatically normalized. 'score' => 'n.promote', ], @@ -233,7 +236,7 @@ public function ranking(): array { // been calculated in node_cron(). if ($node_min_max = \Drupal::state()->get('node.min_max_update_time')) { $ranking['recent'] = [ - 'title' => t('Recently created'), + 'title' => $this->t('Recently created'), // Exponential decay with half life of 14% of the age range of nodes. 'score' => 'EXP(-5 * (1 - (n.created - :node_oldest) / :node_range))', 'arguments' => [ @@ -295,8 +298,8 @@ public function pageTop(array &$page_top): void { public function formSystemThemesAdminFormAlter(&$form, FormStateInterface $form_state, $form_id) : void { $form['admin_theme']['use_admin_theme'] = [ '#type' => 'checkbox', - '#title' => t('Use the administration theme when editing or creating content'), - '#description' => t('Control which roles can "View the administration theme" on the <a href=":permissions">Permissions page</a>.', [ + '#title' => $this->t('Use the administration theme when editing or creating content'), + '#description' => $this->t('Control which roles can "View the administration theme" on the <a href=":permissions">Permissions page</a>.', [ ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'system', ])->toString(), diff --git a/core/modules/node/src/Hook/NodeTokensHooks.php b/core/modules/node/src/Hook/NodeTokensHooks.php index 6fbbf2f65eae86de39450d77909cd4ede9e2fa43..3d7f0b0adf4889dd11a00653bce8b0ad5aeb3b27 100644 --- a/core/modules/node/src/Hook/NodeTokensHooks.php +++ b/core/modules/node/src/Hook/NodeTokensHooks.php @@ -3,6 +3,7 @@ namespace Drupal\node\Hook; use Drupal\Core\Datetime\Entity\DateFormat; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\Entity\User; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\BubbleableMetadata; @@ -13,58 +14,60 @@ */ class NodeTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $type = [ - 'name' => t('Nodes'), - 'description' => t('Tokens related to individual content items, or "nodes".'), + 'name' => $this->t('Nodes'), + 'description' => $this->t('Tokens related to individual content items, or "nodes".'), 'needs-data' => 'node', ]; // Core tokens for nodes. $node['nid'] = [ - 'name' => t("Content ID"), - 'description' => t('The unique ID of the content item, or "node".'), + 'name' => $this->t("Content ID"), + 'description' => $this->t('The unique ID of the content item, or "node".'), ]; $node['uuid'] = [ - 'name' => t('UUID'), - 'description' => t('The UUID of the content item, or "node".'), + 'name' => $this->t('UUID'), + 'description' => $this->t('The UUID of the content item, or "node".'), ]; $node['vid'] = [ - 'name' => t("Revision ID"), - 'description' => t("The unique ID of the node's latest revision."), + 'name' => $this->t("Revision ID"), + 'description' => $this->t("The unique ID of the node's latest revision."), ]; - $node['type'] = ['name' => t("Content type")]; + $node['type'] = ['name' => $this->t("Content type")]; $node['type-name'] = [ - 'name' => t("Content type name"), - 'description' => t("The human-readable name of the node type."), + 'name' => $this->t("Content type name"), + 'description' => $this->t("The human-readable name of the node type."), ]; - $node['title'] = ['name' => t("Title")]; - $node['body'] = ['name' => t("Body"), 'description' => t("The main body text of the node.")]; + $node['title'] = ['name' => $this->t("Title")]; + $node['body'] = ['name' => $this->t("Body"), 'description' => $this->t("The main body text of the node.")]; $node['summary'] = [ - 'name' => t("Summary"), - 'description' => t("The summary of the node's main body text."), + 'name' => $this->t("Summary"), + 'description' => $this->t("The summary of the node's main body text."), ]; $node['langcode'] = [ - 'name' => t('Language code'), - 'description' => t('The language code of the language the node is written in.'), + 'name' => $this->t('Language code'), + 'description' => $this->t('The language code of the language the node is written in.'), ]; $node['published_status'] = [ - 'name' => t('Published'), - 'description' => t('The publication status of the node ("Published" or "Unpublished").'), + 'name' => $this->t('Published'), + 'description' => $this->t('The publication status of the node ("Published" or "Unpublished").'), ]; - $node['url'] = ['name' => t("URL"), 'description' => t("The URL of the node.")]; - $node['edit-url'] = ['name' => t("Edit URL"), 'description' => t("The URL of the node's edit page.")]; + $node['url'] = ['name' => $this->t("URL"), 'description' => $this->t("The URL of the node.")]; + $node['edit-url'] = ['name' => $this->t("Edit URL"), 'description' => $this->t("The URL of the node's edit page.")]; // Chained tokens for nodes. - $node['created'] = ['name' => t("Date created"), 'type' => 'date']; + $node['created'] = ['name' => $this->t("Date created"), 'type' => 'date']; $node['changed'] = [ - 'name' => t("Date changed"), - 'description' => t("The date the node was most recently updated."), + 'name' => $this->t("Date changed"), + 'description' => $this->t("The date the node was most recently updated."), 'type' => 'date', ]; - $node['author'] = ['name' => t("Author"), 'type' => 'user']; + $node['author'] = ['name' => $this->t("Author"), 'type' => 'user']; return ['types' => ['node' => $type], 'tokens' => ['node' => $node]]; } @@ -152,7 +155,7 @@ public function tokens($type, $tokens, array $data, array $options, BubbleableMe break; case 'published_status': - $replacements[$original] = $node->isPublished() ? t('Published') : t('Unpublished'); + $replacements[$original] = $node->isPublished() ? $this->t('Published') : $this->t('Unpublished'); break; case 'url': diff --git a/core/modules/node/src/Hook/NodeViewsHooks.php b/core/modules/node/src/Hook/NodeViewsHooks.php index 1e287d36234172fe0a6c51b030db396ea4c1eb05..477784c153d8b7767f5a740a8f96fe18bd0e20ad 100644 --- a/core/modules/node/src/Hook/NodeViewsHooks.php +++ b/core/modules/node/src/Hook/NodeViewsHooks.php @@ -2,6 +2,7 @@ namespace Drupal\node\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\Analyzer; use Drupal\user\RoleInterface; use Drupal\user\Entity\Role; @@ -13,6 +14,8 @@ */ class NodeViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_analyze(). */ @@ -31,7 +34,7 @@ public function viewsAnalyze(ViewExecutable $view): array { $authenticated_role = Role::load(RoleInterface::AUTHENTICATED_ID); $authenticated_has_access = $authenticated_role && $authenticated_role->hasPermission('access content'); if (!$anonymous_has_access || !$authenticated_has_access) { - $ret[] = Analyzer::formatMessage(t('Some roles lack permission to access content, but display %display has no access control.', ['%display' => $display->display['display_title']]), 'warning'); + $ret[] = Analyzer::formatMessage($this->t('Some roles lack permission to access content, but display %display has no access control.', ['%display' => $display->display['display_title']]), 'warning'); } $filters = $display->getOption('filters'); foreach ($filters as $filter) { @@ -39,7 +42,7 @@ public function viewsAnalyze(ViewExecutable $view): array { continue 2; } } - $ret[] = Analyzer::formatMessage(t('Display %display has no access control but does not contain a filter for published nodes.', ['%display' => $display->display['display_title']]), 'warning'); + $ret[] = Analyzer::formatMessage($this->t('Display %display has no access control but does not contain a filter for published nodes.', ['%display' => $display->display['display_title']]), 'warning'); } } } @@ -47,7 +50,7 @@ public function viewsAnalyze(ViewExecutable $view): array { foreach ($view->displayHandlers as $display) { if ($display->getPluginId() == 'page') { if ($display->getOption('path') == 'node/%') { - $ret[] = Analyzer::formatMessage(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use Layout Builder.', ['%display' => $display->display['display_title']]), 'warning'); + $ret[] = Analyzer::formatMessage($this->t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use Layout Builder.', ['%display' => $display->display['display_title']]), 'warning'); } } } diff --git a/core/modules/options/src/Hook/OptionsHooks.php b/core/modules/options/src/Hook/OptionsHooks.php index f309428bce8ba08fdf20904ea459f80ac0bbbc45..add3bba5dd39784c04652e01c3d0b7dd66b91746 100644 --- a/core/modules/options/src/Hook/OptionsHooks.php +++ b/core/modules/options/src/Hook/OptionsHooks.php @@ -3,6 +3,7 @@ namespace Drupal\options\Hook; use Drupal\Core\Entity\Exception\FieldStorageDefinitionUpdateForbiddenException; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -13,6 +14,8 @@ */ class OptionsHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -21,8 +24,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.options': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Options module allows you to create fields where data values are selected from a fixed list of options. Usually these items are entered through a select list, checkboxes, or radio buttons. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":options_do">online documentation for the Options module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Options module allows you to create fields where data values are selected from a fixed list of options. Usually these items are entered through a select list, checkboxes, or radio buttons. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":options_do">online documentation for the Options module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -31,18 +34,18 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':options_do' => 'https://www.drupal.org/documentation/modules/options', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying list fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the list fields can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying list fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the list fields can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Defining option keys and labels') . '</dt>'; - $output .= '<dd>' . t('When you define the list options you can define a key and a label for each option in the list. The label will be shown to the users while the key gets stored in the database.') . '</dd>'; - $output .= '<dt>' . t('Choosing list field type') . '</dt>'; - $output .= '<dd>' . t('There are three types of list fields, which store different types of data: <em>float</em>, <em>integer</em> or, <em>text</em>. The <em>float</em> type allows storing approximate decimal values. The <em>integer</em> type allows storing whole numbers, such as years (for example, 2012) or values (for example, 1, 2, 5, 305). The <em>text</em> list field type allows storing text values. No matter which type of list field you choose, you can define whatever labels you wish for data entry.') . '</dd>'; + $output .= '<dt>' . $this->t('Defining option keys and labels') . '</dt>'; + $output .= '<dd>' . $this->t('When you define the list options you can define a key and a label for each option in the list. The label will be shown to the users while the key gets stored in the database.') . '</dd>'; + $output .= '<dt>' . $this->t('Choosing list field type') . '</dt>'; + $output .= '<dd>' . $this->t('There are three types of list fields, which store different types of data: <em>float</em>, <em>integer</em> or, <em>text</em>. The <em>float</em> type allows storing approximate decimal values. The <em>integer</em> type allows storing whole numbers, such as years (for example, 2012) or values (for example, 1, 2, 5, 305). The <em>text</em> list field type allows storing text values. No matter which type of list field you choose, you can define whatever labels you wish for data entry.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/package_manager/src/Hook/PackageManagerHooks.php b/core/modules/package_manager/src/Hook/PackageManagerHooks.php index 423ea9708c060879b9c814a55a54de45898fa1c4..2f07923b8cb5244258aa9b3ecccc823321d29707 100644 --- a/core/modules/package_manager/src/Hook/PackageManagerHooks.php +++ b/core/modules/package_manager/src/Hook/PackageManagerHooks.php @@ -2,6 +2,7 @@ namespace Drupal\package_manager\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\package_manager\ComposerInspector; use Drupal\Core\Hook\Attribute\Hook; @@ -10,6 +11,8 @@ */ class PackageManagerHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -17,15 +20,15 @@ class PackageManagerHooks { public function help($route_name) : ?string { switch ($route_name) { case 'help.page.package_manager': - $output = '<h3 id="package-manager-about">' . t('About') . '</h3>'; - $output .= '<p>' . t('Package Manager is a framework for updating Drupal core and installing contributed modules and themes via Composer. It has no user interface, but it provides an API for creating a temporary copy of the current site, making changes to the copy, and then syncing those changes back into the live site.') . '</p>'; - $output .= '<p>' . t('Package Manager dispatches events before and after various operations, and external code can integrate with it by subscribing to those events. For more information, see <code>package_manager.api.php</code>.') . '</p>'; - $output .= '<h3 id="package-manager-requirements">' . t('Requirements') . '</h3>'; + $output = '<h3 id="package-manager-about">' . $this->t('About') . '</h3>'; + $output .= '<p>' . $this->t('Package Manager is a framework for updating Drupal core and installing contributed modules and themes via Composer. It has no user interface, but it provides an API for creating a temporary copy of the current site, making changes to the copy, and then syncing those changes back into the live site.') . '</p>'; + $output .= '<p>' . $this->t('Package Manager dispatches events before and after various operations, and external code can integrate with it by subscribing to those events. For more information, see <code>package_manager.api.php</code>.') . '</p>'; + $output .= '<h3 id="package-manager-requirements">' . $this->t('Requirements') . '</h3>'; $output .= '<ul>'; - $output .= ' <li>' . t("The Drupal application's codebase must be writable in order to use Automatic Updates. This includes Drupal core, modules, themes and the Composer dependencies in the <code>vendor</code> directory. This makes Automatic Updates incompatible with some hosting platforms.") . '</li>'; - $output .= ' <li>' . t('Package Manager requires a Composer executable whose version satisfies <code>@version</code>, and PHP must have permission to run it.', ['@version' => ComposerInspector::SUPPORTED_VERSION]) . '</li>'; - $output .= ' <li>' . t("Your Drupal site's <code>composer.json</code> file must be valid according to <code>composer validate</code>. See <a href=\":url\">Composer's documentation</a> for more information.", [':url' => 'https://getcomposer.org/doc/03-cli.md#validate']) . '</li>'; - $output .= ' <li>' . t('Composer must be configured for secure downloads. This means that <a href=":disable-tls">the <code>disable-tls</code> option</a> must be <code>false</code>, and <a href=":secure-http">the <code>secure-http</code> option</a> must be <code>true</code> in the <code>config</code> section of your <code>composer.json</code> file. If these options are not set in your <code>composer.json</code>, Composer will behave securely by default. To set these values at the command line, run the following commands:', [ + $output .= ' <li>' . $this->t("The Drupal application's codebase must be writable in order to use Automatic Updates. This includes Drupal core, modules, themes and the Composer dependencies in the <code>vendor</code> directory. This makes Automatic Updates incompatible with some hosting platforms.") . '</li>'; + $output .= ' <li>' . $this->t('Package Manager requires a Composer executable whose version satisfies <code>@version</code>, and PHP must have permission to run it.', ['@version' => ComposerInspector::SUPPORTED_VERSION]) . '</li>'; + $output .= ' <li>' . $this->t("Your Drupal site's <code>composer.json</code> file must be valid according to <code>composer validate</code>. See <a href=\":url\">Composer's documentation</a> for more information.", [':url' => 'https://getcomposer.org/doc/03-cli.md#validate']) . '</li>'; + $output .= ' <li>' . $this->t('Composer must be configured for secure downloads. This means that <a href=":disable-tls">the <code>disable-tls</code> option</a> must be <code>false</code>, and <a href=":secure-http">the <code>secure-http</code> option</a> must be <code>true</code> in the <code>config</code> section of your <code>composer.json</code> file. If these options are not set in your <code>composer.json</code>, Composer will behave securely by default. To set these values at the command line, run the following commands:', [ ':disable-tls' => 'https://getcomposer.org/doc/06-config.md#disable-tls', ':secure-http' => 'https://getcomposer.org/doc/06-config.md#secure-http', ]); @@ -33,67 +36,67 @@ public function help($route_name) : ?string { $output .= "composer config --unset disable-tls\n"; $output .= "composer config --unset secure-http\n"; $output .= '</code></pre></li></ul>'; - $output .= '<h3 id="package-manager-limitations">' . t('Limitations') . '</h3>'; - $output .= '<p>' . t("Because Package Manager modifies the current site's code base, it is intentionally limited in certain ways to prevent unexpected changes to the live site:") . '</p>'; + $output .= '<h3 id="package-manager-limitations">' . $this->t('Limitations') . '</h3>'; + $output .= '<p>' . $this->t("Because Package Manager modifies the current site's code base, it is intentionally limited in certain ways to prevent unexpected changes to the live site:") . '</p>'; $output .= '<ul>'; - $output .= ' <li>' . t('It does not support Drupal multi-site installations.') . '</li>'; - $output .= ' <li>' . t('It only allows supported Composer plugins. If you have any, see <a href="#package-manager-faq-unsupported-composer-plugin">What if it says I have unsupported Composer plugins in my codebase?</a>.') . '</li>'; - $output .= ' <li>' . t('It does not automatically perform version control operations, e.g., with Git. Site administrators are responsible for committing updates.') . '</li>'; - $output .= ' <li>' . t('It can only maintain one copy of the site at any given time. If a copy of the site already exists, another one cannot be created until the existing copy is destroyed.') . '</li>'; - $output .= ' <li>' . t('It associates the temporary copy of the site with the user or session that originally created it, and only that user or session can make changes to it.') . '</li>'; - $output .= ' <li>' . t('It does not allow modules to be uninstalled while syncing changes into live site.') . '</li>'; + $output .= ' <li>' . $this->t('It does not support Drupal multi-site installations.') . '</li>'; + $output .= ' <li>' . $this->t('It only allows supported Composer plugins. If you have any, see <a href="#package-manager-faq-unsupported-composer-plugin">What if it says I have unsupported Composer plugins in my codebase?</a>.') . '</li>'; + $output .= ' <li>' . $this->t('It does not automatically perform version control operations, e.g., with Git. Site administrators are responsible for committing updates.') . '</li>'; + $output .= ' <li>' . $this->t('It can only maintain one copy of the site at any given time. If a copy of the site already exists, another one cannot be created until the existing copy is destroyed.') . '</li>'; + $output .= ' <li>' . $this->t('It associates the temporary copy of the site with the user or session that originally created it, and only that user or session can make changes to it.') . '</li>'; + $output .= ' <li>' . $this->t('It does not allow modules to be uninstalled while syncing changes into live site.') . '</li>'; $output .= '</ul>'; - $output .= '<p>' . t('For more information, see the <a href=":url">online documentation for the Package Manager module</a>.', [':url' => 'https://www.drupal.org/docs/8/core/modules/package-manager']) . '</p>'; - $output .= '<h3 id="package-manager-faq">' . t('FAQ') . '</h3>'; - $output .= '<h4 id="package-manager-composer-related-faq">' . t('FAQs related to Composer') . '</h4>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":url">online documentation for the Package Manager module</a>.', [':url' => 'https://www.drupal.org/docs/8/core/modules/package-manager']) . '</p>'; + $output .= '<h3 id="package-manager-faq">' . $this->t('FAQ') . '</h3>'; + $output .= '<h4 id="package-manager-composer-related-faq">' . $this->t('FAQs related to Composer') . '</h4>'; $output .= '<ul>'; - $output .= ' <li>' . t('What if it says the <code>proc_open()</code> function is disabled on your PHP installation?'); - $output .= ' <p>' . t('Ask your system administrator to remove <code>proc_open()</code> from the <a href=":url">disable_functions</a> setting in <code>php.ini</code>.', [':url' => 'https://www.php.net/manual/en/ini.core.php#ini.disable-functions']) . '</p>'; + $output .= ' <li>' . $this->t('What if it says the <code>proc_open()</code> function is disabled on your PHP installation?'); + $output .= ' <p>' . $this->t('Ask your system administrator to remove <code>proc_open()</code> from the <a href=":url">disable_functions</a> setting in <code>php.ini</code>.', [':url' => 'https://www.php.net/manual/en/ini.core.php#ini.disable-functions']) . '</p>'; $output .= ' </li>'; - $output .= ' <li>' . t('What if it says the <code>composer</code> executable cannot be found?'); - $output .= ' <p>' . t("If the <code>composer</code> executable's path cannot be automatically determined, it can be explicitly set by adding the following line to <code>settings.php</code>:") . '</p>'; + $output .= ' <li>' . $this->t('What if it says the <code>composer</code> executable cannot be found?'); + $output .= ' <p>' . $this->t("If the <code>composer</code> executable's path cannot be automatically determined, it can be explicitly set by adding the following line to <code>settings.php</code>:") . '</p>'; $output .= " <pre><code>\$config['package_manager.settings']['executables']['composer'] = '/full/path/to/composer.phar';</code></pre>"; $output .= ' </li>'; - $output .= ' <li>' . t('What if it says the detected version of Composer is not supported?'); - $output .= ' <p>' . t('The version of the <code>composer</code> executable must satisfy <code>@version</code>. See the <a href=":url">the Composer documentation</a> for more information, or use this command to update Composer:', [ + $output .= ' <li>' . $this->t('What if it says the detected version of Composer is not supported?'); + $output .= ' <p>' . $this->t('The version of the <code>composer</code> executable must satisfy <code>@version</code>. See the <a href=":url">the Composer documentation</a> for more information, or use this command to update Composer:', [ '@version' => ComposerInspector::SUPPORTED_VERSION, ':url' => 'https://getcomposer.org/doc/03-cli.md#self-update-selfupdate', ]) . '</p>'; $output .= ' <pre><code>composer self-update</code></pre>'; $output .= ' </li>'; - $output .= ' <li>' . t('What if it says the <code>composer validate</code> command failed?'); - $output .= ' <p>' . t('Composer detected problems with your <code>composer.json</code> and/or <code>composer.lock</code> files, and the project is not in a completely valid state. See <a href=":url">the Composer documentation</a> for more information.', [':url' => 'https://getcomposer.org/doc/04-schema.md']) . '</p>'; + $output .= ' <li>' . $this->t('What if it says the <code>composer validate</code> command failed?'); + $output .= ' <p>' . $this->t('Composer detected problems with your <code>composer.json</code> and/or <code>composer.lock</code> files, and the project is not in a completely valid state. See <a href=":url">the Composer documentation</a> for more information.', [':url' => 'https://getcomposer.org/doc/04-schema.md']) . '</p>'; $output .= ' </li>'; $output .= '</ul>'; - $output .= '<h4 id="package-manager-faq-rsync">' . t('Using rsync') . '</h4>'; - $output .= '<p>' . t('Package Manager must be able to run <code>rsync</code> to copy files between the live site and the stage directory. Package Manager will try to detect the path to <code>rsync</code>, but if it cannot be detected, you can set it explicitly by adding the following line to <code>settings.php</code>:') . '</p>'; + $output .= '<h4 id="package-manager-faq-rsync">' . $this->t('Using rsync') . '</h4>'; + $output .= '<p>' . $this->t('Package Manager must be able to run <code>rsync</code> to copy files between the live site and the stage directory. Package Manager will try to detect the path to <code>rsync</code>, but if it cannot be detected, you can set it explicitly by adding the following line to <code>settings.php</code>:') . '</p>'; $output .= "<pre><code>\$config['package_manager.settings']['executables']['rsync'] = '/full/path/to/rsync';</code></pre>"; - $output .= '<h4 id="package-manager-tuf-info">' . t('Enabling PHP-TUF protection') . '</h4>'; - $output .= '<p>' . t('Package Manager requires <a href=":php-tuf">PHP-TUF</a>, which implements <a href=":tuf">The Update Framework</a> as a way to help secure Composer package downloads via the <a href=":php-tuf-plugin">PHP-TUF Composer integration plugin</a>. This plugin must be installed and configured properly in order to use Package Manager.', [ + $output .= '<h4 id="package-manager-tuf-info">' . $this->t('Enabling PHP-TUF protection') . '</h4>'; + $output .= '<p>' . $this->t('Package Manager requires <a href=":php-tuf">PHP-TUF</a>, which implements <a href=":tuf">The Update Framework</a> as a way to help secure Composer package downloads via the <a href=":php-tuf-plugin">PHP-TUF Composer integration plugin</a>. This plugin must be installed and configured properly in order to use Package Manager.', [ ':php-tuf' => 'https://github.com/php-tuf/php-tuf', ':tuf' => 'https://theupdateframework.io/', ':php-tuf-plugin' => 'https://github.com/php-tuf/composer-integration', ]) . '</p>'; - $output .= '<p>' . t('To install and configure the plugin as needed, you can run the following commands:') . '</p>'; + $output .= '<p>' . $this->t('To install and configure the plugin as needed, you can run the following commands:') . '</p>'; $output .= '<pre><code>'; $output .= "composer config allow-plugins.php-tuf/composer-integration true\n"; $output .= "composer require php-tuf/composer-integration"; $output .= '</code></pre>'; - $output .= '<p>' . t('Package Manager currently requires the <code>https://packages.drupal.org/8</code> Composer repository to be protected by TUF. To set this up, run the following command:') . '</p>'; + $output .= '<p>' . $this->t('Package Manager currently requires the <code>https://packages.drupal.org/8</code> Composer repository to be protected by TUF. To set this up, run the following command:') . '</p>'; $output .= '<pre><code>'; $output .= "composer tuf:protect https://packages.drupal.org/8\n"; $output .= '</code></pre>'; - $output .= '<h4 id="package-manager-faq-unsupported-composer-plugin">' . t('What if it says I have unsupported Composer plugins in my codebase?') . '</h4>'; - $output .= '<p>' . t('A fresh Drupal installation only uses supported Composer plugins, but some modules or themes may depend on additional Composer plugins. <a href=":new-issue">Create a new issue</a> when you encounter this.', [':new-issue' => 'https://www.drupal.org/node/add/project-issue/auto_updates']) . '</p>'; - $output .= '<p>' . t('It is possible to <em>trust</em> additional Composer plugins, but this requires significant expertise: understanding the code of that Composer plugin, what the effects on the file system are and how it affects the Package Manager module. Some Composer plugins could result in a broken site!') . '</p>'; - $output .= '<h4 id="package-manager-faq-composer-patches-installed-or-removed">' . t('What if it says <code>cweagans/composer-patches</code> cannot be installed/removed?') . '</h4>'; - $output .= '<p>' . t('Installation or removal of <code>cweagans/composer-patches</code> via Package Manager is not supported. You can install or remove it manually by running Composer commands in your site root.') . '</p>'; - $output .= '<p>' . t('To install it:') . '</p>'; + $output .= '<h4 id="package-manager-faq-unsupported-composer-plugin">' . $this->t('What if it says I have unsupported Composer plugins in my codebase?') . '</h4>'; + $output .= '<p>' . $this->t('A fresh Drupal installation only uses supported Composer plugins, but some modules or themes may depend on additional Composer plugins. <a href=":new-issue">Create a new issue</a> when you encounter this.', [':new-issue' => 'https://www.drupal.org/node/add/project-issue/auto_updates']) . '</p>'; + $output .= '<p>' . $this->t('It is possible to <em>trust</em> additional Composer plugins, but this requires significant expertise: understanding the code of that Composer plugin, what the effects on the file system are and how it affects the Package Manager module. Some Composer plugins could result in a broken site!') . '</p>'; + $output .= '<h4 id="package-manager-faq-composer-patches-installed-or-removed">' . $this->t('What if it says <code>cweagans/composer-patches</code> cannot be installed/removed?') . '</h4>'; + $output .= '<p>' . $this->t('Installation or removal of <code>cweagans/composer-patches</code> via Package Manager is not supported. You can install or remove it manually by running Composer commands in your site root.') . '</p>'; + $output .= '<p>' . $this->t('To install it:') . '</p>'; $output .= '<pre><code>composer require cweagans/composer-patches</code></pre>'; - $output .= '<p>' . t('To remove it:') . '</p>'; + $output .= '<p>' . $this->t('To remove it:') . '</p>'; $output .= '<pre><code>composer remove cweagans/composer-patches</code></pre>'; - $output .= '<h4 id="package-manager-faq-composer-patches-not-a-root-dependency">' . t('What if it says <code>cweagans/composer-patches</code> must be a root dependency?') . '</h4>'; - $output .= '<p>' . t('If <code>cweagans/composer-patches</code> is installed, it must be defined as a dependency of the main project (i.e., it must be listed in the <code>require</code> or <code>require-dev</code> section of <code>composer.json</code>). You can run the following command in your site root to add it as a dependency of the main project:') . '</p>'; + $output .= '<h4 id="package-manager-faq-composer-patches-not-a-root-dependency">' . $this->t('What if it says <code>cweagans/composer-patches</code> must be a root dependency?') . '</h4>'; + $output .= '<p>' . $this->t('If <code>cweagans/composer-patches</code> is installed, it must be defined as a dependency of the main project (i.e., it must be listed in the <code>require</code> or <code>require-dev</code> section of <code>composer.json</code>). You can run the following command in your site root to add it as a dependency of the main project:') . '</p>'; $output .= "<pre><code>composer require cweagans/composer-patches</code></pre>"; return $output; } diff --git a/core/modules/page_cache/src/Hook/PageCacheHooks.php b/core/modules/page_cache/src/Hook/PageCacheHooks.php index b2b59bc6e13a4dbf0d3bf9535714784dd14dc638..ad4612b11e9e8e7864510ed5265686916f58708c 100644 --- a/core/modules/page_cache/src/Hook/PageCacheHooks.php +++ b/core/modules/page_cache/src/Hook/PageCacheHooks.php @@ -2,6 +2,7 @@ namespace Drupal\page_cache\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class PageCacheHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -18,22 +21,22 @@ class PageCacheHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.page_cache': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Internal Page Cache module caches pages for anonymous users in the database. For more information, see the <a href=":pagecache-documentation">online documentation for the Internal Page Cache module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Internal Page Cache module caches pages for anonymous users in the database. For more information, see the <a href=":pagecache-documentation">online documentation for the Internal Page Cache module</a>.', [ ':pagecache-documentation' => 'https://www.drupal.org/documentation/modules/internal_page_cache', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Speeding up your site') . '</dt>'; - $output .= '<dd>' . t('Pages requested by anonymous users are stored the first time they are requested and then are reused. Depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.') . '</dd>'; - $output .= '<dd>' . t('Pages are usually identical for all anonymous users, while they can be personalized for each authenticated user. This is why entire pages can be cached for anonymous users, whereas they will have to be rebuilt for every authenticated user.') . '</dd>'; - $output .= '<dd>' . t('To speed up your site for authenticated users, see the <a href=":dynamic_page_cache-help">Dynamic Page Cache module</a>.', [ + $output .= '<dt>' . $this->t('Speeding up your site') . '</dt>'; + $output .= '<dd>' . $this->t('Pages requested by anonymous users are stored the first time they are requested and then are reused. Depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.') . '</dd>'; + $output .= '<dd>' . $this->t('Pages are usually identical for all anonymous users, while they can be personalized for each authenticated user. This is why entire pages can be cached for anonymous users, whereas they will have to be rebuilt for every authenticated user.') . '</dd>'; + $output .= '<dd>' . $this->t('To speed up your site for authenticated users, see the <a href=":dynamic_page_cache-help">Dynamic Page Cache module</a>.', [ ':dynamic_page_cache-help' => \Drupal::moduleHandler()->moduleExists('dynamic_page_cache') ? Url::fromRoute('help.page', [ 'name' => 'dynamic_page_cache', ])->toString() : '#', ]) . '</p>'; - $output .= '<dt>' . t('Configuring the internal page cache') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":cache-settings">Performance page</a>, you can configure how long browsers and proxies may cache pages based on the Cache-Control header; this setting is ignored by the Internal Page Cache module, which caches pages permanently until invalidation, unless they carry an Expires header. There is no other configuration.', [ + $output .= '<dt>' . $this->t('Configuring the internal page cache') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":cache-settings">Performance page</a>, you can configure how long browsers and proxies may cache pages based on the Cache-Control header; this setting is ignored by the Internal Page Cache module, which caches pages permanently until invalidation, unless they carry an Expires header. There is no other configuration.', [ ':cache-settings' => Url::fromRoute('system.performance_settings')->toString(), ]) . '</dd>'; $output .= '</dl>'; diff --git a/core/modules/path/src/Hook/PathHooks.php b/core/modules/path/src/Hook/PathHooks.php index 9f913a6aff27b92845f1740d6489f169a0555ebe..ec9312749701b8a6a100f9190c5a148921df4ab4 100644 --- a/core/modules/path/src/Hook/PathHooks.php +++ b/core/modules/path/src/Hook/PathHooks.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\path\PathAliasListBuilder; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; use Drupal\Core\Entity\ContentEntityDeleteForm; @@ -20,6 +21,8 @@ */ class PathHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -28,32 +31,32 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.path': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL redirects, which allow you to forward a changed or inactive URL to a new URL. In addition to making URLs more readable, aliases also help search engines index content more effectively. Multiple aliases may be used for a single internal system path. To automate the aliasing of paths, you can install the contributed module <a href=":pathauto">Pathauto</a>. For more information, see the <a href=":path">online documentation for the Path module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Path module allows you to specify an alias, or custom URL, for any existing internal system path. Aliases should not be confused with URL redirects, which allow you to forward a changed or inactive URL to a new URL. In addition to making URLs more readable, aliases also help search engines index content more effectively. Multiple aliases may be used for a single internal system path. To automate the aliasing of paths, you can install the contributed module <a href=":pathauto">Pathauto</a>. For more information, see the <a href=":path">online documentation for the Path module</a>.', [ ':path' => 'https://www.drupal.org/documentation/modules/path', ':pathauto' => 'https://www.drupal.org/project/pathauto', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating aliases') . '</dt>'; - $output .= '<dd>' . t('If you create or edit a taxonomy term you can add an alias (for example <em>music/jazz</em>) in the field "URL alias". When creating or editing content you can add an alias (for example <em>about-us/team</em>) under the section "URL path settings" in the field "URL alias". Aliases for any other path can be added through the page <a href=":aliases">URL aliases</a>. To add aliases a user needs the permission <a href=":permissions">Create and edit URL aliases</a>.', [ + $output .= '<dt>' . $this->t('Creating aliases') . '</dt>'; + $output .= '<dd>' . $this->t('If you create or edit a taxonomy term you can add an alias (for example <em>music/jazz</em>) in the field "URL alias". When creating or editing content you can add an alias (for example <em>about-us/team</em>) under the section "URL path settings" in the field "URL alias". Aliases for any other path can be added through the page <a href=":aliases">URL aliases</a>. To add aliases a user needs the permission <a href=":permissions">Create and edit URL aliases</a>.', [ ':aliases' => Url::fromRoute('entity.path_alias.collection')->toString(), ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'path', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Managing aliases') . '</dt>'; - $output .= '<dd>' . t('The Path module provides a way to search and view a <a href=":aliases">list of all aliases</a> that are in use on your website. Aliases can be added, edited and deleted through this list.', [ + $output .= '<dt>' . $this->t('Managing aliases') . '</dt>'; + $output .= '<dd>' . $this->t('The Path module provides a way to search and view a <a href=":aliases">list of all aliases</a> that are in use on your website. Aliases can be added, edited and deleted through this list.', [ ':aliases' => Url::fromRoute('entity.path_alias.collection')->toString(), ]) . '</dd>'; $output .= '</dl>'; return $output; case 'entity.path_alias.collection': - return '<p>' . t("An alias defines a different name for an existing URL path - for example, the alias 'about' for the URL path 'node/1'. A URL path can have multiple aliases.") . '</p>'; + return '<p>' . $this->t("An alias defines a different name for an existing URL path - for example, the alias 'about' for the URL path 'node/1'. A URL path can have multiple aliases.") . '</p>'; case 'entity.path_alias.add_form': - return '<p>' . t('Enter the path you wish to create the alias for, followed by the name of the new alias.') . '</p>'; + return '<p>' . $this->t('Enter the path you wish to create the alias for, followed by the name of the new alias.') . '</p>'; } } @@ -102,7 +105,7 @@ public function entityBaseFieldInfoAlter(&$fields, EntityTypeInterface $entity_t #[Hook('entity_base_field_info')] public function entityBaseFieldInfo(EntityTypeInterface $entity_type): array { if (in_array($entity_type->id(), ['taxonomy_term', 'node', 'media'], TRUE)) { - $fields['path'] = BaseFieldDefinition::create('path')->setLabel(t('URL alias'))->setTranslatable(TRUE)->setDisplayOptions('form', ['type' => 'path', 'weight' => 30])->setDisplayConfigurable('form', TRUE)->setComputed(TRUE); + $fields['path'] = BaseFieldDefinition::create('path')->setLabel($this->t('URL alias'))->setTranslatable(TRUE)->setDisplayOptions('form', ['type' => 'path', 'weight' => 30])->setDisplayConfigurable('form', TRUE)->setComputed(TRUE); return $fields; } return []; @@ -137,15 +140,15 @@ public function fieldWidgetSingleElementFormAlter(&$element, FormStateInterface $element['value']['#field_prefix'] = \Drupal::service('router.request_context')->getCompleteBaseUrl(); } if ($field_name === 'langcode') { - $element['value']['#description'] = t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- Not specified -</em>.'); + $element['value']['#description'] = $this->t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- Not specified -</em>.'); $element['value']['#empty_value'] = LanguageInterface::LANGCODE_NOT_SPECIFIED; - $element['value']['#empty_option'] = t('- Not specified -'); + $element['value']['#empty_option'] = $this->t('- Not specified -'); } if ($field_name === 'path') { - $element['value']['#description'] = t('Specify the existing path you wish to alias. For example: /node/28, /media/1, /taxonomy/term/1.'); + $element['value']['#description'] = $this->t('Specify the existing path you wish to alias. For example: /node/28, /media/1, /taxonomy/term/1.'); } if ($field_name === 'alias') { - $element['value']['#description'] = t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'); + $element['value']['#description'] = $this->t('Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.'); } } } diff --git a/core/modules/pgsql/src/Hook/PgsqlHooks.php b/core/modules/pgsql/src/Hook/PgsqlHooks.php index 11fe1d0c2b6260bf089c5601881f0a8e9ea6ce62..d199f65f151690cfff34604acd0eb4fd63f59e22 100644 --- a/core/modules/pgsql/src/Hook/PgsqlHooks.php +++ b/core/modules/pgsql/src/Hook/PgsqlHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for pgsql. */ class PgsqlHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -18,8 +21,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.pgsql': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The PostgreSQL module provides the connection between Drupal and a PostgreSQL database. For more information, see the <a href=":pgsql">online documentation for the PostgreSQL module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The PostgreSQL module provides the connection between Drupal and a PostgreSQL database. For more information, see the <a href=":pgsql">online documentation for the PostgreSQL module</a>.', [ ':pgsql' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/postgresql-module', ]) . '</p>'; return $output; diff --git a/core/modules/phpass/src/Hook/PhpassHooks.php b/core/modules/phpass/src/Hook/PhpassHooks.php index 1420e4e7b4a559e21c433d8e09b6179f18556c56..422d623006cbe1a9bafc5ba0bdc86c42d965a382 100644 --- a/core/modules/phpass/src/Hook/PhpassHooks.php +++ b/core/modules/phpass/src/Hook/PhpassHooks.php @@ -5,12 +5,15 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for phpass. */ class PhpassHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,13 +22,13 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.phpass': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Password Compatibility module provides the password checking algorithm for user accounts created with Drupal prior to version 10.1.0. For more information, see the <a href=":phpass">online documentation for the Password Compatibility module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Password Compatibility module provides the password checking algorithm for user accounts created with Drupal prior to version 10.1.0. For more information, see the <a href=":phpass">online documentation for the Password Compatibility module</a>.', [ ':phpass' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/password-compatibility-module', ]) . '</p>'; - $output .= '<p>' . t('Drupal 10.1.0 and later use a different algorithm to compute the hashed password. This provides better security against brute-force attacks. The hashed passwords are different from the ones computed with Drupal versions before 10.1.0.') . '</p>'; - $output .= '<p>' . t('When the Password Compatibility module is installed, a user can log in with a username and password created before Drupal 10.1.0. The first time these credentials are used, a new hash is computed and saved. From then on, the user will be able to log in with the same username and password whether or not this module is installed.') . '</p>'; - $output .= '<p>' . t('Passwords created before Drupal 10.1.0 <strong>will not work</strong> unless they are used at least once while this module is installed. Make sure that you can log in before uninstalling this module.') . '</p>'; + $output .= '<p>' . $this->t('Drupal 10.1.0 and later use a different algorithm to compute the hashed password. This provides better security against brute-force attacks. The hashed passwords are different from the ones computed with Drupal versions before 10.1.0.') . '</p>'; + $output .= '<p>' . $this->t('When the Password Compatibility module is installed, a user can log in with a username and password created before Drupal 10.1.0. The first time these credentials are used, a new hash is computed and saved. From then on, the user will be able to log in with the same username and password whether or not this module is installed.') . '</p>'; + $output .= '<p>' . $this->t('Passwords created before Drupal 10.1.0 <strong>will not work</strong> unless they are used at least once while this module is installed. Make sure that you can log in before uninstalling this module.') . '</p>'; return $output; } } @@ -39,7 +42,7 @@ public function formSystemModulesUninstallConfirmFormAlter(array &$form, FormSta if (!in_array('phpass', $modules)) { return; } - \Drupal::messenger()->addWarning(t('Make sure that you can log in before uninstalling the Password Compatibility module. For more information, see the <a href=":phpass">online documentation for the Password Compatibility module</a>.', [ + \Drupal::messenger()->addWarning($this->t('Make sure that you can log in before uninstalling the Password Compatibility module. For more information, see the <a href=":phpass">online documentation for the Password Compatibility module</a>.', [ ':phpass' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/password-compatibility-module', ])); } diff --git a/core/modules/responsive_image/src/Hook/ResponsiveImageHooks.php b/core/modules/responsive_image/src/Hook/ResponsiveImageHooks.php index 3a437e03415285d180d46966540a59c2670bc054..c12d76e036d154b5c65bc2f3474c129fa26d1f16 100644 --- a/core/modules/responsive_image/src/Hook/ResponsiveImageHooks.php +++ b/core/modules/responsive_image/src/Hook/ResponsiveImageHooks.php @@ -2,6 +2,7 @@ namespace Drupal\responsive_image\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class ResponsiveImageHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,39 +22,39 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.responsive_image': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Responsive Image module provides an image formatter that allows browsers to select which image file to display based on media queries or which image file types the browser supports, using the HTML 5 picture and source elements and/or the sizes, srcset and type attributes. For more information, see the <a href=":responsive_image">online documentation for the Responsive Image module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Responsive Image module provides an image formatter that allows browsers to select which image file to display based on media queries or which image file types the browser supports, using the HTML 5 picture and source elements and/or the sizes, srcset and type attributes. For more information, see the <a href=":responsive_image">online documentation for the Responsive Image module</a>.', [ ':responsive_image' => 'https://www.drupal.org/documentation/modules/responsive_image', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Defining responsive image styles') . '</dt>'; - $output .= '<dd>' . t('By creating responsive image styles you define which options the browser has in selecting which image file to display. In most cases this means providing different image sizes based on the viewport size. On the <a href=":responsive_image_style">Responsive image styles</a> page, click <em>Add responsive image style</em> to create a new style. First choose a label, a fallback image style and a breakpoint group and click Save.', [ + $output .= '<dt>' . $this->t('Defining responsive image styles') . '</dt>'; + $output .= '<dd>' . $this->t('By creating responsive image styles you define which options the browser has in selecting which image file to display. In most cases this means providing different image sizes based on the viewport size. On the <a href=":responsive_image_style">Responsive image styles</a> page, click <em>Add responsive image style</em> to create a new style. First choose a label, a fallback image style and a breakpoint group and click Save.', [ ':responsive_image_style' => Url::fromRoute('entity.responsive_image_style.collection')->toString(), ]) . '</dd>'; $output .= '<dl>'; - $output .= '<dt>' . t('Fallback image style') . '</dt>'; - $output .= '<dd>' . t('The fallback image style is typically the smallest size image you expect to appear in this space. The fallback image should only appear on a site if an error occurs.') . '</dd>'; - $output .= '<dt>' . t('Breakpoint groups: viewport sizing vs art direction') . '</dt>'; - $output .= '<dd>' . t('The breakpoint group typically only needs a single breakpoint with an empty media query in order to do <em>viewport sizing.</em> Multiple breakpoints are used for changing the crop or aspect ratio of images at different viewport sizes, which is often referred to as <em>art direction.</em> A new breakpoint group should be created for each aspect ratio to avoid content shift. Once you select a breakpoint group, you can choose which breakpoints to use for the responsive image style. By default, the option <em>do not use this breakpoint</em> is selected for each breakpoint. See the <a href=":breakpoint_help">help page of the Breakpoint module</a> for more information.', [ + $output .= '<dt>' . $this->t('Fallback image style') . '</dt>'; + $output .= '<dd>' . $this->t('The fallback image style is typically the smallest size image you expect to appear in this space. The fallback image should only appear on a site if an error occurs.') . '</dd>'; + $output .= '<dt>' . $this->t('Breakpoint groups: viewport sizing vs art direction') . '</dt>'; + $output .= '<dd>' . $this->t('The breakpoint group typically only needs a single breakpoint with an empty media query in order to do <em>viewport sizing.</em> Multiple breakpoints are used for changing the crop or aspect ratio of images at different viewport sizes, which is often referred to as <em>art direction.</em> A new breakpoint group should be created for each aspect ratio to avoid content shift. Once you select a breakpoint group, you can choose which breakpoints to use for the responsive image style. By default, the option <em>do not use this breakpoint</em> is selected for each breakpoint. See the <a href=":breakpoint_help">help page of the Breakpoint module</a> for more information.', [ ':breakpoint_help' => Url::fromRoute('help.page', [ 'name' => 'breakpoint', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Breakpoint settings: sizes vs image styles') . '</dt>'; - $output .= '<dd>' . t('While you have the option to provide only one image style per breakpoint, the sizes attribute allows you to provide more options to browsers as to which image file it can display. If using sizes field and art direction, all selected image styles should use the same aspect ratio to avoid content shifting. Breakpoints are defined in the configuration files of the theme.') . '</dd>'; - $output .= '<dt>' . t('Sizes field') . '</dt>'; - $output .= '<dd>' . t('The sizes attribute paired with the srcset attribute provides information on how much space these images take up within the viewport at different browser breakpoints, but the aspect ratios should remain the same across those breakpoints. Once the sizes option is selected, you can let the browser know the size of this image in relation to the site layout, using the <em>Sizes</em> field. For a hero image that always fills the entire screen, you could simply enter 100vw, which means 100% of the viewport width. For an image that fills 90% of the screen for small viewports, but only fills 40% of the screen when the viewport is larger than 40em (typically 640px), you could enter "(min-width: 40em) 40vw, 90vw" in the Sizes field. The last item in the comma-separated list is the smallest viewport size: other items in the comma-separated list should have a media condition paired with an image width. <em>Media conditions</em> are similar to a media query, often a min-width paired with a viewport width using em or px units: e.g. (min-width: 640px) or (min-width: 40em). This is paired with the <em>image width</em> at that viewport size using px, em or vw units. The vw unit is viewport width and is used instead of a percentage because the percentage always refers to the width of the entire viewport.') . '</dd>'; - $output .= '<dt>' . t('Image styles for sizes') . '</dt>'; - $output .= '<dd>' . t('Below the Sizes field you can choose multiple image styles so the browser can choose the best image file size to fill the space defined in the Sizes field. Typically you will want to use image styles that resize your image to have options that range from the smallest px width possible for the space the image will appear in to the largest px width possible, with a variety of widths in between. You may want to provide image styles with widths that are 1.5x to 2x the space available in the layout to account for high resolution screens. Image styles can be defined on the <a href=":image_styles">Image styles page</a> that is provided by the <a href=":image_help">Image module</a>.', [ + $output .= '<dt>' . $this->t('Breakpoint settings: sizes vs image styles') . '</dt>'; + $output .= '<dd>' . $this->t('While you have the option to provide only one image style per breakpoint, the sizes attribute allows you to provide more options to browsers as to which image file it can display. If using sizes field and art direction, all selected image styles should use the same aspect ratio to avoid content shifting. Breakpoints are defined in the configuration files of the theme.') . '</dd>'; + $output .= '<dt>' . $this->t('Sizes field') . '</dt>'; + $output .= '<dd>' . $this->t('The sizes attribute paired with the srcset attribute provides information on how much space these images take up within the viewport at different browser breakpoints, but the aspect ratios should remain the same across those breakpoints. Once the sizes option is selected, you can let the browser know the size of this image in relation to the site layout, using the <em>Sizes</em> field. For a hero image that always fills the entire screen, you could simply enter 100vw, which means 100% of the viewport width. For an image that fills 90% of the screen for small viewports, but only fills 40% of the screen when the viewport is larger than 40em (typically 640px), you could enter "(min-width: 40em) 40vw, 90vw" in the Sizes field. The last item in the comma-separated list is the smallest viewport size: other items in the comma-separated list should have a media condition paired with an image width. <em>Media conditions</em> are similar to a media query, often a min-width paired with a viewport width using em or px units: e.g. (min-width: 640px) or (min-width: 40em). This is paired with the <em>image width</em> at that viewport size using px, em or vw units. The vw unit is viewport width and is used instead of a percentage because the percentage always refers to the width of the entire viewport.') . '</dd>'; + $output .= '<dt>' . $this->t('Image styles for sizes') . '</dt>'; + $output .= '<dd>' . $this->t('Below the Sizes field you can choose multiple image styles so the browser can choose the best image file size to fill the space defined in the Sizes field. Typically you will want to use image styles that resize your image to have options that range from the smallest px width possible for the space the image will appear in to the largest px width possible, with a variety of widths in between. You may want to provide image styles with widths that are 1.5x to 2x the space available in the layout to account for high resolution screens. Image styles can be defined on the <a href=":image_styles">Image styles page</a> that is provided by the <a href=":image_help">Image module</a>.', [ ':image_styles' => Url::fromRoute('entity.image_style.collection')->toString(), ':image_help' => Url::fromRoute('help.page', [ 'name' => 'image', ])->toString(), ]) . '</dd>'; $output .= '</dl></dd>'; - $output .= '<dt>' . t('Using responsive image styles in Image fields') . '</dt>'; - $output .= '<dd>' . t('After defining responsive image styles, you can use them in the display settings for your Image fields, so that the site displays responsive images using the HTML5 picture tag. Open the Manage display page for the entity type (content type, taxonomy vocabulary, etc.) that the Image field is attached to. Choose the format <em>Responsive image</em>, click the Edit icon, and select one of the responsive image styles that you have created. For general information on how to manage fields and their display see the <a href=":field_ui">Field UI module help page</a>. For background information about entities and fields see the <a href=":field_help">Field module help page</a>.', [ + $output .= '<dt>' . $this->t('Using responsive image styles in Image fields') . '</dt>'; + $output .= '<dd>' . $this->t('After defining responsive image styles, you can use them in the display settings for your Image fields, so that the site displays responsive images using the HTML5 picture tag. Open the Manage display page for the entity type (content type, taxonomy vocabulary, etc.) that the Image field is attached to. Choose the format <em>Responsive image</em>, click the Edit icon, and select one of the responsive image styles that you have created. For general information on how to manage fields and their display see the <a href=":field_ui">Field UI module help page</a>. For background information about entities and fields see the <a href=":field_help">Field module help page</a>.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', @@ -63,7 +66,7 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.responsive_image_style.collection': - return '<p>' . t('A responsive image style associates an image style with each breakpoint defined by your theme.') . '</p>'; + return '<p>' . $this->t('A responsive image style associates an image style with each breakpoint defined by your theme.') . '</p>'; } } diff --git a/core/modules/rest/src/Hook/RestHooks.php b/core/modules/rest/src/Hook/RestHooks.php index e4dc99d9d604c00eeb73028541235a0790ec3e0b..b5d5d4add5d2747470d59e587fd4294a3b4dd632 100644 --- a/core/modules/rest/src/Hook/RestHooks.php +++ b/core/modules/rest/src/Hook/RestHooks.php @@ -2,6 +2,7 @@ namespace Drupal\rest\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class RestHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,17 +22,17 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.rest': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The RESTful Web Services module provides a framework for exposing REST resources on your site. It provides support for content entity types such as the main site content, comments, content blocks, taxonomy terms, and user accounts, etc. (see the <a href=":field">Field module help page</a> for more information about entities). REST support for content items of the Node module is installed by default, and support for other types of content entities can be enabled. Other modules may add support for other types of REST resources. For more information, see the <a href=":rest">online documentation for the RESTful Web Services module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The RESTful Web Services module provides a framework for exposing REST resources on your site. It provides support for content entity types such as the main site content, comments, content blocks, taxonomy terms, and user accounts, etc. (see the <a href=":field">Field module help page</a> for more information about entities). REST support for content items of the Node module is installed by default, and support for other types of content entities can be enabled. Other modules may add support for other types of REST resources. For more information, see the <a href=":rest">online documentation for the RESTful Web Services module</a>.', [ ':rest' => 'https://www.drupal.org/documentation/modules/rest', ':field' => \Drupal::moduleHandler()->moduleExists('field') ? Url::fromRoute('help.page', [ 'name' => 'field', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Installing supporting modules') . '</dt>'; - $output .= '<dd>' . t('In order to use REST on a website, you need to install modules that provide serialization and authentication services. You can use the Core module <a href=":serialization">serialization</a> for serialization and <a href=":basic_auth">HTTP Basic Authentication</a> for authentication, or install a contributed or custom module.', [ + $output .= '<dt>' . $this->t('Installing supporting modules') . '</dt>'; + $output .= '<dd>' . $this->t('In order to use REST on a website, you need to install modules that provide serialization and authentication services. You can use the Core module <a href=":serialization">serialization</a> for serialization and <a href=":basic_auth">HTTP Basic Authentication</a> for authentication, or install a contributed or custom module.', [ ':serialization' => \Drupal::moduleHandler()->moduleExists('serialization') ? Url::fromRoute('help.page', [ 'name' => 'serialization', ])->toString() : 'https://www.drupal.org/docs/8/core/modules/serialization/overview', @@ -37,17 +40,17 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'basic_auth', ])->toString() : 'https://www.drupal.org/docs/8/core/modules/basic_auth/overview', ]) . '</dd>'; - $output .= '<dt>' . t('Enabling REST support for an entity type') . '</dt>'; - $output .= '<dd>' . t('REST support for content types (provided by the <a href=":node">Node</a> module) is enabled by default. To enable support for other content entity types, you can use a <a href=":config" target="blank">process based on configuration editing</a> or the contributed <a href=":restui">REST UI module</a>.', [ + $output .= '<dt>' . $this->t('Enabling REST support for an entity type') . '</dt>'; + $output .= '<dd>' . $this->t('REST support for content types (provided by the <a href=":node">Node</a> module) is enabled by default. To enable support for other content entity types, you can use a <a href=":config" target="blank">process based on configuration editing</a> or the contributed <a href=":restui">REST UI module</a>.', [ ':node' => \Drupal::moduleHandler()->moduleExists('node') ? Url::fromRoute('help.page', [ 'name' => 'node', ])->toString() : '#', ':config' => 'https://www.drupal.org/documentation/modules/rest', ':restui' => 'https://www.drupal.org/project/restui', ]) . '</dd>'; - $output .= '<dd>' . t('You will also need to grant anonymous users permission to perform each of the REST operations you want to be available, and set up authentication properly to authorize web requests.') . '</dd>'; - $output .= '<dt>' . t('General') . '</dt>'; - $output .= '<dd>' . t('The <a href=":rest-docs">RESTful Web Services</a> and <a href=":jsonapi-docs">JSON:API</a> modules serve similar purposes. <a href=":comparison">Read the comparison of the RESTFul Web Services and JSON:API modules</a> to determine the best choice for your site.', [ + $output .= '<dd>' . $this->t('You will also need to grant anonymous users permission to perform each of the REST operations you want to be available, and set up authentication properly to authorize web requests.') . '</dd>'; + $output .= '<dt>' . $this->t('General') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":rest-docs">RESTful Web Services</a> and <a href=":jsonapi-docs">JSON:API</a> modules serve similar purposes. <a href=":comparison">Read the comparison of the RESTFul Web Services and JSON:API modules</a> to determine the best choice for your site.', [ ':rest-docs' => 'https://www.drupal.org/docs/8/core/modules/rest', ':jsonapi-docs' => 'https://www.drupal.org/docs/8/modules/json-api', ':comparison' => 'https://www.drupal.org/docs/8/modules/jsonapi/jsonapi-vs-cores-rest-module', diff --git a/core/modules/search/src/Hook/SearchHooks.php b/core/modules/search/src/Hook/SearchHooks.php index 1e87c3140d3566dc659c8e562a0b80770d225a5b..47b51209ddef28e21e7453593be97d30b34aa5bc 100644 --- a/core/modules/search/src/Hook/SearchHooks.php +++ b/core/modules/search/src/Hook/SearchHooks.php @@ -4,6 +4,7 @@ use Drupal\block\BlockInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -13,6 +14,8 @@ */ class SearchHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -21,32 +24,32 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.search': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', [':search-module' => 'https://www.drupal.org/documentation/modules/search']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Search module provides the ability to set up search pages based on plugins provided by other modules. In Drupal core, there are two page-type plugins: the Content page type provides keyword searching for content managed by the Node module, and the Users page type provides keyword searching for registered users. Contributed modules may provide other page-type plugins. For more information, see the <a href=":search-module">online documentation for the Search module</a>.', [':search-module' => 'https://www.drupal.org/documentation/modules/search']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Configuring search pages') . '</dt>'; - $output .= '<dd>' . t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [ + $output .= '<dt>' . $this->t('Configuring search pages') . '</dt>'; + $output .= '<dd>' . $this->t('To configure search pages, visit the <a href=":search-settings">Search pages page</a>. In the Search pages section, you can add a new search page, edit the configuration of existing search pages, enable and disable search pages, and choose the default search page. Each enabled search page has a URL path starting with <em>search</em>, and each will appear as a tab or local task link on the <a href=":search-url">search page</a>; you can configure the text that is shown in the tab. In addition, some search page plugins have additional settings that you can configure for each search page.', [ ':search-settings' => Url::fromRoute('entity.search_page.collection')->toString(), ':search-url' => Url::fromRoute('search.view')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Managing the search index') . '</dt>'; - $output .= '<dd>' . t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', [ + $output .= '<dt>' . $this->t('Managing the search index') . '</dt>'; + $output .= '<dd>' . $this->t('Some search page plugins, such as the core Content search page, index searchable text using the Drupal core search index, and will not work unless content is indexed. Indexing is done during <em>cron</em> runs, so it requires a <a href=":cron">cron maintenance task</a> to be set up. There are also several settings affecting indexing that can be configured on the <a href=":search-settings">Search pages page</a>: the number of items to index per cron run, the minimum word length to index, and how to handle Chinese, Japanese, and Korean characters.', [ ':cron' => Url::fromRoute('system.cron_settings')->toString(), ':search-settings' => Url::fromRoute('entity.search_page.collection')->toString(), ]) . '</dd>'; - $output .= '<dd>' . t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, installing or uninstalling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', [ + $output .= '<dd>' . $this->t('Modules providing search page plugins generally ensure that content-related actions on your site (creating, editing, or deleting content and comments) automatically cause affected content items to be marked for indexing or reindexing at the next cron run. When content is marked for reindexing, the previous content remains in the index until cron runs, at which time it is replaced by the new content. However, there are some actions related to the structure of your site that do not cause affected content to be marked for reindexing. Examples of structure-related actions that affect content include deleting or editing taxonomy terms, installing or uninstalling modules that add text to content (such as Taxonomy, Comment, and field-providing modules), and modifying the fields or display parameters of your content types. If you take one of these actions and you want to ensure that the search index is updated to reflect your changed site structure, you can mark all content for reindexing by clicking the "Re-index site" button on the <a href=":search-settings">Search pages page</a>. If you have a lot of content on your site, it may take several cron runs for the content to be reindexed.', [ ':search-settings' => Url::fromRoute('entity.search_page.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Displaying the Search block') . '</dt>'; - $output .= '<dd>' . t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module installed; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', [ + $output .= '<dt>' . $this->t('Displaying the Search block') . '</dt>'; + $output .= '<dd>' . $this->t('The Search module includes a block, which can be enabled and configured on the <a href=":blocks">Block layout page</a>, if you have the Block module installed; the default block title is Search, and it is the Search form block in the Forms category, if you wish to add another instance. The block is available to users with the <a href=":search_permission">Use search</a> permission, and it performs a search using the configured default search page.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ':search_permission' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'search', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Searching your site') . '</dt>'; - $output .= '<dd>' . t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', [ + $output .= '<dt>' . $this->t('Searching your site') . '</dt>'; + $output .= '<dd>' . $this->t('Users with <a href=":search_permission">Use search</a> permission can use the Search block and <a href=":search">Search page</a>. Users with the <a href=":node_permission">View published content</a> permission can use configured search pages of type <em>Content</em> to search for content containing exact keywords; in addition, users with <a href=":search_permission">Use advanced search</a> permission can use more complex search filtering. Users with the <a href=":user_permission">View user information</a> permission can use configured search pages of type <em>Users</em> to search for active users containing the keyword anywhere in the username, and users with the <a href=":user_permission">Administer users</a> permission can search for active and blocked users, by email address or username keyword.', [ ':search' => Url::fromRoute('search.view')->toString(), ':search_permission' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'search', @@ -58,8 +61,8 @@ public function help($route_name, RouteMatchInterface $route_match) { 'modules' => 'user', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Extending the Search module') . '</dt>'; - $output .= '<dd>' . t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', [ + $output .= '<dt>' . $this->t('Extending the Search module') . '</dt>'; + $output .= '<dd>' . $this->t('By default, the Search module only supports exact keyword matching in content searches. You can modify this behavior by installing a language-specific stemming module for your language (such as <a href=":porterstemmer_url">Porter Stemmer</a> for American English), which allows words such as walk, walking, and walked to be matched in the Search module. Another approach is to use a third-party search technology with stemming or partial word matching features built in, such as <a href=":solr_url">Apache Solr</a> or <a href=":sphinx_url">Sphinx</a>. There are also contributed modules that provide additional search pages. These and other <a href=":contrib-search">search-related contributed modules</a> can be downloaded by visiting Drupal.org.', [ ':contrib-search' => 'https://www.drupal.org/project/project_module?f[2]=im_vid_3%3A105', ':porterstemmer_url' => 'https://www.drupal.org/project/porterstemmer', ':solr_url' => 'https://www.drupal.org/project/apachesolr', diff --git a/core/modules/serialization/src/Hook/SerializationHooks.php b/core/modules/serialization/src/Hook/SerializationHooks.php index e2d6b36244f90d35f9b175a8347e684fd4b66f65..00ffa7913c5fa94474e5c955f600bb07390d453a 100644 --- a/core/modules/serialization/src/Hook/SerializationHooks.php +++ b/core/modules/serialization/src/Hook/SerializationHooks.php @@ -2,6 +2,7 @@ namespace Drupal\serialization\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class SerializationHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,16 +22,16 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.serialization': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Serialization module provides a service for serializing and deserializing data to and from formats such as JSON and XML.') . '</p>'; - $output .= '<p>' . t('Serialization is the process of converting data structures like arrays and objects into a string. This allows the data to be represented in a way that is easy to exchange and store (for example, for transmission over the Internet or for storage in a local file system). These representations can then be deserialized to get back to the original data structures.') . '</p>'; - $output .= '<p>' . t('The serializer splits this process into two parts. Normalization converts an object to a normalized array structure. Encoding takes that array and converts it to a string.') . '</p>'; - $output .= '<p>' . t('This module does not have a user interface. It is used by other modules which need to serialize data, such as <a href=":rest">REST</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Serialization module provides a service for serializing and deserializing data to and from formats such as JSON and XML.') . '</p>'; + $output .= '<p>' . $this->t('Serialization is the process of converting data structures like arrays and objects into a string. This allows the data to be represented in a way that is easy to exchange and store (for example, for transmission over the Internet or for storage in a local file system). These representations can then be deserialized to get back to the original data structures.') . '</p>'; + $output .= '<p>' . $this->t('The serializer splits this process into two parts. Normalization converts an object to a normalized array structure. Encoding takes that array and converts it to a string.') . '</p>'; + $output .= '<p>' . $this->t('This module does not have a user interface. It is used by other modules which need to serialize data, such as <a href=":rest">REST</a>.', [ ':rest' => \Drupal::moduleHandler()->moduleExists('rest') ? Url::fromRoute('help.page', [ 'name' => 'rest', ])->toString() : '#', ]) . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":doc_url">online documentation for the Serialization module</a>.', [':doc_url' => 'https://www.drupal.org/documentation/modules/serialization']) . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":doc_url">online documentation for the Serialization module</a>.', [':doc_url' => 'https://www.drupal.org/documentation/modules/serialization']) . '</p>'; return $output; } } diff --git a/core/modules/settings_tray/src/Hook/SettingsTrayHooks.php b/core/modules/settings_tray/src/Hook/SettingsTrayHooks.php index 014999107c6374d08e4a951f91b90f31236ad51e..c10a65d0f03997dc4addd71cb3d18e10774af2f6 100644 --- a/core/modules/settings_tray/src/Hook/SettingsTrayHooks.php +++ b/core/modules/settings_tray/src/Hook/SettingsTrayHooks.php @@ -4,6 +4,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Asset\AttachedAssetsInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\settings_tray\Block\BlockEntitySettingTrayForm; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -14,6 +15,8 @@ */ class SettingsTrayHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -21,8 +24,8 @@ class SettingsTrayHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.settings_tray': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Settings Tray module allows users with the <a href=":administer_block_permission">Administer blocks</a> and <a href=":contextual_permission">Use contextual links</a> permissions to edit blocks without visiting a separate page. For more information, see the <a href=":handbook_url">online documentation for the Settings Tray module</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Settings Tray module allows users with the <a href=":administer_block_permission">Administer blocks</a> and <a href=":contextual_permission">Use contextual links</a> permissions to edit blocks without visiting a separate page. For more information, see the <a href=":handbook_url">online documentation for the Settings Tray module</a>.', [ ':handbook_url' => 'https://www.drupal.org/documentation/modules/settings_tray', ':administer_block_permission' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'block', @@ -31,17 +34,17 @@ public function help($route_name, RouteMatchInterface $route_match) { 'modules' => 'contextual', ])->toString(), ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Editing blocks in place') . '</dt>'; + $output .= '<dt>' . $this->t('Editing blocks in place') . '</dt>'; $output .= '<dd>'; - $output .= '<p>' . t('To edit blocks in place, either click the <strong>Edit</strong> button in the toolbar and then click on the block, or choose "Quick edit" from the block\'s contextual link. (See the <a href=":contextual">Contextual Links module help</a> for more information about how to use contextual links.)', [ + $output .= '<p>' . $this->t('To edit blocks in place, either click the <strong>Edit</strong> button in the toolbar and then click on the block, or choose "Quick edit" from the block\'s contextual link. (See the <a href=":contextual">Contextual Links module help</a> for more information about how to use contextual links.)', [ ':contextual' => Url::fromRoute('help.page', [ 'name' => 'contextual', ])->toString(), ]) . '</p>'; - $output .= '<p>' . t('The Settings Tray for the block will open in a sidebar, with a compact form for configuring what the block shows.') . '</p>'; - $output .= '<p>' . t('Save the form and the changes will be immediately visible on the page.') . '</p>'; + $output .= '<p>' . $this->t('The Settings Tray for the block will open in a sidebar, with a compact form for configuring what the block shows.') . '</p>'; + $output .= '<p>' . $this->t('Save the form and the changes will be immediately visible on the page.') . '</p>'; $output .= '</dd>'; $output .= '</dl>'; return ['#markup' => $output]; @@ -62,7 +65,7 @@ public function contextualLinksViewAlter(&$element, $items): void { $element['#links'] = ['settings-trayblock-configure' => $settings_tray_link] + $element['#links']; // If this is content block change title to avoid duplicate "Quick Edit". if (isset($element['#links']['block-contentblock-edit'])) { - $element['#links']['settings-trayblock-configure']['title'] = t('Quick edit settings'); + $element['#links']['settings-trayblock-configure']['title'] = $this->t('Quick edit settings'); } $element['#attached']['library'][] = 'core/drupal.dialog.off_canvas'; } diff --git a/core/modules/shortcut/src/Hook/ShortcutHooks.php b/core/modules/shortcut/src/Hook/ShortcutHooks.php index 9dd73cb3ce423ba82333e6238487ec3f05104c35..d751d6dc3648dbc2d3bbdae59c4b9c679eb6b469 100644 --- a/core/modules/shortcut/src/Hook/ShortcutHooks.php +++ b/core/modules/shortcut/src/Hook/ShortcutHooks.php @@ -3,6 +3,7 @@ namespace Drupal\shortcut\Hook; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class ShortcutHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,19 +22,19 @@ class ShortcutHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.shortcut': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>. Each user with <em>Select any shortcut set</em> permission can select a shortcut set created by anyone at the site. For more information, see the <a href=":shortcut">online documentation for the Shortcut module</a>.', [':shortcut' => 'https://www.drupal.org/docs/8/core/modules/shortcut']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; - $output .= '<dl><dt>' . t('Administering shortcuts') . '</dt>'; - $output .= '<dd>' . t('Users with the <em>Administer shortcuts</em> permission can manage shortcut sets and edit the shortcuts within sets from the <a href=":shortcuts">Shortcuts administration page</a>.', [ + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Shortcut module allows users to create sets of <em>shortcut</em> links to commonly-visited pages of the site. Shortcuts are contained within <em>sets</em>. Each user with <em>Select any shortcut set</em> permission can select a shortcut set created by anyone at the site. For more information, see the <a href=":shortcut">online documentation for the Shortcut module</a>.', [':shortcut' => 'https://www.drupal.org/docs/8/core/modules/shortcut']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; + $output .= '<dl><dt>' . $this->t('Administering shortcuts') . '</dt>'; + $output .= '<dd>' . $this->t('Users with the <em>Administer shortcuts</em> permission can manage shortcut sets and edit the shortcuts within sets from the <a href=":shortcuts">Shortcuts administration page</a>.', [ ':shortcuts' => Url::fromRoute('entity.shortcut_set.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Choosing shortcut sets') . '</dt>'; - $output .= '<dd>' . t('Users with permission to switch shortcut sets can choose a shortcut set to use from the Shortcuts tab of their user account page.') . '</dd>'; - $output .= '<dt>' . t('Adding and removing shortcuts') . '</dt>'; - $output .= '<dd>' . t('The Shortcut module creates an add/remove link for each page on your site; the link lets you add or remove the current page from the currently-enabled set of shortcuts (if your theme displays it and you have permission to edit your shortcut set). The core Claro administration theme displays this link next to the page title, as a gray or yellow star. If you click on the gray star, you will add that page to your preferred set of shortcuts. If the page is already part of your shortcut set, the link will be a yellow star, and will allow you to remove the current page from your shortcut set.') . '</dd>'; - $output .= '<dt>' . t('Displaying shortcuts') . '</dt>'; - $output .= '<dd>' . t('You can display your shortcuts by enabling the <em>Shortcuts</em> block on the <a href=":blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href=":toolbar-help">Toolbar module</a> provides a corresponding menu link.', [ + $output .= '<dt>' . $this->t('Choosing shortcut sets') . '</dt>'; + $output .= '<dd>' . $this->t('Users with permission to switch shortcut sets can choose a shortcut set to use from the Shortcuts tab of their user account page.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding and removing shortcuts') . '</dt>'; + $output .= '<dd>' . $this->t('The Shortcut module creates an add/remove link for each page on your site; the link lets you add or remove the current page from the currently-enabled set of shortcuts (if your theme displays it and you have permission to edit your shortcut set). The core Claro administration theme displays this link next to the page title, as a gray or yellow star. If you click on the gray star, you will add that page to your preferred set of shortcuts. If the page is already part of your shortcut set, the link will be a yellow star, and will allow you to remove the current page from your shortcut set.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying shortcuts') . '</dt>'; + $output .= '<dd>' . $this->t('You can display your shortcuts by enabling the <em>Shortcuts</em> block on the <a href=":blocks">Blocks administration page</a>. Certain administrative modules also display your shortcuts; for example, the core <a href=":toolbar-help">Toolbar module</a> provides a corresponding menu link.', [ ':blocks' => \Drupal::moduleHandler()->moduleExists('block') ? Url::fromRoute('block.admin_display')->toString() : '#', ':toolbar-help' => \Drupal::moduleHandler()->moduleExists('toolbar') ? Url::fromRoute('help.page', [ 'name' => 'toolbar', @@ -45,7 +48,7 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'entity.shortcut_set.edit_form': $user = \Drupal::currentUser(); if ($user->hasPermission('access shortcuts') && $user->hasPermission('switch shortcut sets')) { - $output = '<p>' . t('Define which shortcut set you are using on the <a href=":shortcut-link">Shortcuts tab</a> of your account page.', [ + $output = '<p>' . $this->t('Define which shortcut set you are using on the <a href=":shortcut-link">Shortcuts tab</a> of your account page.', [ ':shortcut-link' => Url::fromRoute('shortcut.set_switch', [ 'user' => $user->id(), ])->toString(), @@ -69,10 +72,10 @@ public function toolbar(): array { '#type' => 'toolbar_item', 'tab' => [ '#type' => 'link', - '#title' => t('Shortcuts'), + '#title' => $this->t('Shortcuts'), '#url' => $shortcut_set->toUrl('collection'), '#attributes' => [ - 'title' => t('Shortcuts'), + 'title' => $this->t('Shortcuts'), 'class' => [ 'toolbar-icon', 'toolbar-icon-shortcut', @@ -80,7 +83,7 @@ public function toolbar(): array { ], ], 'tray' => [ - '#heading' => t('User-defined shortcuts'), + '#heading' => $this->t('User-defined shortcuts'), 'children' => [ '#lazy_builder' => [ 'shortcut.lazy_builders:lazyLinks', diff --git a/core/modules/sqlite/src/Hook/SqliteHooks.php b/core/modules/sqlite/src/Hook/SqliteHooks.php index d0a6e384fcb4cd0a9b898afacbd9d90e315d5880..f6fe55aa3d7882aff311a9b6222ce9bc241fd565 100644 --- a/core/modules/sqlite/src/Hook/SqliteHooks.php +++ b/core/modules/sqlite/src/Hook/SqliteHooks.php @@ -4,12 +4,15 @@ use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for sqlite. */ class SqliteHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -18,8 +21,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.sqlite': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The SQLite module provides the connection between Drupal and a SQLite database. For more information, see the <a href=":sqlite">online documentation for the SQLite module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The SQLite module provides the connection between Drupal and a SQLite database. For more information, see the <a href=":sqlite">online documentation for the SQLite module</a>.', [ ':sqlite' => 'https://www.drupal.org/docs/core-modules-and-themes/core-modules/sqlite-module', ]) . '</p>'; return $output; diff --git a/core/modules/syslog/src/Hook/SyslogHooks.php b/core/modules/syslog/src/Hook/SyslogHooks.php index 6862392d5a489277f24ae012ba8c69542ce1908a..4b45feec66b1e6c363c86c948b566cc263599332 100644 --- a/core/modules/syslog/src/Hook/SyslogHooks.php +++ b/core/modules/syslog/src/Hook/SyslogHooks.php @@ -2,6 +2,7 @@ namespace Drupal\syslog\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Link; use Drupal\Core\Form\FormStateInterface; @@ -13,6 +14,8 @@ */ class SyslogHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -21,14 +24,14 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.syslog': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Syslog module logs events by sending messages to the logging facility of your web server\'s operating system. Syslog is an operating system administrative logging tool that provides valuable information for use in system management and security auditing. Most suited to medium and large sites, Syslog provides filtering tools that allow messages to be routed by type and severity. For more information, see the <a href=":syslog">online documentation for the Syslog module</a>, as well as PHP\'s documentation pages for the <a href="http://php.net/manual/function.openlog.php">openlog</a> and <a href="http://php.net/manual/function.syslog.php">syslog</a> functions.', [':syslog' => 'https://www.drupal.org/documentation/modules/syslog']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Syslog module logs events by sending messages to the logging facility of your web server\'s operating system. Syslog is an operating system administrative logging tool that provides valuable information for use in system management and security auditing. Most suited to medium and large sites, Syslog provides filtering tools that allow messages to be routed by type and severity. For more information, see the <a href=":syslog">online documentation for the Syslog module</a>, as well as PHP\'s documentation pages for the <a href="http://php.net/manual/function.openlog.php">openlog</a> and <a href="http://php.net/manual/function.syslog.php">syslog</a> functions.', [':syslog' => 'https://www.drupal.org/documentation/modules/syslog']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Logging for UNIX, Linux, and Mac OS X') . '</dt>'; - $output .= '<dd>' . t('On UNIX, Linux, and Mac OS X, you will find the configuration in the file <em>/etc/syslog.conf</em>, or in <em>/etc/rsyslog.conf</em> or in the directory <em>/etc/rsyslog.d</em>. These files define the routing configuration. Messages can be flagged with the codes <code>LOG_LOCAL0</code> through <code>LOG_LOCAL7</code>. For information on Syslog facilities, severity levels, and how to set up <em>syslog.conf</em> or <em>rsyslog.conf</em>, see the <em>syslog.conf</em> or <em>rsyslog.conf</em> manual page on your command line.') . '</dd>'; - $output .= '<dt>' . t('Logging for Microsoft Windows') . '</dt>'; - $output .= '<dd>' . t('On Microsoft Windows, messages are always sent to the Event Log using the code <code>LOG_USER</code>.') . '</dd>'; + $output .= '<dt>' . $this->t('Logging for UNIX, Linux, and Mac OS X') . '</dt>'; + $output .= '<dd>' . $this->t('On UNIX, Linux, and Mac OS X, you will find the configuration in the file <em>/etc/syslog.conf</em>, or in <em>/etc/rsyslog.conf</em> or in the directory <em>/etc/rsyslog.d</em>. These files define the routing configuration. Messages can be flagged with the codes <code>LOG_LOCAL0</code> through <code>LOG_LOCAL7</code>. For information on Syslog facilities, severity levels, and how to set up <em>syslog.conf</em> or <em>rsyslog.conf</em>, see the <em>syslog.conf</em> or <em>rsyslog.conf</em> manual page on your command line.') . '</dd>'; + $output .= '<dt>' . $this->t('Logging for Microsoft Windows') . '</dt>'; + $output .= '<dd>' . $this->t('On Microsoft Windows, messages are always sent to the Event Log using the code <code>LOG_USER</code>.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -40,28 +43,28 @@ public function help($route_name, RouteMatchInterface $route_match) { #[Hook('form_system_logging_settings_alter')] public function formSystemLoggingSettingsAlter(&$form, FormStateInterface $form_state) : void { $config = \Drupal::configFactory()->getEditable('syslog.settings'); - $help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . Link::fromTextAndUrl(t('More information'), Url::fromRoute('help.page', ['name' => 'syslog']))->toString() . '.' : NULL; + $help = \Drupal::moduleHandler()->moduleExists('help') ? ' ' . Link::fromTextAndUrl($this->t('More information'), Url::fromRoute('help.page', ['name' => 'syslog']))->toString() . '.' : NULL; $form['syslog_identity'] = [ '#type' => 'textfield', - '#title' => t('Syslog identity'), + '#title' => $this->t('Syslog identity'), '#default_value' => $config->get('identity'), - '#description' => t('A string that will be prepended to every message logged to Syslog. If you have multiple sites logging to the same Syslog log file, a unique identity per site makes it easy to tell the log entries apart.') . $help, + '#description' => $this->t('A string that will be prepended to every message logged to Syslog. If you have multiple sites logging to the same Syslog log file, a unique identity per site makes it easy to tell the log entries apart.') . $help, ]; if (defined('LOG_LOCAL0')) { $form['syslog_facility'] = [ '#type' => 'select', - '#title' => t('Syslog facility'), + '#title' => $this->t('Syslog facility'), '#default_value' => $config->get('facility'), '#options' => syslog_facility_list(), - '#description' => t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, + '#description' => $this->t('Depending on the system configuration, Syslog and other logging tools use this code to identify or filter messages from within the entire system log.') . $help, ]; } $form['syslog_format'] = [ '#type' => 'textarea', - '#title' => t('Syslog format'), + '#title' => $this->t('Syslog format'), '#default_value' => $config->get('format'), '#required' => TRUE, - '#description' => t('Specify the format of the syslog entry. Available variables are: <dl><dt><code>!base_url</code></dt><dd>Base URL of the site.</dd><dt><code>!timestamp</code></dt><dd>Unix timestamp of the log entry.</dd><dt><code>!type</code></dt><dd>The category to which this message belongs.</dd><dt><code>!ip</code></dt><dd>IP address of the user triggering the message.</dd><dt><code>!request_uri</code></dt><dd>The requested URI.</dd><dt><code>!referer</code></dt><dd>HTTP Referer if available.</dd><dt><code>!severity</code></dt><dd>The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).</dd><dt><code>!uid</code></dt><dd>User ID.</dd><dt><code>!link</code></dt><dd>A link to associate with the message.</dd><dt><code>!message</code></dt><dd>The message to store in the log.</dd></dl>'), + '#description' => $this->t('Specify the format of the syslog entry. Available variables are: <dl><dt><code>!base_url</code></dt><dd>Base URL of the site.</dd><dt><code>!timestamp</code></dt><dd>Unix timestamp of the log entry.</dd><dt><code>!type</code></dt><dd>The category to which this message belongs.</dd><dt><code>!ip</code></dt><dd>IP address of the user triggering the message.</dd><dt><code>!request_uri</code></dt><dd>The requested URI.</dd><dt><code>!referer</code></dt><dd>HTTP Referer if available.</dd><dt><code>!severity</code></dt><dd>The severity level of the event; ranges from 0 (Emergency) to 7 (Debug).</dd><dt><code>!uid</code></dt><dd>User ID.</dd><dt><code>!link</code></dt><dd>A link to associate with the message.</dd><dt><code>!message</code></dt><dd>The message to store in the log.</dd></dl>'), ]; $form['#submit'][] = 'syslog_logging_settings_submit'; } diff --git a/core/modules/system/src/Hook/SystemHooks.php b/core/modules/system/src/Hook/SystemHooks.php index 9147cc327eafc7d7f7bdfd1d9515c8f4629b11e2..0c877d2b35b8702bc036a6491169bac53149dee4 100644 --- a/core/modules/system/src/Hook/SystemHooks.php +++ b/core/modules/system/src/Hook/SystemHooks.php @@ -18,6 +18,7 @@ use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Routing\StackedRouteMatchInterface; use Drupal\Core\Asset\AttachedAssetsInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -27,6 +28,8 @@ */ class SystemHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -35,36 +38,36 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.system': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The System module is integral to the site: it provides user interfaces for many core systems and settings, as well as the basic administrative menu structure. For more information, see the <a href=":system">online documentation for the System module</a>.', [':system' => 'https://www.drupal.org/documentation/modules/system']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The System module is integral to the site: it provides user interfaces for many core systems and settings, as well as the basic administrative menu structure. For more information, see the <a href=":system">online documentation for the System module</a>.', [':system' => 'https://www.drupal.org/documentation/modules/system']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing modules') . '</dt>'; - $output .= '<dd>' . t('Users with appropriate permission can install and uninstall modules from the <a href=":modules">Extend page</a>. Depending on which distribution or installation profile you choose when you install your site, several modules are installed and others are provided but not installed. Each module provides a discrete set of features; modules may be installed or uninstalled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download from the <a href=":drupal-modules">Drupal.org module page</a>. Note that uninstalling a module is a destructive action: when you uninstall a module, you will permanently lose all data connected to the module.', [ + $output .= '<dt>' . $this->t('Managing modules') . '</dt>'; + $output .= '<dd>' . $this->t('Users with appropriate permission can install and uninstall modules from the <a href=":modules">Extend page</a>. Depending on which distribution or installation profile you choose when you install your site, several modules are installed and others are provided but not installed. Each module provides a discrete set of features; modules may be installed or uninstalled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download from the <a href=":drupal-modules">Drupal.org module page</a>. Note that uninstalling a module is a destructive action: when you uninstall a module, you will permanently lose all data connected to the module.', [ ':modules' => Url::fromRoute('system.modules_list')->toString(), ':drupal-modules' => 'https://www.drupal.org/project/modules', ]) . '</dd>'; - $output .= '<dt>' . t('Managing themes') . '</dt>'; - $output .= '<dd>' . t('Users with appropriate permission can install and uninstall themes on the <a href=":themes">Appearance page</a>. Themes determine the design and presentation of your site. Depending on which distribution or installation profile you choose when you install your site, a default theme is installed, and possibly a different theme for administration pages. Other themes are provided but not installed, and additional contributed themes are available at the <a href=":drupal-themes">Drupal.org theme page</a>.', [ + $output .= '<dt>' . $this->t('Managing themes') . '</dt>'; + $output .= '<dd>' . $this->t('Users with appropriate permission can install and uninstall themes on the <a href=":themes">Appearance page</a>. Themes determine the design and presentation of your site. Depending on which distribution or installation profile you choose when you install your site, a default theme is installed, and possibly a different theme for administration pages. Other themes are provided but not installed, and additional contributed themes are available at the <a href=":drupal-themes">Drupal.org theme page</a>.', [ ':themes' => Url::fromRoute('system.themes_page')->toString(), ':drupal-themes' => 'https://www.drupal.org/project/themes', ]) . '</dd>'; - $output .= '<dt>' . t('Disabling drag-and-drop functionality') . '</dt>'; - $output .= '<dd>' . t('The default drag-and-drop user interface for ordering tables in the administrative interface presents a challenge for some users, including users of screen readers and other assistive technology. The drag-and-drop interface can be disabled in a table by clicking a link labeled "Show row weights" above the table. The replacement interface allows users to order the table by choosing numerical weights instead of dragging table rows.') . '</dd>'; - $output .= '<dt>' . t('Configuring basic site settings') . '</dt>'; - $output .= '<dd>' . t('The System module provides pages for managing basic site configuration, including <a href=":date-time-settings">Date and time formats</a> and <a href=":site-info">Basic site settings</a> (site name, email address to send mail from, home page, and error pages). Additional configuration pages are listed on the main <a href=":config">Configuration page</a>.', [ + $output .= '<dt>' . $this->t('Disabling drag-and-drop functionality') . '</dt>'; + $output .= '<dd>' . $this->t('The default drag-and-drop user interface for ordering tables in the administrative interface presents a challenge for some users, including users of screen readers and other assistive technology. The drag-and-drop interface can be disabled in a table by clicking a link labeled "Show row weights" above the table. The replacement interface allows users to order the table by choosing numerical weights instead of dragging table rows.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring basic site settings') . '</dt>'; + $output .= '<dd>' . $this->t('The System module provides pages for managing basic site configuration, including <a href=":date-time-settings">Date and time formats</a> and <a href=":site-info">Basic site settings</a> (site name, email address to send mail from, home page, and error pages). Additional configuration pages are listed on the main <a href=":config">Configuration page</a>.', [ ':date-time-settings' => Url::fromRoute('entity.date_format.collection')->toString(), ':site-info' => Url::fromRoute('system.site_information_settings')->toString(), ':config' => Url::fromRoute('system.admin_config')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Checking site status') . '</dt>'; - $output .= '<dd>' . t('The <a href=":status">Status report</a> provides an overview of the configuration, status, and health of your site. Review this report to make sure there are not any problems to address, and to find information about the software your site and web server are using.', [':status' => Url::fromRoute('system.status')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Using maintenance mode') . '</dt>'; - $output .= '<dd>' . t('When you are performing site maintenance, you can prevent non-administrative users (including anonymous visitors) from viewing your site by putting it in <a href=":maintenance-mode">Maintenance mode</a>. This will prevent unauthorized users from making changes to the site while you are performing maintenance, or from seeing a broken site while updates are in progress.', [ + $output .= '<dt>' . $this->t('Checking site status') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":status">Status report</a> provides an overview of the configuration, status, and health of your site. Review this report to make sure there are not any problems to address, and to find information about the software your site and web server are using.', [':status' => Url::fromRoute('system.status')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Using maintenance mode') . '</dt>'; + $output .= '<dd>' . $this->t('When you are performing site maintenance, you can prevent non-administrative users (including anonymous visitors) from viewing your site by putting it in <a href=":maintenance-mode">Maintenance mode</a>. This will prevent unauthorized users from making changes to the site while you are performing maintenance, or from seeing a broken site while updates are in progress.', [ ':maintenance-mode' => Url::fromRoute('system.site_maintenance_mode')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Configuring for performance') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":performance-page">Performance page</a>, the site can be configured to aggregate CSS and JavaScript files, making the total request size smaller. Note that, for small- to medium-sized websites, the <a href=":page-cache">Internal Page Cache module</a> should be installed so that pages are efficiently cached and reused for anonymous users. Finally, for websites of all sizes, the <a href=":dynamic-page-cache">Dynamic Page Cache module</a> should also be installed so that the non-personalized parts of pages are efficiently cached (for all users).', [ + $output .= '<dt>' . $this->t('Configuring for performance') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":performance-page">Performance page</a>, the site can be configured to aggregate CSS and JavaScript files, making the total request size smaller. Note that, for small- to medium-sized websites, the <a href=":page-cache">Internal Page Cache module</a> should be installed so that pages are efficiently cached and reused for anonymous users. Finally, for websites of all sizes, the <a href=":dynamic-page-cache">Dynamic Page Cache module</a> should also be installed so that the non-personalized parts of pages are efficiently cached (for all users).', [ ':performance-page' => Url::fromRoute('system.performance_settings')->toString(), ':page-cache' => \Drupal::moduleHandler()->moduleExists('page_cache') ? Url::fromRoute('help.page', [ 'name' => 'page_cache', @@ -73,52 +76,52 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'dynamic_page_cache', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Configuring cron') . '</dt>'; - $output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis; these operations are known as <em>cron</em> tasks. On the <a href=":cron">Cron page</a>, you can configure cron to run periodically as part of server responses by installing the <em>Automated Cron</em> module, or you can turn this off and trigger cron from an outside process on your web server. You can verify the status of cron tasks by visiting the <a href=":status">Status report page</a>. For more information, see the <a href=":handbook">online documentation for configuring cron jobs</a>.', [ + $output .= '<dt>' . $this->t('Configuring cron') . '</dt>'; + $output .= '<dd>' . $this->t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis; these operations are known as <em>cron</em> tasks. On the <a href=":cron">Cron page</a>, you can configure cron to run periodically as part of server responses by installing the <em>Automated Cron</em> module, or you can turn this off and trigger cron from an outside process on your web server. You can verify the status of cron tasks by visiting the <a href=":status">Status report page</a>. For more information, see the <a href=":handbook">online documentation for configuring cron jobs</a>.', [ ':status' => Url::fromRoute('system.status')->toString(), ':handbook' => 'https://www.drupal.org/docs/administering-a-drupal-site/cron-automated-tasks/cron-automated-tasks-overview', ':cron' => Url::fromRoute('system.cron_settings')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Configuring the file system') . '</dt>'; - $output .= '<dd>' . t('Your site has several file directories, which are used to store and process uploaded and generated files. The <em>public</em> file directory, which is configured in your settings.php file, is the default place for storing uploaded files. Links to files in this directory contain the direct file URL, so when the files are requested, the web server will send them directly without invoking your site code. This means that the files can be downloaded by anyone with the file URL, so requests are not access-controlled but they are efficient. The <em>private</em> file directory, also configured in your settings.php file and ideally located outside the site web root, is access controlled. Links to files in this directory are not direct, so requests to these files are mediated by your site code. This means that your site can check file access permission for each file before deciding to fulfill the request, so the requests are more secure, but less efficient. You should only use the private storage for files that need access control, not for files like your site logo and background images used on every page. The <em>temporary</em> file directory is used internally by your site code for various operations, and is configured on the <a href=":file-system">File system settings</a> page. You can also see the configured public and private file directories on this page, and choose whether public or private should be the default for uploaded files.', [ + $output .= '<dt>' . $this->t('Configuring the file system') . '</dt>'; + $output .= '<dd>' . $this->t('Your site has several file directories, which are used to store and process uploaded and generated files. The <em>public</em> file directory, which is configured in your settings.php file, is the default place for storing uploaded files. Links to files in this directory contain the direct file URL, so when the files are requested, the web server will send them directly without invoking your site code. This means that the files can be downloaded by anyone with the file URL, so requests are not access-controlled but they are efficient. The <em>private</em> file directory, also configured in your settings.php file and ideally located outside the site web root, is access controlled. Links to files in this directory are not direct, so requests to these files are mediated by your site code. This means that your site can check file access permission for each file before deciding to fulfill the request, so the requests are more secure, but less efficient. You should only use the private storage for files that need access control, not for files like your site logo and background images used on every page. The <em>temporary</em> file directory is used internally by your site code for various operations, and is configured on the <a href=":file-system">File system settings</a> page. You can also see the configured public and private file directories on this page, and choose whether public or private should be the default for uploaded files.', [ ':file-system' => Url::fromRoute('system.file_system_settings')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Configuring the image toolkit') . '</dt>'; - $output .= '<dd>' . t('On the <a href=":toolkit">Image toolkit page</a>, you can select and configure the PHP toolkit used to manipulate images. Depending on which distribution or installation profile you choose when you install your site, the GD2 toolkit and possibly others are included; other toolkits may be provided by contributed modules.', [ + $output .= '<dt>' . $this->t('Configuring the image toolkit') . '</dt>'; + $output .= '<dd>' . $this->t('On the <a href=":toolkit">Image toolkit page</a>, you can select and configure the PHP toolkit used to manipulate images. Depending on which distribution or installation profile you choose when you install your site, the GD2 toolkit and possibly others are included; other toolkits may be provided by contributed modules.', [ ':toolkit' => Url::fromRoute('system.image_toolkit_settings')->toString(), ]) . '</dd>'; if (\Drupal::currentUser()->hasPermission('administer site configuration')) { - $output .= '<dt id="security-advisories">' . t('Critical security advisories') . '</dt>'; - $output .= '<dd>' . t('The System module displays highly critical and time-sensitive security announcements to site administrators. Some security announcements will be displayed until a critical security update is installed. Announcements that are not associated with a specific release will appear for a fixed period of time. <a href=":handbook">More information on critical security advisories</a>.', [ + $output .= '<dt id="security-advisories">' . $this->t('Critical security advisories') . '</dt>'; + $output .= '<dd>' . $this->t('The System module displays highly critical and time-sensitive security announcements to site administrators. Some security announcements will be displayed until a critical security update is installed. Announcements that are not associated with a specific release will appear for a fixed period of time. <a href=":handbook">More information on critical security advisories</a>.', [ ':handbook' => 'https://www.drupal.org/docs/updating-drupal/responding-to-critical-security-update-advisories', ]) . '</dd>'; - $output .= '<dd>' . t('Only the most highly critical security announcements will be shown. <a href=":advisories-list">View all security announcements</a>.', [':advisories-list' => 'https://www.drupal.org/security']) . '</dd>'; + $output .= '<dd>' . $this->t('Only the most highly critical security announcements will be shown. <a href=":advisories-list">View all security announcements</a>.', [':advisories-list' => 'https://www.drupal.org/security']) . '</dd>'; } $output .= '</dl>'; return $output; case 'system.admin_index': - return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>'; + return '<p>' . $this->t('This page shows you all available administration tasks for each module.') . '</p>'; case 'system.themes_page': - $output = '<p>' . t('Set and configure the default theme for your website. Alternative <a href=":themes">themes</a> are available.', [':themes' => 'https://www.drupal.org/project/themes']) . '</p>'; + $output = '<p>' . $this->t('Set and configure the default theme for your website. Alternative <a href=":themes">themes</a> are available.', [':themes' => 'https://www.drupal.org/project/themes']) . '</p>'; if (\Drupal::moduleHandler()->moduleExists('block')) { - $output .= '<p>' . t('You can place blocks for each theme on the <a href=":blocks">block layout</a> page.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; + $output .= '<p>' . $this->t('You can place blocks for each theme on the <a href=":blocks">block layout</a> page.', [':blocks' => Url::fromRoute('block.admin_display')->toString()]) . '</p>'; } return $output; case 'system.theme_settings_theme': $theme_list = \Drupal::service('theme_handler')->listInfo(); $theme = $theme_list[$route_match->getParameter('theme')]; - return '<p>' . t('These options control the display settings for the %name theme. When your site is displayed using this theme, these settings will be used.', ['%name' => $theme->info['name']]) . '</p>'; + return '<p>' . $this->t('These options control the display settings for the %name theme. When your site is displayed using this theme, these settings will be used.', ['%name' => $theme->info['name']]) . '</p>'; case 'system.theme_settings': - return '<p>' . t('Control default display settings for your site, across all themes. Use theme-specific settings to override these defaults.') . '</p>'; + return '<p>' . $this->t('Control default display settings for your site, across all themes. Use theme-specific settings to override these defaults.') . '</p>'; case 'system.modules_list': - $output = '<p>' . t('Add <a href=":modules">contributed modules</a> to extend your site\'s functionality.', [':modules' => 'https://www.drupal.org/project/modules']) . '</p>'; + $output = '<p>' . $this->t('Add <a href=":modules">contributed modules</a> to extend your site\'s functionality.', [':modules' => 'https://www.drupal.org/project/modules']) . '</p>'; if (!\Drupal::moduleHandler()->moduleExists('update')) { - $output .= '<p>' . t('Regularly review available updates and update as required to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated. Install the <a href=":update-manager">Update Manager module</a> to update modules and themes.', [ + $output .= '<p>' . $this->t('Regularly review available updates and update as required to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time a module is updated. Install the <a href=":update-manager">Update Manager module</a> to update modules and themes.', [ ':update-php' => Url::fromRoute('system.db_update')->toString(), ':update-manager' => Url::fromRoute('system.modules_list', [], [ 'fragment' => 'module-update', @@ -128,28 +131,28 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'system.modules_uninstall': - return '<p>' . t('The uninstall process removes all data related to a module.') . '</p>'; + return '<p>' . $this->t('The uninstall process removes all data related to a module.') . '</p>'; case 'entity.block.edit_form': if (($block = $route_match->getParameter('block')) && $block->getPluginId() == 'system_powered_by_block') { - return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>'; + return '<p>' . $this->t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>'; } break; case 'block.admin_add': if ($route_match->getParameter('plugin_id') == 'system_powered_by_block') { - return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>'; + return '<p>' . $this->t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>'; } break; case 'system.site_maintenance_mode': if (\Drupal::currentUser()->id() == 1) { - return '<p>' . t('Use maintenance mode when making major updates, particularly if the updates could disrupt visitors or the update process. Examples include upgrading, importing or exporting content, modifying a theme, modifying content types, and making backups.') . '</p>'; + return '<p>' . $this->t('Use maintenance mode when making major updates, particularly if the updates could disrupt visitors or the update process. Examples include upgrading, importing or exporting content, modifying a theme, modifying content types, and making backups.') . '</p>'; } break; case 'system.status': - return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on Drupal.org's support forums and project issue queues. Before filing a support request, ensure that your web server meets the <a href=\":system-requirements\">system requirements.</a>", [':system-requirements' => 'https://www.drupal.org/docs/system-requirements']) . '</p>'; + return '<p>' . $this->t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on Drupal.org's support forums and project issue queues. Before filing a support request, ensure that your web server meets the <a href=\":system-requirements\">system requirements.</a>", [':system-requirements' => 'https://www.drupal.org/docs/system-requirements']) . '</p>'; } } @@ -165,12 +168,12 @@ public function updaterInfo(): array { return [ 'module' => [ 'class' => 'Drupal\Core\Updater\Module', - 'name' => t('Update modules'), + 'name' => $this->t('Update modules'), 'weight' => 0, ], 'theme' => [ 'class' => 'Drupal\Core\Updater\Theme', - 'name' => t('Update themes'), + 'name' => $this->t('Update themes'), 'weight' => 0, ], ]; @@ -184,12 +187,12 @@ public function filetransferInfo(): array { $backends = []; // This is the default, will be available on most systems. if (function_exists('ftp_connect')) { - $backends['ftp'] = ['title' => t('FTP'), 'class' => 'Drupal\Core\FileTransfer\FTP', 'weight' => 0]; + $backends['ftp'] = ['title' => $this->t('FTP'), 'class' => 'Drupal\Core\FileTransfer\FTP', 'weight' => 0]; } // SSH2 lib connection is only available if the proper PHP extension is // installed. if (function_exists('ssh2_connect')) { - $backends['ssh'] = ['title' => t('SSH'), 'class' => 'Drupal\Core\FileTransfer\SSH', 'weight' => 20]; + $backends['ssh'] = ['title' => $this->t('SSH'), 'class' => 'Drupal\Core\FileTransfer\SSH', 'weight' => 20]; } return $backends; } @@ -470,7 +473,7 @@ public function pageTop(): void { $display_as_errors ? $messenger->addError($link) : $messenger->addWarning($link); } if (\Drupal::moduleHandler()->moduleExists('help')) { - $help_link = t('(<a href=":system-help">What are critical security announcements?</a>)', [ + $help_link = $this->t('(<a href=":system-help">What are critical security announcements?</a>)', [ ':system-help' => Url::fromRoute('help.page', [ 'name' => 'system', ], [ diff --git a/core/modules/system/src/Hook/SystemTokensHooks.php b/core/modules/system/src/Hook/SystemTokensHooks.php index ee05509017daa9c4e6af6e35e6fd33ff94ac6952..8ff35bf8775bc0e40d5f6fce2c4177bd50f4a1ec 100644 --- a/core/modules/system/src/Hook/SystemTokensHooks.php +++ b/core/modules/system/src/Hook/SystemTokensHooks.php @@ -3,6 +3,7 @@ namespace Drupal\system\Hook; use Drupal\Core\Datetime\Entity\DateFormat; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Hook\Attribute\Hook; @@ -12,82 +13,84 @@ */ class SystemTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $types['site'] = [ - 'name' => t("Site information"), - 'description' => t("Tokens for site-wide settings and other global information."), + 'name' => $this->t("Site information"), + 'description' => $this->t("Tokens for site-wide settings and other global information."), ]; - $types['date'] = ['name' => t("Dates"), 'description' => t("Tokens related to times and dates.")]; + $types['date'] = ['name' => $this->t("Dates"), 'description' => $this->t("Tokens related to times and dates.")]; // Site-wide global tokens. - $site['name'] = ['name' => t("Name"), 'description' => t("The name of the site.")]; - $site['slogan'] = ['name' => t("Slogan"), 'description' => t("The slogan of the site.")]; + $site['name'] = ['name' => $this->t("Name"), 'description' => $this->t("The name of the site.")]; + $site['slogan'] = ['name' => $this->t("Slogan"), 'description' => $this->t("The slogan of the site.")]; $site['mail'] = [ - 'name' => t("Email"), - 'description' => t("The administrative email address for the site."), + 'name' => $this->t("Email"), + 'description' => $this->t("The administrative email address for the site."), ]; $site['base-url'] = [ - 'name' => t("Base URL"), - 'description' => t("The base URL of the site, currently: @base_url", [ + 'name' => $this->t("Base URL"), + 'description' => $this->t("The base URL of the site, currently: @base_url", [ '@base_url' => \Drupal::service('router.request_context')->getCompleteBaseUrl(), ]), ]; $site['base-path'] = [ - 'name' => t("Base path"), - 'description' => t("The base path of the site, currently: @base_path", [ + 'name' => $this->t("Base path"), + 'description' => $this->t("The base path of the site, currently: @base_path", [ '@base_path' => \Drupal::request()->getBasePath(), ]), ]; $site['url'] = [ - 'name' => t("URL"), - 'description' => t("The URL of the site's front page with the language prefix, if it exists."), + 'name' => $this->t("URL"), + 'description' => $this->t("The URL of the site's front page with the language prefix, if it exists."), ]; $site['url-brief'] = [ - 'name' => t("URL (brief)"), - 'description' => t("The URL of the site's front page without the protocol."), + 'name' => $this->t("URL (brief)"), + 'description' => $this->t("The URL of the site's front page without the protocol."), ]; $site['login-url'] = [ - 'name' => t("Login page"), - 'description' => t("The URL of the site's login page."), + 'name' => $this->t("Login page"), + 'description' => $this->t("The URL of the site's login page."), ]; /** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */ $date_formatter = \Drupal::service('date.formatter'); // Date related tokens. $request_time = \Drupal::time()->getRequestTime(); $date['short'] = [ - 'name' => t("Short format"), - 'description' => t("The current date in 'short' format. (%date)", [ + 'name' => $this->t("Short format"), + 'description' => $this->t("The current date in 'short' format. (%date)", [ '%date' => $date_formatter->format($request_time, 'short'), ]), ]; $date['medium'] = [ - 'name' => t("Medium format"), - 'description' => t("The current date in 'medium' format. (%date)", [ + 'name' => $this->t("Medium format"), + 'description' => $this->t("The current date in 'medium' format. (%date)", [ '%date' => $date_formatter->format($request_time, 'medium'), ]), ]; $date['long'] = [ - 'name' => t("Long format"), - 'description' => t("The current date in 'long' format. (%date)", [ + 'name' => $this->t("Long format"), + 'description' => $this->t("The current date in 'long' format. (%date)", [ '%date' => $date_formatter->format($request_time, 'long'), ]), ]; $date['custom'] = [ - 'name' => t("Custom format"), - 'description' => t('The current date in a custom format. See <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters">the PHP documentation</a> for details.'), + 'name' => $this->t("Custom format"), + 'description' => $this->t('The current date in a custom format. See <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters">the PHP documentation</a> for details.'), ]; $date['since'] = [ - 'name' => t("Time-since"), - 'description' => t("The current date in 'time-since' format. (%date)", [ + 'name' => $this->t("Time-since"), + 'description' => $this->t("The current date in 'time-since' format. (%date)", [ '%date' => $date_formatter->formatTimeDiffSince($request_time - 360), ]), ]; $date['raw'] = [ - 'name' => t("Raw timestamp"), - 'description' => t("The current date in UNIX timestamp format (%date)", [ + 'name' => $this->t("Raw timestamp"), + 'description' => $this->t("The current date in UNIX timestamp format (%date)", [ '%date' => $request_time, ]), ]; diff --git a/core/modules/taxonomy/src/Hook/TaxonomyHooks.php b/core/modules/taxonomy/src/Hook/TaxonomyHooks.php index 710708551ad3e89e146b6bb9c3df4c775cbfa9c0..51c122c91f45bd2ac2f6a4002c4900e921685a98 100644 --- a/core/modules/taxonomy/src/Hook/TaxonomyHooks.php +++ b/core/modules/taxonomy/src/Hook/TaxonomyHooks.php @@ -2,6 +2,7 @@ namespace Drupal\taxonomy\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\taxonomy\Entity\Term; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; @@ -13,6 +14,8 @@ */ class TaxonomyHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,26 +25,26 @@ public function help($route_name, RouteMatchInterface $route_match) { case 'help.page.taxonomy': $field_ui_url = \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', ['name' => 'field_ui'])->toString() : '#'; $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Taxonomy module allows users who have permission to create and edit content to categorize (tag) content of that type. Users who have the <em>Administer vocabularies and terms</em> <a href=":permissions" title="Taxonomy module permissions">permission</a> can add <em>vocabularies</em> that contain a set of related <em>terms</em>. The terms in a vocabulary can either be pre-set by an administrator or built gradually as content is added and edited. Terms may be organized hierarchically if desired.', [ ':permissions' => Url::fromRoute('user.admin_permissions.module', [ 'modules' => 'taxonomy', ])->toString(), ]) . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', [':taxonomy' => 'https://www.drupal.org/docs/8/core/modules/taxonomy']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":taxonomy">online documentation for the Taxonomy module</a>.', [':taxonomy' => 'https://www.drupal.org/docs/8/core/modules/taxonomy']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing vocabularies') . '</dt>'; - $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', [ + $output .= '<dt>' . $this->t('Managing vocabularies') . '</dt>'; + $output .= '<dd>' . $this->t('Users who have the <em>Administer vocabularies and terms</em> permission can add and edit vocabularies from the <a href=":taxonomy_admin">Taxonomy administration page</a>. Vocabularies can be deleted from their <em>Edit vocabulary</em> page. Users with the <em>Taxonomy term: Administer fields</em> permission may add additional fields for terms in that vocabulary using the <a href=":field_ui">Field UI module</a>.', [ ':taxonomy_admin' => Url::fromRoute('entity.taxonomy_vocabulary.collection')->toString(), ':field_ui' => $field_ui_url, ]) . '</dd>'; - $output .= '<dt>' . t('Managing terms') . '</dt>'; - $output .= '<dd>' . t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', [ + $output .= '<dt>' . $this->t('Managing terms') . '</dt>'; + $output .= '<dd>' . $this->t('Users who have the <em>Administer vocabularies and terms</em> permission or the <em>Edit terms</em> permission for a particular vocabulary can add, edit, and organize the terms in a vocabulary from a vocabulary\'s term listing page, which can be accessed by going to the <a href=":taxonomy_admin">Taxonomy administration page</a> and clicking <em>List terms</em> in the <em>Operations</em> column. Users must have the <em>Administer vocabularies and terms</em> permission or the <em>Delete terms</em> permission for a particular vocabulary to delete terms.', [ ':taxonomy_admin' => Url::fromRoute('entity.taxonomy_vocabulary.collection')->toString(), ]) . ' </dd>'; - $output .= '<dt>' . t('Classifying entity content') . '</dt>'; - $output .= '<dd>' . t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', [ + $output .= '<dt>' . $this->t('Classifying entity content') . '</dt>'; + $output .= '<dd>' . $this->t('A user with the <em>Administer fields</em> permission for a certain entity type may add <em>Taxonomy term</em> reference fields to the entity type, which will allow entities to be classified using taxonomy terms. See the <a href=":entity_reference">Entity Reference help</a> for more information about reference fields. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them.', [ ':field_ui' => $field_ui_url, ':field' => Url::fromRoute('help.page', [ 'name' => 'field', @@ -50,10 +53,10 @@ public function help($route_name, RouteMatchInterface $route_match) { 'name' => 'entity_reference', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Adding new terms during content creation') . '</dt>'; - $output .= '<dd>' . t("Allowing users to add new terms gradually builds a vocabulary as content is added and edited. Users can add new terms if either of the two <em>Autocomplete</em> widgets is chosen for the Taxonomy term reference field in the <em>Manage form display</em> page for the field. You will also need to enable the <em>Create referenced entities if they don't already exist</em> option, and restrict the field to one vocabulary.") . '</dd>'; - $output .= '<dt>' . t('Configuring displays and form displays') . '</dt>'; - $output .= '<dd>' . t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', [ + $output .= '<dt>' . $this->t('Adding new terms during content creation') . '</dt>'; + $output .= '<dd>' . $this->t("Allowing users to add new terms gradually builds a vocabulary as content is added and edited. Users can add new terms if either of the two <em>Autocomplete</em> widgets is chosen for the Taxonomy term reference field in the <em>Manage form display</em> page for the field. You will also need to enable the <em>Create referenced entities if they don't already exist</em> option, and restrict the field to one vocabulary.") . '</dd>'; + $output .= '<dt>' . $this->t('Configuring displays and form displays') . '</dt>'; + $output .= '<dd>' . $this->t('See the <a href=":entity_reference">Entity Reference help</a> page for the field widgets and formatters that can be configured for any reference field on the <em>Manage display</em> and <em>Manage form display</em> pages. Taxonomy additionally provides an <em>RSS category</em> formatter that displays nothing when the entity item is displayed as HTML, but displays an RSS category instead of a list when the entity item is displayed in an RSS feed.', [ ':entity_reference' => Url::fromRoute('help.page', [ 'name' => 'entity_reference', ])->toString(), @@ -64,7 +67,7 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'entity.taxonomy_vocabulary.collection': - $output = '<p>' . t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '</p>'; + $output = '<p>' . $this->t('Taxonomy is for categorizing content. Terms are grouped into vocabularies. For example, a vocabulary called "Fruit" would contain the terms "Apple" and "Banana".') . '</p>'; return $output; } } @@ -101,7 +104,7 @@ public function entityOperation(EntityInterface $term): array { $operations = []; if ($term instanceof Term && $term->access('create')) { $operations['add-child'] = [ - 'title' => t('Add child'), + 'title' => $this->t('Add child'), 'weight' => 10, 'url' => Url::fromRoute('entity.taxonomy_term.add_form', [ 'taxonomy_vocabulary' => $term->bundle(), diff --git a/core/modules/taxonomy/src/Hook/TaxonomyTokensHooks.php b/core/modules/taxonomy/src/Hook/TaxonomyTokensHooks.php index b75d4172493e5a81697d14ef61b4fd56e1ddb3ac..12c8f7dc885820d65d68c57b9706424e94af7799 100644 --- a/core/modules/taxonomy/src/Hook/TaxonomyTokensHooks.php +++ b/core/modules/taxonomy/src/Hook/TaxonomyTokensHooks.php @@ -3,6 +3,7 @@ namespace Drupal\taxonomy\Hook; use Drupal\Core\Datetime\Entity\DateFormat; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\taxonomy\Entity\Vocabulary; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Render\BubbleableMetadata; @@ -13,69 +14,71 @@ */ class TaxonomyTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $types['term'] = [ - 'name' => t("Taxonomy terms"), - 'description' => t("Tokens related to taxonomy terms."), + 'name' => $this->t("Taxonomy terms"), + 'description' => $this->t("Tokens related to taxonomy terms."), 'needs-data' => 'term', ]; $types['vocabulary'] = [ - 'name' => t("Vocabularies"), - 'description' => t("Tokens related to taxonomy vocabularies."), + 'name' => $this->t("Vocabularies"), + 'description' => $this->t("Tokens related to taxonomy vocabularies."), 'needs-data' => 'vocabulary', ]; // Taxonomy term related variables. $term['tid'] = [ - 'name' => t("Term ID"), - 'description' => t("The unique ID of the taxonomy term."), + 'name' => $this->t("Term ID"), + 'description' => $this->t("The unique ID of the taxonomy term."), ]; - $term['uuid'] = ['name' => t('UUID'), 'description' => t("The UUID of the taxonomy term.")]; - $term['name'] = ['name' => t("Name"), 'description' => t("The name of the taxonomy term.")]; + $term['uuid'] = ['name' => $this->t('UUID'), 'description' => $this->t("The UUID of the taxonomy term.")]; + $term['name'] = ['name' => $this->t("Name"), 'description' => $this->t("The name of the taxonomy term.")]; $term['description'] = [ - 'name' => t("Description"), - 'description' => t("The optional description of the taxonomy term."), + 'name' => $this->t("Description"), + 'description' => $this->t("The optional description of the taxonomy term."), ]; $term['node-count'] = [ - 'name' => t("Node count"), - 'description' => t("The number of nodes tagged with the taxonomy term."), + 'name' => $this->t("Node count"), + 'description' => $this->t("The number of nodes tagged with the taxonomy term."), ]; - $term['url'] = ['name' => t("URL"), 'description' => t("The URL of the taxonomy term.")]; + $term['url'] = ['name' => $this->t("URL"), 'description' => $this->t("The URL of the taxonomy term.")]; // Taxonomy vocabulary related variables. $vocabulary['vid'] = [ - 'name' => t("Vocabulary ID"), - 'description' => t("The unique ID of the taxonomy vocabulary."), + 'name' => $this->t("Vocabulary ID"), + 'description' => $this->t("The unique ID of the taxonomy vocabulary."), ]; - $vocabulary['name'] = ['name' => t("Name"), 'description' => t("The name of the taxonomy vocabulary.")]; + $vocabulary['name'] = ['name' => $this->t("Name"), 'description' => $this->t("The name of the taxonomy vocabulary.")]; $vocabulary['description'] = [ - 'name' => t("Description"), - 'description' => t("The optional description of the taxonomy vocabulary."), + 'name' => $this->t("Description"), + 'description' => $this->t("The optional description of the taxonomy vocabulary."), ]; $vocabulary['node-count'] = [ - 'name' => t("Node count"), - 'description' => t("The number of nodes tagged with terms belonging to the taxonomy vocabulary."), + 'name' => $this->t("Node count"), + 'description' => $this->t("The number of nodes tagged with terms belonging to the taxonomy vocabulary."), ]; $vocabulary['term-count'] = [ - 'name' => t("Term count"), - 'description' => t("The number of terms belonging to the taxonomy vocabulary."), + 'name' => $this->t("Term count"), + 'description' => $this->t("The number of terms belonging to the taxonomy vocabulary."), ]; // Chained tokens for taxonomies $term['vocabulary'] = [ - 'name' => t("Vocabulary"), - 'description' => t("The vocabulary the taxonomy term belongs to."), + 'name' => $this->t("Vocabulary"), + 'description' => $this->t("The vocabulary the taxonomy term belongs to."), 'type' => 'vocabulary', ]; $term['parent'] = [ - 'name' => t("Parent term"), - 'description' => t("The parent term of the taxonomy term, if one exists."), + 'name' => $this->t("Parent term"), + 'description' => $this->t("The parent term of the taxonomy term, if one exists."), 'type' => 'term', ]; $term['changed'] = [ - 'name' => t("Date changed"), - 'description' => t("The date the taxonomy was most recently updated."), + 'name' => $this->t("Date changed"), + 'description' => $this->t("The date the taxonomy was most recently updated."), 'type' => 'date', ]; return ['types' => $types, 'tokens' => ['term' => $term, 'vocabulary' => $vocabulary]]; diff --git a/core/modules/taxonomy/src/Hook/TaxonomyViewsHooks.php b/core/modules/taxonomy/src/Hook/TaxonomyViewsHooks.php index 092a99231c7f4fb83f14173d7d8105b042455ef6..3e8a274f40c0edb26980225eb6e659ac165a4a5c 100644 --- a/core/modules/taxonomy/src/Hook/TaxonomyViewsHooks.php +++ b/core/modules/taxonomy/src/Hook/TaxonomyViewsHooks.php @@ -2,6 +2,7 @@ namespace Drupal\taxonomy\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -10,43 +11,45 @@ */ class TaxonomyViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data_alter(). */ #[Hook('views_data_alter')] public function viewsDataAlter(&$data): void { $data['node_field_data']['term_node_tid'] = [ - 'title' => t('Taxonomy terms on node'), - 'help' => t('Relate nodes to taxonomy terms, specifying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'), + 'title' => $this->t('Taxonomy terms on node'), + 'help' => $this->t('Relate nodes to taxonomy terms, specifying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'), 'relationship' => [ 'id' => 'node_term_data', - 'label' => t('term'), + 'label' => $this->t('term'), 'base' => 'taxonomy_term_field_data', ], 'field' => [ - 'title' => t('All taxonomy terms'), - 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'), + 'title' => $this->t('All taxonomy terms'), + 'help' => $this->t('Display all taxonomy terms associated with a node from specified vocabularies.'), 'id' => 'taxonomy_index_tid', 'no group by' => TRUE, 'click sortable' => FALSE, ], ]; $data['node_field_data']['term_node_tid_depth'] = [ - 'help' => t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.'), + 'help' => $this->t('Display content if it has the selected taxonomy terms, or children of the selected terms. Due to additional complexity, this has fewer options than the versions without depth.'), 'real field' => 'nid', 'argument' => [ - 'title' => t('Has taxonomy term ID (with depth)'), + 'title' => $this->t('Has taxonomy term ID (with depth)'), 'id' => 'taxonomy_index_tid_depth', 'accept depth modifier' => TRUE, ], 'filter' => [ - 'title' => t('Has taxonomy terms (with depth)'), + 'title' => $this->t('Has taxonomy terms (with depth)'), 'id' => 'taxonomy_index_tid_depth', ], ]; $data['node_field_data']['term_node_tid_depth_modifier'] = [ - 'title' => t('Has taxonomy term ID depth modifier'), - 'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.'), + 'title' => $this->t('Has taxonomy term ID depth modifier'), + 'help' => $this->t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional contextual filter value.'), 'argument' => [ 'id' => 'taxonomy_index_tid_depth_modifier', ], diff --git a/core/modules/telephone/src/Hook/TelephoneHooks.php b/core/modules/telephone/src/Hook/TelephoneHooks.php index 5af75f98fd9d31e08759c7648edee478c50aa0b7..6813600e5a7fe9d06b5abc3836530ff149339d1a 100644 --- a/core/modules/telephone/src/Hook/TelephoneHooks.php +++ b/core/modules/telephone/src/Hook/TelephoneHooks.php @@ -3,6 +3,7 @@ namespace Drupal\telephone\Hook; use Drupal\Core\Field\FieldTypeCategoryManagerInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -12,6 +13,8 @@ */ class TelephoneHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -20,8 +23,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.telephone': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Telephone module allows you to create fields that contain telephone numbers. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":telephone_documentation">online documentation for the Telephone module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Telephone module allows you to create fields that contain telephone numbers. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":telephone_documentation">online documentation for the Telephone module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -30,16 +33,16 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':telephone_documentation' => 'https://www.drupal.org/documentation/modules/telephone', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying telephone fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and the <em>display</em> of the telephone field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying telephone fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and the <em>display</em> of the telephone field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Displaying telephone numbers as links') . '</dt>'; - $output .= '<dd>' . t('Telephone numbers can be displayed as links with the scheme name <em>tel:</em> by choosing the <em>Telephone</em> display format on the <em>Manage display</em> page. Any spaces will be stripped out of the link text. This semantic markup improves the user experience on mobile and assistive technology devices.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying telephone numbers as links') . '</dt>'; + $output .= '<dd>' . $this->t('Telephone numbers can be displayed as links with the scheme name <em>tel:</em> by choosing the <em>Telephone</em> display format on the <em>Manage display</em> page. Any spaces will be stripped out of the link text. This semantic markup improves the user experience on mobile and assistive technology devices.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/text/src/Hook/TextHooks.php b/core/modules/text/src/Hook/TextHooks.php index 356052ad658d8eefc11ed9bd84513f2f8771a946..21835e4063a41362b64ed412e2d709e368f73df3 100644 --- a/core/modules/text/src/Hook/TextHooks.php +++ b/core/modules/text/src/Hook/TextHooks.php @@ -2,6 +2,7 @@ namespace Drupal\text\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class TextHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,8 +22,8 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.text': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Text module allows you to create short and long text fields with optional summaries. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":text_documentation">online documentation for the Text module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Text module allows you to create short and long text fields with optional summaries. See the <a href=":field">Field module help</a> and the <a href=":field_ui">Field UI help</a> pages for general information on fields and how to create and manage them. For more information, see the <a href=":text_documentation">online documentation for the Text module</a>.', [ ':field' => Url::fromRoute('help.page', [ 'name' => 'field', ])->toString(), @@ -29,24 +32,24 @@ public function help($route_name, RouteMatchInterface $route_match) { ])->toString() : '#', ':text_documentation' => 'https://www.drupal.org/documentation/modules/text', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Managing and displaying text fields') . '</dt>'; - $output .= '<dd>' . t('The <em>settings</em> and <em>display</em> of the text field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ + $output .= '<dt>' . $this->t('Managing and displaying text fields') . '</dt>'; + $output .= '<dd>' . $this->t('The <em>settings</em> and <em>display</em> of the text field can be configured separately. See the <a href=":field_ui">Field UI help</a> for more information on how to manage fields and their display.', [ ':field_ui' => \Drupal::moduleHandler()->moduleExists('field_ui') ? Url::fromRoute('help.page', [ 'name' => 'field_ui', ])->toString() : '#', ]) . '</dd>'; - $output .= '<dt>' . t('Creating short text fields') . '</dt>'; - $output .= '<dd>' . t('If you choose <em>Text (plain)</em> or <em>Text (formatted)</em> as the field type on the <em>Manage fields</em> page, then a field with a single row is displayed. You can change the maximum text length in the <em>Field settings</em> when you set up the field.') . '</dd>'; - $output .= '<dt>' . t('Creating long text fields') . '</dt>'; - $output .= '<dd>' . t('If you choose <em>Text (plain, long)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long, with summary)</em> on the <em>Manage fields</em> page, then users can insert text of unlimited length. On the <em>Manage form display</em> page, you can set the number of rows that are displayed to users.') . '</dd>'; - $output .= '<dt>' . t('Trimming the text length') . '</dt>'; - $output .= '<dd>' . t('On the <em>Manage display</em> page you can choose to display a trimmed version of the text, and if so, where to cut off the text.') . '</dd>'; - $output .= '<dt>' . t('Displaying summaries instead of trimmed text') . '</dt>'; - $output .= '<dd>' . t('As an alternative to using a trimmed version of the text, you can enter a separate summary by choosing the <em>Text (formatted, long, with summary)</em> field type on the <em>Manage fields</em> page. Even when <em>Summary input</em> is enabled, and summaries are provided, you can display <em>trimmed</em> text nonetheless by choosing the appropriate format on the <em>Manage display</em> page.') . '</dd>'; - $output .= '<dt>' . t('Using text formats and editors') . '</dt>'; - $output .= '<dd>' . t('If you choose <em>Text (plain)</em> or <em>Text (plain, long)</em> you restrict the input to <em>Plain text</em> only. If you choose <em>Text (formatted)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long with summary)</em> you allow users to write formatted text. Which options are available to individual users depends on the settings on the <a href=":formats">Text formats and editors page</a>.', [':formats' => Url::fromRoute('filter.admin_overview')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Creating short text fields') . '</dt>'; + $output .= '<dd>' . $this->t('If you choose <em>Text (plain)</em> or <em>Text (formatted)</em> as the field type on the <em>Manage fields</em> page, then a field with a single row is displayed. You can change the maximum text length in the <em>Field settings</em> when you set up the field.') . '</dd>'; + $output .= '<dt>' . $this->t('Creating long text fields') . '</dt>'; + $output .= '<dd>' . $this->t('If you choose <em>Text (plain, long)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long, with summary)</em> on the <em>Manage fields</em> page, then users can insert text of unlimited length. On the <em>Manage form display</em> page, you can set the number of rows that are displayed to users.') . '</dd>'; + $output .= '<dt>' . $this->t('Trimming the text length') . '</dt>'; + $output .= '<dd>' . $this->t('On the <em>Manage display</em> page you can choose to display a trimmed version of the text, and if so, where to cut off the text.') . '</dd>'; + $output .= '<dt>' . $this->t('Displaying summaries instead of trimmed text') . '</dt>'; + $output .= '<dd>' . $this->t('As an alternative to using a trimmed version of the text, you can enter a separate summary by choosing the <em>Text (formatted, long, with summary)</em> field type on the <em>Manage fields</em> page. Even when <em>Summary input</em> is enabled, and summaries are provided, you can display <em>trimmed</em> text nonetheless by choosing the appropriate format on the <em>Manage display</em> page.') . '</dd>'; + $output .= '<dt>' . $this->t('Using text formats and editors') . '</dt>'; + $output .= '<dd>' . $this->t('If you choose <em>Text (plain)</em> or <em>Text (plain, long)</em> you restrict the input to <em>Plain text</em> only. If you choose <em>Text (formatted)</em>, <em>Text (formatted, long)</em>, or <em>Text (formatted, long with summary)</em> you allow users to write formatted text. Which options are available to individual users depends on the settings on the <a href=":formats">Text formats and editors page</a>.', [':formats' => Url::fromRoute('filter.admin_overview')->toString()]) . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/toolbar/src/Hook/ToolbarHooks.php b/core/modules/toolbar/src/Hook/ToolbarHooks.php index 3929a65e6f928f94528ebe73a84ad613df947d57..aec157c03434e2a98e83f274bde4ba9117c237a3 100644 --- a/core/modules/toolbar/src/Hook/ToolbarHooks.php +++ b/core/modules/toolbar/src/Hook/ToolbarHooks.php @@ -2,6 +2,7 @@ namespace Drupal\toolbar\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\toolbar\Controller\ToolbarController; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -12,6 +13,8 @@ */ class ToolbarHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -19,14 +22,14 @@ class ToolbarHooks { public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.toolbar': - $output = '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Toolbar module provides a toolbar for site administrators, which displays tabs and trays provided by the Toolbar module itself and other modules. For more information, see the <a href=":toolbar_docs">online documentation for the Toolbar module</a>.', [':toolbar_docs' => 'https://www.drupal.org/docs/8/core/modules/toolbar']) . '</p>'; - $output .= '<h4>' . t('Terminology') . '</h4>'; + $output = '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Toolbar module provides a toolbar for site administrators, which displays tabs and trays provided by the Toolbar module itself and other modules. For more information, see the <a href=":toolbar_docs">online documentation for the Toolbar module</a>.', [':toolbar_docs' => 'https://www.drupal.org/docs/8/core/modules/toolbar']) . '</p>'; + $output .= '<h4>' . $this->t('Terminology') . '</h4>'; $output .= '<dl>'; - $output .= '<dt>' . t('Tabs') . '</dt>'; - $output .= '<dd>' . t('Tabs are buttons, displayed in a bar across the top of the screen. Some tabs execute an action (such as starting Edit mode), while other tabs toggle which tray is open.') . '</dd>'; - $output .= '<dt>' . t('Trays') . '</dt>'; - $output .= '<dd>' . t('Trays are usually lists of links, which can be hierarchical like a menu. If a tray has been toggled open, it is displayed either vertically or horizontally below the tab bar, depending on the browser width. Only one tray may be open at a time. If you click another tab, that tray will replace the tray being displayed. In wide browser widths, the user has the ability to toggle from vertical to horizontal, using a link at the bottom or right of the tray. Hierarchical menus only have open/close behavior in vertical mode; if you display a tray containing a hierarchical menu horizontally, only the top-level links will be available.') . '</dd>'; + $output .= '<dt>' . $this->t('Tabs') . '</dt>'; + $output .= '<dd>' . $this->t('Tabs are buttons, displayed in a bar across the top of the screen. Some tabs execute an action (such as starting Edit mode), while other tabs toggle which tray is open.') . '</dd>'; + $output .= '<dt>' . $this->t('Trays') . '</dt>'; + $output .= '<dd>' . $this->t('Trays are usually lists of links, which can be hierarchical like a menu. If a tray has been toggled open, it is displayed either vertically or horizontally below the tab bar, depending on the browser width. Only one tray may be open at a time. If you click another tab, that tray will replace the tray being displayed. In wide browser widths, the user has the ability to toggle from vertical to horizontal, using a link at the bottom or right of the tray. Hierarchical menus only have open/close behavior in vertical mode; if you display a tray containing a hierarchical menu horizontally, only the top-level links will be available.') . '</dd>'; $output .= '</dl>'; return $output; } @@ -80,10 +83,10 @@ public function toolbar(): array { '#type' => 'toolbar_item', 'tab' => [ '#type' => 'link', - '#title' => t('Back to site'), + '#title' => $this->t('Back to site'), '#url' => Url::fromRoute('<front>'), '#attributes' => [ - 'title' => t('Return to site content'), + 'title' => $this->t('Return to site content'), 'class' => [ 'toolbar-icon', 'toolbar-icon-escape-admin', @@ -116,10 +119,10 @@ public function toolbar(): array { '#type' => 'toolbar_item', 'tab' => [ '#type' => 'link', - '#title' => t('Manage'), + '#title' => $this->t('Manage'), '#url' => Url::fromRoute('system.admin'), '#attributes' => [ - 'title' => t('Admin menu'), + 'title' => $this->t('Admin menu'), 'class' => [ 'toolbar-icon', 'toolbar-icon-menu', @@ -134,7 +137,7 @@ public function toolbar(): array { ], ], 'tray' => [ - '#heading' => t('Administration menu'), + '#heading' => $this->t('Administration menu'), '#attached' => $subtrees_attached, 'toolbar_administration' => [ '#pre_render' => [ diff --git a/core/modules/update/src/Hook/UpdateHooks.php b/core/modules/update/src/Hook/UpdateHooks.php index f33078b2e80f075c2fe07647cee7122f8d656f71..0e7a748e1c96e3b36681783d2299c803be0311e8 100644 --- a/core/modules/update/src/Hook/UpdateHooks.php +++ b/core/modules/update/src/Hook/UpdateHooks.php @@ -2,6 +2,7 @@ namespace Drupal\update\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\update\UpdateManagerInterface; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; @@ -12,6 +13,8 @@ */ class UpdateHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -20,26 +23,26 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.update': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Update Manager module periodically checks for new versions of your site\'s software (including contributed modules and themes), and alerts administrators to available updates. The Update Manager system is also used by some other modules to manage updates and downloads; for example, the Interface Translation module uses the Update Manager to download translations from the localization server. Note that whenever the Update Manager system is used, anonymous usage statistics are sent to Drupal.org. If desired, you may uninstall the Update Manager module from the <a href=":modules">Extend page</a>; if you do so, functionality that depends on the Update Manager system will not work. For more information, see the <a href=":update">online documentation for the Update Manager module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Update Manager module periodically checks for new versions of your site\'s software (including contributed modules and themes), and alerts administrators to available updates. The Update Manager system is also used by some other modules to manage updates and downloads; for example, the Interface Translation module uses the Update Manager to download translations from the localization server. Note that whenever the Update Manager system is used, anonymous usage statistics are sent to Drupal.org. If desired, you may uninstall the Update Manager module from the <a href=":modules">Extend page</a>; if you do so, functionality that depends on the Update Manager system will not work. For more information, see the <a href=":update">online documentation for the Update Manager module</a>.', [ ':update' => 'https://www.drupal.org/documentation/modules/update', ':modules' => Url::fromRoute('system.modules_list')->toString(), ]) . '</p>'; // Only explain the Update manager if it has not been uninstalled. if (_update_manager_access()) { - $output .= '<p>' . t('The Update Manager also allows administrators to add and update modules and themes through the administration interface.') . '</p>'; + $output .= '<p>' . $this->t('The Update Manager also allows administrators to add and update modules and themes through the administration interface.') . '</p>'; } - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Checking for available updates') . '</dt>'; - $output .= '<dd>' . t('The <a href=":update-report">Available updates report</a> displays core, contributed modules, and themes for which there are new releases available for download. On the report page, you can also check manually for updates. You can configure the frequency of update checks, which are performed during cron runs, and whether notifications are sent on the <a href=":update-settings">Update Manager settings page</a>.', [ + $output .= '<dt>' . $this->t('Checking for available updates') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":update-report">Available updates report</a> displays core, contributed modules, and themes for which there are new releases available for download. On the report page, you can also check manually for updates. You can configure the frequency of update checks, which are performed during cron runs, and whether notifications are sent on the <a href=":update-settings">Update Manager settings page</a>.', [ ':update-report' => Url::fromRoute('update.status')->toString(), ':update-settings' => Url::fromRoute('update.settings')->toString(), ]) . '</dd>'; // Only explain the Update manager if it has not been uninstalled. if (_update_manager_access()) { - $output .= '<dt>' . t('Performing updates through the Update page') . '</dt>'; - $output .= '<dd>' . t('The Update Manager module allows administrators to perform updates directly from the <a href=":update-page">Update page</a>. It lists all available updates, and you can confirm whether you want to download them. If you don\'t have sufficient access rights to your web server, you could be prompted for your FTP/SSH password. Afterwards the files are transferred into your site installation, overwriting your old files. Direct links to the Update page are also displayed on the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>.', [ + $output .= '<dt>' . $this->t('Performing updates through the Update page') . '</dt>'; + $output .= '<dd>' . $this->t('The Update Manager module allows administrators to perform updates directly from the <a href=":update-page">Update page</a>. It lists all available updates, and you can confirm whether you want to download them. If you don\'t have sufficient access rights to your web server, you could be prompted for your FTP/SSH password. Afterwards the files are transferred into your site installation, overwriting your old files. Direct links to the Update page are also displayed on the <a href=":modules_page">Extend page</a> and the <a href=":themes_page">Appearance page</a>.', [ ':modules_page' => Url::fromRoute('system.modules_list')->toString(), ':themes_page' => Url::fromRoute('system.themes_page')->toString(), ':update-page' => Url::fromRoute('update.report_update')->toString(), @@ -49,10 +52,10 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'update.status': - return '<p>' . t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a "project", which may or may not have the same name, and might include multiple modules or themes within it.') . '</p>'; + return '<p>' . $this->t('Here you can find information about available updates for your installed modules and themes. Note that each module or theme is part of a "project", which may or may not have the same name, and might include multiple modules or themes within it.') . '</p>'; case 'system.modules_list': - return '<p>' . t('Regularly review <a href=":updates">available updates</a> and update as required to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time you update software.', [ + return '<p>' . $this->t('Regularly review <a href=":updates">available updates</a> and update as required to maintain a secure and current site. Always run the <a href=":update-php">update script</a> each time you update software.', [ ':update-php' => Url::fromRoute('system.db_update')->toString(), ':updates' => Url::fromRoute('update.status')->toString(), ]) . '</p>'; @@ -257,20 +260,20 @@ public function modulesUninstalled($modules): void { public function mail($key, &$message, $params): void { $langcode = $message['langcode']; $language = \Drupal::languageManager()->getLanguage($langcode); - $message['subject'] .= t('New release(s) available for @site_name', ['@site_name' => \Drupal::config('system.site')->get('name')], ['langcode' => $langcode]); + $message['subject'] .= $this->t('New release(s) available for @site_name', ['@site_name' => \Drupal::config('system.site')->get('name')], ['langcode' => $langcode]); foreach ($params as $msg_type => $msg_reason) { $message['body'][] = _update_message_text($msg_type, $msg_reason, $langcode); } - $message['body'][] = t('See the available updates page for more information:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.status', [], ['absolute' => TRUE, 'language' => $language])->toString(); + $message['body'][] = $this->t('See the available updates page for more information:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.status', [], ['absolute' => TRUE, 'language' => $language])->toString(); if (_update_manager_access()) { - $message['body'][] = t('You can automatically download your missing updates using the Update manager:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.report_update', [], ['absolute' => TRUE, 'language' => $language])->toString(); + $message['body'][] = $this->t('You can automatically download your missing updates using the Update manager:', [], ['langcode' => $langcode]) . "\n" . Url::fromRoute('update.report_update', [], ['absolute' => TRUE, 'language' => $language])->toString(); } $settings_url = Url::fromRoute('update.settings', [], ['absolute' => TRUE])->toString(); if (\Drupal::config('update.settings')->get('notification.threshold') == 'all') { - $message['body'][] = t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, @url.', ['@url' => $settings_url]); + $message['body'][] = $this->t('Your site is currently configured to send these emails when any updates are available. To get notified only for security updates, @url.', ['@url' => $settings_url]); } else { - $message['body'][] = t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, @url.', ['@url' => $settings_url]); + $message['body'][] = $this->t('Your site is currently configured to send these emails only when security updates are available. To get notified for any available updates, @url.', ['@url' => $settings_url]); } } @@ -293,7 +296,7 @@ public function verifyUpdateArchive($project, $archive_file, $directory): array // Make sure this isn't a tarball of Drupal core. if (file_exists("{$directory}/{$project}/index.php") && file_exists("{$directory}/{$project}/core/install.php") && file_exists("{$directory}/{$project}/core/includes/bootstrap.inc") && file_exists("{$directory}/{$project}/core/modules/node/node.module") && file_exists("{$directory}/{$project}/core/modules/system/system.module")) { return [ - 'no-core' => t('Automatic updating of Drupal core is not supported. See the <a href=":update-guide">Updating Drupal guide</a> for information on how to update Drupal core manually.', [ + 'no-core' => $this->t('Automatic updating of Drupal core is not supported. See the <a href=":update-guide">Updating Drupal guide</a> for information on how to update Drupal core manually.', [ ':update-guide' => 'https://www.drupal.org/docs/updating-drupal', ]), ]; @@ -313,7 +316,7 @@ public function verifyUpdateArchive($project, $archive_file, $directory): array $info = \Drupal::service('info_parser')->parse($file->uri); // If the module or theme is incompatible with Drupal core, set an error. if ($info['core_incompatible']) { - $incompatible[] = !empty($info['name']) ? $info['name'] : t('Unknown'); + $incompatible[] = !empty($info['name']) ? $info['name'] : $this->t('Unknown'); } else { $compatible_project = TRUE; @@ -321,7 +324,7 @@ public function verifyUpdateArchive($project, $archive_file, $directory): array } } if (empty($files)) { - $errors[] = t('%archive_file does not contain any .info.yml files.', ['%archive_file' => $file_system->basename($archive_file)]); + $errors[] = $this->t('%archive_file does not contain any .info.yml files.', ['%archive_file' => $file_system->basename($archive_file)]); } elseif (!$compatible_project) { $errors[] = \Drupal::translation()->formatPlural(count($incompatible), '%archive_file contains a version of %names that is not compatible with Drupal @version.', '%archive_file contains versions of modules or themes that are not compatible with Drupal @version: %names', [ diff --git a/core/modules/user/src/Hook/UserHooks.php b/core/modules/user/src/Hook/UserHooks.php index 838f2b5620956d997582b109d54d7a2906df7c4f..ec1ff9bc7e4132b2e609843ee9d1b02863bba962 100644 --- a/core/modules/user/src/Hook/UserHooks.php +++ b/core/modules/user/src/Hook/UserHooks.php @@ -3,6 +3,7 @@ namespace Drupal\user\Hook; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\Entity\Role; use Drupal\filter\FilterFormatInterface; use Drupal\Core\Form\FormStateInterface; @@ -25,6 +26,8 @@ */ class UserHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -33,26 +36,26 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.user': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The User module allows users to register, log in, and log out. It also allows users with proper permissions to manage user roles and permissions. For more information, see the <a href=":user_docs">online documentation for the User module</a>.', [':user_docs' => 'https://www.drupal.org/documentation/modules/user']) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The User module allows users to register, log in, and log out. It also allows users with proper permissions to manage user roles and permissions. For more information, see the <a href=":user_docs">online documentation for the User module</a>.', [':user_docs' => 'https://www.drupal.org/documentation/modules/user']) . '</p>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating and managing users') . '</dt>'; - $output .= '<dd>' . t('Through the <a href=":people">People administration page</a> you can add and cancel user accounts and assign users to roles. By editing one particular user you can change their username, email address, password, and information in other fields.', [':people' => Url::fromRoute('entity.user.collection')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Configuring user roles') . '</dt>'; - $output .= '<dd>' . t('<em>Roles</em> are used to group and classify users; each user can be assigned one or more roles. Typically there are two pre-defined roles: <em>Anonymous user</em> (users that are not logged in), and <em>Authenticated user</em> (users that are registered and logged in). Depending on how your site was set up, an <em>Administrator</em> role may also be available: users with this role will automatically be assigned any new permissions whenever a module is installed. You can create additional roles on the <a href=":roles">Roles administration page</a>.', [ + $output .= '<dt>' . $this->t('Creating and managing users') . '</dt>'; + $output .= '<dd>' . $this->t('Through the <a href=":people">People administration page</a> you can add and cancel user accounts and assign users to roles. By editing one particular user you can change their username, email address, password, and information in other fields.', [':people' => Url::fromRoute('entity.user.collection')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Configuring user roles') . '</dt>'; + $output .= '<dd>' . $this->t('<em>Roles</em> are used to group and classify users; each user can be assigned one or more roles. Typically there are two pre-defined roles: <em>Anonymous user</em> (users that are not logged in), and <em>Authenticated user</em> (users that are registered and logged in). Depending on how your site was set up, an <em>Administrator</em> role may also be available: users with this role will automatically be assigned any new permissions whenever a module is installed. You can create additional roles on the <a href=":roles">Roles administration page</a>.', [ ':roles' => Url::fromRoute('entity.user_role.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Setting permissions') . '</dt>'; - $output .= '<dd>' . t('After creating roles, you can set permissions for each role on the <a href=":permissions_user">Permissions page</a>. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing content, editing or creating a particular type of content, administering settings for a particular module, or using a particular function of the site (such as search).', [ + $output .= '<dt>' . $this->t('Setting permissions') . '</dt>'; + $output .= '<dd>' . $this->t('After creating roles, you can set permissions for each role on the <a href=":permissions_user">Permissions page</a>. Granting a permission allows users who have been assigned a particular role to perform an action on the site, such as viewing content, editing or creating a particular type of content, administering settings for a particular module, or using a particular function of the site (such as search).', [ ':permissions_user' => Url::fromRoute('user.admin_permissions')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Other permissions pages') . '</dt>'; - $output .= '<dd>' . t('The main Permissions page can be overwhelming, so each module that defines permissions has its own page for setting them. There are links to these pages on the <a href=":modules">Extend page</a>. When editing a content type, vocabulary, etc., there is also a Manage permissions tab for permissions related to that configuration.', [':modules' => Url::fromRoute('system.modules_list')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Managing account settings') . '</dt>'; - $output .= '<dd>' . t('The <a href=":accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization, and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is installed (the Administrator role).', [':accounts' => Url::fromRoute('entity.user.admin_form')->toString()]) . '</dd>'; - $output .= '<dt>' . t('Managing user account fields') . '</dt>'; - $output .= '<dd>' . t('Because User accounts are an entity type, you can extend them by adding fields through the Manage fields tab on the <a href=":accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website. For background information on entities and fields, see the <a href=":field_help">Field module help page</a>.', [ + $output .= '<dt>' . $this->t('Other permissions pages') . '</dt>'; + $output .= '<dd>' . $this->t('The main Permissions page can be overwhelming, so each module that defines permissions has its own page for setting them. There are links to these pages on the <a href=":modules">Extend page</a>. When editing a content type, vocabulary, etc., there is also a Manage permissions tab for permissions related to that configuration.', [':modules' => Url::fromRoute('system.modules_list')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Managing account settings') . '</dt>'; + $output .= '<dd>' . $this->t('The <a href=":accounts">Account settings page</a> allows you to manage settings for the displayed name of the Anonymous user role, personal contact forms, user registration settings, and account cancellation settings. On this page you can also manage settings for account personalization, and adapt the text for the email messages that users receive when they register or request a password recovery. You may also set which role is automatically assigned new permissions whenever a module is installed (the Administrator role).', [':accounts' => Url::fromRoute('entity.user.admin_form')->toString()]) . '</dd>'; + $output .= '<dt>' . $this->t('Managing user account fields') . '</dt>'; + $output .= '<dd>' . $this->t('Because User accounts are an entity type, you can extend them by adding fields through the Manage fields tab on the <a href=":accounts">Account settings page</a>. By adding fields for e.g., a picture, a biography, or address, you can a create a custom profile for the users of the website. For background information on entities and fields, see the <a href=":field_help">Field module help page</a>.', [ ':field_help' => \Drupal::moduleHandler()->moduleExists('field') ? Url::fromRoute('help.page', [ 'name' => 'field', ])->toString() : '#', @@ -62,27 +65,27 @@ public function help($route_name, RouteMatchInterface $route_match) { return $output; case 'user.admin_create': - return '<p>' . t("This web page allows administrators to register new users. Users' email addresses and usernames must be unique.") . '</p>'; + return '<p>' . $this->t("This web page allows administrators to register new users. Users' email addresses and usernames must be unique.") . '</p>'; case 'user.admin_permissions': - return '<p>' . t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href=":role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. On the <a href=":settings">Role settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all permissions. You should be careful to ensure that only trusted users are given this access and level of control of your site.', [ + return '<p>' . $this->t('Permissions let you control what users can do and see on your site. You can define a specific set of permissions for each role. (See the <a href=":role">Roles</a> page to create a role.) Any permissions granted to the Authenticated user role will be given to any user who is logged in to your site. On the <a href=":settings">Role settings</a> page, you can make any role into an Administrator role for the site, meaning that role will be granted all permissions. You should be careful to ensure that only trusted users are given this access and level of control of your site.', [ ':role' => Url::fromRoute('entity.user_role.collection')->toString(), ':settings' => Url::fromRoute('user.role.settings')->toString(), ]) . '</p>'; case 'entity.user_role.collection': - return '<p>' . t('A role defines a group of users that have certain privileges. These privileges are defined on the <a href=":permissions">Permissions page</a>. Here, you can define the names and the display sort order of the roles on your site. It is recommended to order roles from least permissive (for example, Anonymous user) to most permissive (for example, Administrator user). Users who are not logged in have the Anonymous user role. Users who are logged in have the Authenticated user role, plus any other roles granted to their user account.', [ + return '<p>' . $this->t('A role defines a group of users that have certain privileges. These privileges are defined on the <a href=":permissions">Permissions page</a>. Here, you can define the names and the display sort order of the roles on your site. It is recommended to order roles from least permissive (for example, Anonymous user) to most permissive (for example, Administrator user). Users who are not logged in have the Anonymous user role. Users who are logged in have the Authenticated user role, plus any other roles granted to their user account.', [ ':permissions' => Url::fromRoute('user.admin_permissions')->toString(), ]) . '</p>'; case 'entity.user.field_ui_fields': - return '<p>' . t('This form lets administrators add and edit fields for storing user data.') . '</p>'; + return '<p>' . $this->t('This form lets administrators add and edit fields for storing user data.') . '</p>'; case 'entity.entity_form_display.user.default': - return '<p>' . t('This form lets administrators configure how form fields should be displayed when editing a user profile.') . '</p>'; + return '<p>' . $this->t('This form lets administrators configure how form fields should be displayed when editing a user profile.') . '</p>'; case 'entity.entity_view_display.user.default': - return '<p>' . t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '</p>'; + return '<p>' . $this->t('This form lets administrators configure how fields should be displayed when rendering a user profile page.') . '</p>'; } } @@ -126,25 +129,25 @@ public function jsSettingsAlter(&$settings, AttachedAssetsInterface $assets): vo #[Hook('entity_extra_field_info')] public function entityExtraFieldInfo(): array { $fields['user']['user']['form']['account'] = [ - 'label' => t('User name and password'), - 'description' => t('User module account form elements.'), + 'label' => $this->t('User name and password'), + 'description' => $this->t('User module account form elements.'), 'weight' => -10, ]; $fields['user']['user']['form']['language'] = [ - 'label' => t('Language settings'), - 'description' => t('User module form element.'), + 'label' => $this->t('Language settings'), + 'description' => $this->t('User module form element.'), 'weight' => 0, ]; if (\Drupal::config('system.date')->get('timezone.user.configurable')) { $fields['user']['user']['form']['timezone'] = [ - 'label' => t('Timezone'), - 'description' => t('System module form element.'), + 'label' => $this->t('Timezone'), + 'description' => $this->t('System module form element.'), 'weight' => 6, ]; } $fields['user']['user']['display']['member_for'] = [ - 'label' => t('Member for'), - 'description' => t("User module 'member for' view element."), + 'label' => $this->t('Member for'), + 'description' => $this->t("User module 'member for' view element."), 'weight' => 5, ]; return $fields; @@ -172,7 +175,7 @@ public function userView(array &$build, UserInterface $account, EntityViewDispla if ($account->isAuthenticated() && $display->getComponent('member_for')) { $build['member_for'] = [ '#type' => 'item', - '#markup' => '<h4 class="label">' . t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatTimeDiffSince($account->getCreatedTime()), + '#markup' => '<h4 class="label">' . $this->t('Member for') . '</h4> ' . \Drupal::service('date.formatter')->formatTimeDiffSince($account->getCreatedTime()), ]; } } @@ -230,7 +233,7 @@ public function userLogin(UserInterface $account): void { // If the user has a NULL time zone, notify them to set a time zone. $config = \Drupal::config('system.date'); if (!$account->getTimezone() && $config->get('timezone.user.configurable') && $config->get('timezone.user.warn')) { - \Drupal::messenger()->addStatus(t('Configure your <a href=":user-edit">account time zone setting</a>.', [ + \Drupal::messenger()->addStatus($this->t('Configure your <a href=":user-edit">account time zone setting</a>.', [ ':user-edit' => $account->toUrl('edit-form', [ 'query' => \Drupal::destination()->getAsArray(), 'fragment' => 'edit-timezone', @@ -285,7 +288,7 @@ public function userRoleInsert(RoleInterface $role): void { $action = Action::create([ 'id' => $add_id, 'type' => 'user', - 'label' => t('Add the @label role to the selected user(s)', [ + 'label' => $this->t('Add the @label role to the selected user(s)', [ '@label' => $role->label(), ]), 'configuration' => [ @@ -300,7 +303,7 @@ public function userRoleInsert(RoleInterface $role): void { $action = Action::create([ 'id' => $remove_id, 'type' => 'user', - 'label' => t('Remove the @label role from the selected user(s)', [ + 'label' => $this->t('Remove the @label role from the selected user(s)', [ '@label' => $role->label(), ]), 'configuration' => [ @@ -365,7 +368,7 @@ public function toolbar(): array { '#title' => $user->getDisplayName(), '#url' => Url::fromRoute('user.page'), '#attributes' => [ - 'title' => t('My account'), + 'title' => $this->t('My account'), 'class' => [ 'toolbar-icon', 'toolbar-icon-user', @@ -379,7 +382,7 @@ public function toolbar(): array { ], ], 'tray' => [ - '#heading' => t('User account actions'), + '#heading' => $this->t('User account actions'), ], '#weight' => 100, '#attached' => [ @@ -391,7 +394,7 @@ public function toolbar(): array { if ($user->isAnonymous()) { $links = [ 'login' => [ - 'title' => t('Log in'), + 'title' => $this->t('Log in'), 'url' => Url::fromRoute('user.page'), ], ]; @@ -441,7 +444,7 @@ public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form $config = \Drupal::config('system.date'); $form['timezone']['configurable_timezones'] = [ '#type' => 'checkbox', - '#title' => t('Users may set their own time zone'), + '#title' => $this->t('Users may set their own time zone'), '#default_value' => $config->get('timezone.user.configurable'), ]; $form['timezone']['configurable_timezones_wrapper'] = [ @@ -458,20 +461,20 @@ public function formSystemRegionalSettingsAlter(&$form, FormStateInterface $form ]; $form['timezone']['configurable_timezones_wrapper']['empty_timezone_message'] = [ '#type' => 'checkbox', - '#title' => t('Remind users at login if their time zone is not set'), + '#title' => $this->t('Remind users at login if their time zone is not set'), '#default_value' => $config->get('timezone.user.warn'), - '#description' => t('Only applied if users may set their own time zone.'), + '#description' => $this->t('Only applied if users may set their own time zone.'), ]; $form['timezone']['configurable_timezones_wrapper']['user_default_timezone'] = [ '#type' => 'radios', - '#title' => t('Time zone for new users'), + '#title' => $this->t('Time zone for new users'), '#default_value' => $config->get('timezone.user.default'), '#options' => [ - UserInterface::TIMEZONE_DEFAULT => t('Default time zone'), - UserInterface::TIMEZONE_EMPTY => t('Empty time zone'), - UserInterface::TIMEZONE_SELECT => t('Users may set their own time zone at registration'), + UserInterface::TIMEZONE_DEFAULT => $this->t('Default time zone'), + UserInterface::TIMEZONE_EMPTY => $this->t('Empty time zone'), + UserInterface::TIMEZONE_SELECT => $this->t('Users may set their own time zone at registration'), ], - '#description' => t('Only applied if users may set their own time zone.'), + '#description' => $this->t('Only applied if users may set their own time zone.'), ]; $form['#submit'][] = 'user_form_system_regional_settings_submit'; } @@ -512,7 +515,7 @@ public function entityOperation(EntityInterface $entity): array { } return [ 'manage-permissions' => [ - 'title' => t('Manage permissions'), + 'title' => $this->t('Manage permissions'), 'weight' => 50, 'url' => $url, ], diff --git a/core/modules/user/src/Hook/UserTokensHooks.php b/core/modules/user/src/Hook/UserTokensHooks.php index 2305596d5d1d7f361cc85811498d034c2173741b..8cd57ecf8ca05ab4435f908e60acb88ed2737bcf 100644 --- a/core/modules/user/src/Hook/UserTokensHooks.php +++ b/core/modules/user/src/Hook/UserTokensHooks.php @@ -2,6 +2,7 @@ namespace Drupal\user\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\user\Entity\User; use Drupal\Core\Datetime\Entity\DateFormat; use Drupal\Core\Render\BubbleableMetadata; @@ -12,49 +13,51 @@ */ class UserTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $types['user'] = [ - 'name' => t('Users'), - 'description' => t('Tokens related to individual user accounts.'), + 'name' => $this->t('Users'), + 'description' => $this->t('Tokens related to individual user accounts.'), 'needs-data' => 'user', ]; $types['current-user'] = [ - 'name' => t('Current user'), - 'description' => t('Tokens related to the currently logged in user.'), + 'name' => $this->t('Current user'), + 'description' => $this->t('Tokens related to the currently logged in user.'), 'type' => 'user', ]; - $user['uid'] = ['name' => t('User ID'), 'description' => t("The unique ID of the user account.")]; - $user['uuid'] = ['name' => t('UUID'), 'description' => t("The UUID of the user account.")]; + $user['uid'] = ['name' => $this->t('User ID'), 'description' => $this->t("The unique ID of the user account.")]; + $user['uuid'] = ['name' => $this->t('UUID'), 'description' => $this->t("The UUID of the user account.")]; $user['name'] = [ - 'name' => t("Deprecated: User Name"), - 'description' => t("Deprecated: Use account-name or display-name instead."), + 'name' => $this->t("Deprecated: User Name"), + 'description' => $this->t("Deprecated: Use account-name or display-name instead."), ]; $user['account-name'] = [ - 'name' => t("Account Name"), - 'description' => t("The login name of the user account."), + 'name' => $this->t("Account Name"), + 'description' => $this->t("The login name of the user account."), ]; $user['display-name'] = [ - 'name' => t("Display Name"), - 'description' => t("The display name of the user account."), + 'name' => $this->t("Display Name"), + 'description' => $this->t("The display name of the user account."), ]; $user['mail'] = [ - 'name' => t("Email"), - 'description' => t("The email address of the user account."), + 'name' => $this->t("Email"), + 'description' => $this->t("The email address of the user account."), ]; - $user['url'] = ['name' => t("URL"), 'description' => t("The URL of the account profile page.")]; - $user['edit-url'] = ['name' => t("Edit URL"), 'description' => t("The URL of the account edit page.")]; + $user['url'] = ['name' => $this->t("URL"), 'description' => $this->t("The URL of the account profile page.")]; + $user['edit-url'] = ['name' => $this->t("Edit URL"), 'description' => $this->t("The URL of the account edit page.")]; $user['last-login'] = [ - 'name' => t("Last login"), - 'description' => t("The date the user last logged in to the site."), + 'name' => $this->t("Last login"), + 'description' => $this->t("The date the user last logged in to the site."), 'type' => 'date', ]; $user['created'] = [ - 'name' => t("Created"), - 'description' => t("The date the user account was created."), + 'name' => $this->t("Created"), + 'description' => $this->t("The date the user account was created."), 'type' => 'date', ]; return ['types' => $types, 'tokens' => ['user' => $user]]; @@ -83,7 +86,7 @@ public function tokens($type, $tokens, array $data, array $options, BubbleableMe // Basic user account information. case 'uid': // In the case of hook user_presave uid is not set yet. - $replacements[$original] = $account->id() ?: t('not yet assigned'); + $replacements[$original] = $account->id() ?: $this->t('not yet assigned'); break; case 'uuid': @@ -111,11 +114,11 @@ public function tokens($type, $tokens, array $data, array $options, BubbleableMe break; case 'url': - $replacements[$original] = $account->id() ? $account->toUrl('canonical', $url_options)->toString() : t('not yet assigned'); + $replacements[$original] = $account->id() ? $account->toUrl('canonical', $url_options)->toString() : $this->t('not yet assigned'); break; case 'edit-url': - $replacements[$original] = $account->id() ? $account->toUrl('edit-form', $url_options)->toString() : t('not yet assigned'); + $replacements[$original] = $account->id() ? $account->toUrl('edit-form', $url_options)->toString() : $this->t('not yet assigned'); break; // These tokens are default variations on the chained tokens handled @@ -123,14 +126,14 @@ public function tokens($type, $tokens, array $data, array $options, BubbleableMe case 'last-login': $date_format = DateFormat::load('medium'); $bubbleable_metadata->addCacheableDependency($date_format); - $replacements[$original] = $account->getLastLoginTime() ? \Drupal::service('date.formatter')->format($account->getLastLoginTime(), 'medium', '', NULL, $langcode) : t('never'); + $replacements[$original] = $account->getLastLoginTime() ? \Drupal::service('date.formatter')->format($account->getLastLoginTime(), 'medium', '', NULL, $langcode) : $this->t('never'); break; case 'created': $date_format = DateFormat::load('medium'); $bubbleable_metadata->addCacheableDependency($date_format); // In the case of user_presave the created date may not yet be set. - $replacements[$original] = $account->getCreatedTime() ? \Drupal::service('date.formatter')->format($account->getCreatedTime(), 'medium', '', NULL, $langcode) : t('not yet created'); + $replacements[$original] = $account->getCreatedTime() ? \Drupal::service('date.formatter')->format($account->getCreatedTime(), 'medium', '', NULL, $langcode) : $this->t('not yet created'); break; } } diff --git a/core/modules/user/src/Hook/UserViewsHooks.php b/core/modules/user/src/Hook/UserViewsHooks.php index b9c8944aea468b0650435f1433cb86a28b29afdf..04f79c42025dfe93a4f35efbb907df1425a997b3 100644 --- a/core/modules/user/src/Hook/UserViewsHooks.php +++ b/core/modules/user/src/Hook/UserViewsHooks.php @@ -3,18 +3,21 @@ namespace Drupal\user\Hook; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for user. */ class UserViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_plugins_argument_validator_alter(). */ #[Hook('views_plugins_argument_validator_alter')] public function viewsPluginsArgumentValidatorAlter(array &$plugins): void { - $plugins['entity:user']['title'] = t('User ID'); + $plugins['entity:user']['title'] = $this->t('User ID'); $plugins['entity:user']['class'] = 'Drupal\user\Plugin\views\argument_validator\User'; $plugins['entity:user']['provider'] = 'user'; } diff --git a/core/modules/views/src/Hook/ViewsHooks.php b/core/modules/views/src/Hook/ViewsHooks.php index 8d31b03d073c0f785107ddff6874a6a698337abe..24fd71646f06483f995eb88aa747712b79f50a5a 100644 --- a/core/modules/views/src/Hook/ViewsHooks.php +++ b/core/modules/views/src/Hook/ViewsHooks.php @@ -2,6 +2,7 @@ namespace Drupal\views\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\ViewsConfigUpdater; use Drupal\views\ViewEntityInterface; use Drupal\views\Plugin\Derivative\ViewsLocalTask; @@ -20,6 +21,8 @@ */ class ViewsHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -28,26 +31,26 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.views': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Views module provides a back end to fetch information from content, user accounts, taxonomy terms, and other entities from the database and present it to the user as a grid, HTML list, table, unformatted list, etc. The resulting displays are known generally as <em>views</em>.') . '</p>'; - $output .= '<p>' . t('For more information, see the <a href=":views">online documentation for the Views module</a>.', [':views' => 'https://www.drupal.org/documentation/modules/views']) . '</p>'; - $output .= '<p>' . t('In order to create and modify your own views using the administration and configuration user interface, you will need to install either the Views UI module in core or a contributed module that provides a user interface for Views. See the <a href=":views-ui">Views UI module help page</a> for more information.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Views module provides a back end to fetch information from content, user accounts, taxonomy terms, and other entities from the database and present it to the user as a grid, HTML list, table, unformatted list, etc. The resulting displays are known generally as <em>views</em>.') . '</p>'; + $output .= '<p>' . $this->t('For more information, see the <a href=":views">online documentation for the Views module</a>.', [':views' => 'https://www.drupal.org/documentation/modules/views']) . '</p>'; + $output .= '<p>' . $this->t('In order to create and modify your own views using the administration and configuration user interface, you will need to install either the Views UI module in core or a contributed module that provides a user interface for Views. See the <a href=":views-ui">Views UI module help page</a> for more information.', [ ':views-ui' => \Drupal::moduleHandler()->moduleExists('views_ui') ? Url::fromRoute('help.page', [ 'name' => 'views_ui', ])->toString() : '#', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Adding functionality to administrative pages') . '</dt>'; - $output .= '<dd>' . t('The Views module adds functionality to some core administration pages. For example, <em>admin/content</em> uses Views to filter and sort content. With Views uninstalled, <em>admin/content</em> is more limited.') . '</dd>'; - $output .= '<dt>' . t('Expanding Views functionality') . '</dt>'; - $output .= '<dd>' . t('Contributed projects that support the Views module can be found in the <a href=":node">online documentation for Views-related contributed modules</a>.', [':node' => 'https://www.drupal.org/documentation/modules/views/add-ons']) . '</dd>'; - $output .= '<dt>' . t('Improving table accessibility') . '</dt>'; - $output .= '<dd>' . t('Views tables include semantic markup to improve accessibility. Data cells are automatically associated with header cells through id and header attributes. To improve the accessibility of your tables you can add descriptive elements within the Views table settings. The <em>caption</em> element can introduce context for a table, making it easier to understand. The <em>summary</em> element can provide an overview of how the data has been organized and how to navigate the table. Both the caption and summary are visible by default and also implemented according to HTML5 guidelines.') . '</dd>'; - $output .= '<dt>' . t('Working with multilingual views') . '</dt>'; - $output .= '<dd>' . t('If your site has multiple languages and translated entities, each result row in a view will contain one translation of each involved entity (a view can involve multiple entities if it uses relationships). You can use a filter to restrict your view to one language: without filtering, if an entity has three translations it will add three rows to the results; if you filter by language, at most one result will appear (it could be zero if that particular entity does not have a translation matching your language filter choice). If a view uses relationships, each entity in the relationship needs to be filtered separately. You can filter a view to a fixed language choice, such as English or Spanish, or to the language selected by the page the view is displayed on (the language that is selected for the page by the language detection settings either for Content or User interface).') . '</dd>'; - $output .= '<dd>' . t('Because each result row contains a specific translation of each entity, field-level filters are also relative to these entity translations. For example, if your view has a filter that specifies that the entity title should contain a particular English word, you will presumably filter out all rows containing Chinese translations, since they will not contain the English word. If your view also has a second filter specifying that the title should contain a particular Chinese word, and if you are using "And" logic for filtering, you will presumably end up with no results in the view, because there are probably not any entity translations containing both the English and Chinese words in the title.') . '</dd>'; - $output .= '<dd>' . t('Independent of filtering, you can choose the display language (the language used to display the entities and their fields) via a setting on the display. Your language choices are the same as the filter language choices, with an additional choice of "Content language of view row" and "Original language of content in view row", which means to display each entity in the result row using the language that entity has or in which it was originally created. In theory, this would give you the flexibility to filter to French translations, for instance, and then display the results in Spanish. The more usual choices would be to use the same language choices for the display language and each entity filter in the view, or to use the Row language setting for the display.') . '</dd>'; + $output .= '<dt>' . $this->t('Adding functionality to administrative pages') . '</dt>'; + $output .= '<dd>' . $this->t('The Views module adds functionality to some core administration pages. For example, <em>admin/content</em> uses Views to filter and sort content. With Views uninstalled, <em>admin/content</em> is more limited.') . '</dd>'; + $output .= '<dt>' . $this->t('Expanding Views functionality') . '</dt>'; + $output .= '<dd>' . $this->t('Contributed projects that support the Views module can be found in the <a href=":node">online documentation for Views-related contributed modules</a>.', [':node' => 'https://www.drupal.org/documentation/modules/views/add-ons']) . '</dd>'; + $output .= '<dt>' . $this->t('Improving table accessibility') . '</dt>'; + $output .= '<dd>' . $this->t('Views tables include semantic markup to improve accessibility. Data cells are automatically associated with header cells through id and header attributes. To improve the accessibility of your tables you can add descriptive elements within the Views table settings. The <em>caption</em> element can introduce context for a table, making it easier to understand. The <em>summary</em> element can provide an overview of how the data has been organized and how to navigate the table. Both the caption and summary are visible by default and also implemented according to HTML5 guidelines.') . '</dd>'; + $output .= '<dt>' . $this->t('Working with multilingual views') . '</dt>'; + $output .= '<dd>' . $this->t('If your site has multiple languages and translated entities, each result row in a view will contain one translation of each involved entity (a view can involve multiple entities if it uses relationships). You can use a filter to restrict your view to one language: without filtering, if an entity has three translations it will add three rows to the results; if you filter by language, at most one result will appear (it could be zero if that particular entity does not have a translation matching your language filter choice). If a view uses relationships, each entity in the relationship needs to be filtered separately. You can filter a view to a fixed language choice, such as English or Spanish, or to the language selected by the page the view is displayed on (the language that is selected for the page by the language detection settings either for Content or User interface).') . '</dd>'; + $output .= '<dd>' . $this->t('Because each result row contains a specific translation of each entity, field-level filters are also relative to these entity translations. For example, if your view has a filter that specifies that the entity title should contain a particular English word, you will presumably filter out all rows containing Chinese translations, since they will not contain the English word. If your view also has a second filter specifying that the title should contain a particular Chinese word, and if you are using "And" logic for filtering, you will presumably end up with no results in the view, because there are probably not any entity translations containing both the English and Chinese words in the title.') . '</dd>'; + $output .= '<dd>' . $this->t('Independent of filtering, you can choose the display language (the language used to display the entities and their fields) via a setting on the display. Your language choices are the same as the filter language choices, with an additional choice of "Content language of view row" and "Original language of content in view row", which means to display each entity in the result row using the language that entity has or in which it was originally created. In theory, this would give you the flexibility to filter to French translations, for instance, and then display the results in Spanish. The more usual choices would be to use the same language choices for the display language and each entity filter in the view, or to use the Row language setting for the display.') . '</dd>'; $output .= '</dl>'; return $output; } diff --git a/core/modules/views/src/Hook/ViewsTokensHooks.php b/core/modules/views/src/Hook/ViewsTokensHooks.php index e19541844400d33e4d9c58051d20f3f5ef8d53d7..6c88c0b8236126517b9868edf5fdbbb26e01f6c8 100644 --- a/core/modules/views/src/Hook/ViewsTokensHooks.php +++ b/core/modules/views/src/Hook/ViewsTokensHooks.php @@ -4,53 +4,56 @@ use Drupal\Core\Render\BubbleableMetadata; use Drupal\Core\Hook\Attribute\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; /** * Hook implementations for views. */ class ViewsTokensHooks { + use StringTranslationTrait; + /** * Implements hook_token_info(). */ #[Hook('token_info')] public function tokenInfo(): array { $info['types']['view'] = [ - 'name' => t('View', [], [ + 'name' => $this->t('View', [], [ 'context' => 'View entity type', ]), - 'description' => t('Tokens related to views.'), + 'description' => $this->t('Tokens related to views.'), 'needs-data' => 'view', ]; - $info['tokens']['view']['label'] = ['name' => t('Label'), 'description' => t('The label of the view.')]; - $info['tokens']['view']['description'] = ['name' => t('Description'), 'description' => t('The description of the view.')]; - $info['tokens']['view']['id'] = ['name' => t('ID'), 'description' => t('The machine-readable ID of the view.')]; + $info['tokens']['view']['label'] = ['name' => $this->t('Label'), 'description' => $this->t('The label of the view.')]; + $info['tokens']['view']['description'] = ['name' => $this->t('Description'), 'description' => $this->t('The description of the view.')]; + $info['tokens']['view']['id'] = ['name' => $this->t('ID'), 'description' => $this->t('The machine-readable ID of the view.')]; $info['tokens']['view']['title'] = [ - 'name' => t('Title'), - 'description' => t('The title of current display of the view.'), + 'name' => $this->t('Title'), + 'description' => $this->t('The title of current display of the view.'), ]; - $info['tokens']['view']['url'] = ['name' => t('URL'), 'description' => t('The URL of the view.'), 'type' => 'url']; + $info['tokens']['view']['url'] = ['name' => $this->t('URL'), 'description' => $this->t('The URL of the view.'), 'type' => 'url']; $info['tokens']['view']['base-table'] = [ - 'name' => t('Base table'), - 'description' => t('The base table used for this view.'), + 'name' => $this->t('Base table'), + 'description' => $this->t('The base table used for this view.'), ]; $info['tokens']['view']['base-field'] = [ - 'name' => t('Base field'), - 'description' => t('The base field used for this view.'), + 'name' => $this->t('Base field'), + 'description' => $this->t('The base field used for this view.'), ]; $info['tokens']['view']['total-rows'] = [ - 'name' => t('Total rows'), - 'description' => t('The total amount of results returned from the view. The current display will be used.'), + 'name' => $this->t('Total rows'), + 'description' => $this->t('The total amount of results returned from the view. The current display will be used.'), ]; $info['tokens']['view']['items-per-page'] = [ - 'name' => t('Items per page'), - 'description' => t('The number of items per page.'), + 'name' => $this->t('Items per page'), + 'description' => $this->t('The number of items per page.'), ]; $info['tokens']['view']['current-page'] = [ - 'name' => t('Current page'), - 'description' => t('The current page of results the view is on.'), + 'name' => $this->t('Current page'), + 'description' => $this->t('The current page of results the view is on.'), ]; - $info['tokens']['view']['page-count'] = ['name' => t('Page count'), 'description' => t('The total page count.')]; + $info['tokens']['view']['page-count'] = ['name' => $this->t('Page count'), 'description' => $this->t('The total page count.')]; return $info; } diff --git a/core/modules/views/src/Hook/ViewsViewsHooks.php b/core/modules/views/src/Hook/ViewsViewsHooks.php index fbcbc6b11bc77e2b6d3ef077b286cec8eb67bb45..531f6c754fa2dccddcb5974f079e167354ea537a 100644 --- a/core/modules/views/src/Hook/ViewsViewsHooks.php +++ b/core/modules/views/src/Hook/ViewsViewsHooks.php @@ -3,6 +3,7 @@ namespace Drupal\views\Hook; use Drupal\Core\Entity\ContentEntityTypeInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\FieldStorageConfigInterface; use Drupal\Component\Utility\NestedArray; use Drupal\system\ActionConfigEntityInterface; @@ -13,109 +14,111 @@ */ class ViewsViewsHooks { + use StringTranslationTrait; + /** * Implements hook_views_data(). */ #[Hook('views_data')] public function viewsData(): array { - $data['views']['table']['group'] = t('Global'); + $data['views']['table']['group'] = $this->t('Global'); $data['views']['table']['join'] = ['#global' => []]; $data['views']['random'] = [ - 'title' => t('Random'), - 'help' => t('Randomize the display order.'), + 'title' => $this->t('Random'), + 'help' => $this->t('Randomize the display order.'), 'sort' => [ 'id' => 'random', ], ]; $data['views']['null'] = [ - 'title' => t('Null'), - 'help' => t('Allow a contextual filter value to be ignored. The query will not be altered by this contextual filter value. Can be used when contextual filter values come from the URL, and a part of the URL needs to be ignored.'), + 'title' => $this->t('Null'), + 'help' => $this->t('Allow a contextual filter value to be ignored. The query will not be altered by this contextual filter value. Can be used when contextual filter values come from the URL, and a part of the URL needs to be ignored.'), 'argument' => [ 'id' => 'null', ], ]; $data['views']['nothing'] = [ - 'title' => t('Custom text'), - 'help' => t('Provide custom text or link.'), + 'title' => $this->t('Custom text'), + 'help' => $this->t('Provide custom text or link.'), 'field' => [ 'id' => 'custom', 'click sortable' => FALSE, ], ]; $data['views']['counter'] = [ - 'title' => t('View result counter'), - 'help' => t('Displays the actual position of the view result'), + 'title' => $this->t('View result counter'), + 'help' => $this->t('Displays the actual position of the view result'), 'field' => [ 'id' => 'counter', ], ]; $data['views']['area'] = [ - 'title' => t('Text area'), - 'help' => t('Provide markup for the area using any available text format.'), + 'title' => $this->t('Text area'), + 'help' => $this->t('Provide markup for the area using any available text format.'), 'area' => [ 'id' => 'text', ], ]; $data['views']['area_text_custom'] = [ - 'title' => t('Unfiltered text'), - 'help' => t('Provide markup for the area with minimal filtering.'), + 'title' => $this->t('Unfiltered text'), + 'help' => $this->t('Provide markup for the area with minimal filtering.'), 'area' => [ 'id' => 'text_custom', ], ]; $data['views']['title'] = [ - 'title' => t('Title override'), - 'help' => t('Override the default view title for this view. This is useful to display an alternative title when a view is empty.'), + 'title' => $this->t('Title override'), + 'help' => $this->t('Override the default view title for this view. This is useful to display an alternative title when a view is empty.'), 'area' => [ 'id' => 'title', 'sub_type' => 'empty', ], ]; $data['views']['view'] = [ - 'title' => t('View area'), - 'help' => t('Insert a view inside an area.'), + 'title' => $this->t('View area'), + 'help' => $this->t('Insert a view inside an area.'), 'area' => [ 'id' => 'view', ], ]; $data['views']['result'] = [ - 'title' => t('Result summary'), - 'help' => t('Shows result summary, for example the items per page.'), + 'title' => $this->t('Result summary'), + 'help' => $this->t('Shows result summary, for example the items per page.'), 'area' => [ 'id' => 'result', ], ]; $data['views']['messages'] = [ - 'title' => t('Messages'), - 'help' => t('Displays messages in an area.'), + 'title' => $this->t('Messages'), + 'help' => $this->t('Displays messages in an area.'), 'area' => [ 'id' => 'messages', ], ]; $data['views']['http_status_code'] = [ - 'title' => t('Response status code'), - 'help' => t('Alter the HTTP response status code used by this view, mostly helpful for empty results.'), + 'title' => $this->t('Response status code'), + 'help' => $this->t('Alter the HTTP response status code used by this view, mostly helpful for empty results.'), 'area' => [ 'id' => 'http_status_code', ], ]; $data['views']['combine'] = [ - 'title' => t('Combine fields filter'), - 'help' => t('Combine multiple fields together and search by them.'), + 'title' => $this->t('Combine fields filter'), + 'help' => $this->t('Combine multiple fields together and search by them.'), 'filter' => [ 'id' => 'combine', ], ]; $data['views']['dropbutton'] = [ - 'title' => t('Dropbutton'), - 'help' => t('Display fields in a dropbutton.'), + 'title' => $this->t('Dropbutton'), + 'help' => $this->t('Display fields in a dropbutton.'), 'field' => [ 'id' => 'dropbutton', ], ]; $data['views']['display_link'] = [ - 'title' => t('Link to display'), - 'help' => t('Displays a link to a path-based display of this view while keeping the filter criteria, sort criteria, pager settings and contextual filters.'), + 'title' => $this->t('Link to display'), + 'help' => $this->t('Displays a link to a path-based display of this view while keeping the filter criteria, sort criteria, pager settings and contextual filters.'), 'area' => [ 'id' => 'display_link', ], @@ -126,10 +129,10 @@ public function viewsData(): array { if ($entity_type->hasViewBuilderClass()) { $label = $entity_type->getLabel(); $data['views']['entity_' . $entity_type_id] = [ - 'title' => t('Rendered entity - @label', [ + 'title' => $this->t('Rendered entity - @label', [ '@label' => $label, ]), - 'help' => t('Displays a rendered @label entity in an area.', [ + 'help' => $this->t('Displays a rendered @label entity in an area.', [ '@label' => $label, ]), 'area' => [ @@ -148,8 +151,8 @@ public function viewsData(): array { continue; } $data[$entity_info->getBaseTable()][$entity_type . '_bulk_form'] = [ - 'title' => t('Bulk update'), - 'help' => t('Allows users to apply an action to one or more items.'), + 'title' => $this->t('Bulk update'), + 'help' => $this->t('Allows users to apply an action to one or more items.'), 'field' => [ 'id' => 'bulk_form', ], @@ -240,10 +243,10 @@ public function fieldViewsData(FieldStorageConfigInterface $field_storage): arra // field. $args = ['@label' => $target_entity_type->getLabel(), '@field_name' => $field_name]; $data[$table_name][$field_name]['relationship'] = [ - 'title' => t('@label referenced from @field_name', $args), - 'label' => t('@field_name: @label', $args), + 'title' => $this->t('@label referenced from @field_name', $args), + 'label' => $this->t('@field_name: @label', $args), 'group' => $entity_type->getLabel(), - 'help' => t('Appears in: @bundles.', [ + 'help' => $this->t('Appears in: @bundles.', [ '@bundles' => implode(', ', $field_storage->getBundles()), ]), 'id' => 'standard', @@ -258,12 +261,12 @@ public function fieldViewsData(FieldStorageConfigInterface $field_storage): arra $args['@label'] = $target_entity_type->getSingularLabel(); $pseudo_field_name = 'reverse__' . $entity_type_id . '__' . $field_name; $data[$target_base_table][$pseudo_field_name]['relationship'] = [ - 'title' => t('@entity using @field_name', $args), - 'label' => t('@field_name', [ + 'title' => $this->t('@entity using @field_name', $args), + 'label' => $this->t('@field_name', [ '@field_name' => $field_name, ]), 'group' => $target_entity_type->getLabel(), - 'help' => t('Relate each @entity with a @field_name set to the @label.', $args), + 'help' => $this->t('Relate each @entity with a @field_name set to the @label.', $args), 'id' => 'entity_reverse', 'base' => $entity_type->getDataTable() ?: $entity_type->getBaseTable(), 'entity_type' => $entity_type_id, diff --git a/core/modules/views_ui/src/Hook/ViewsUiHooks.php b/core/modules/views_ui/src/Hook/ViewsUiHooks.php index 88a3e363c1643d48c26766e66469a4a8829ed65a..da70548154f362e746a2e860a068390f9732c5f5 100644 --- a/core/modules/views_ui/src/Hook/ViewsUiHooks.php +++ b/core/modules/views_ui/src/Hook/ViewsUiHooks.php @@ -2,6 +2,7 @@ namespace Drupal\views_ui\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\views\Entity\View; use Drupal\block\BlockInterface; use Drupal\Core\Entity\EntityInterface; @@ -16,6 +17,8 @@ */ class ViewsUiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -24,29 +27,29 @@ public function help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { case 'help.page.views_ui': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Views UI module provides an interface for managing views for the <a href=":views">Views module</a>. For more information, see the <a href=":handbook">online documentation for the Views UI module</a>.', [ + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Views UI module provides an interface for managing views for the <a href=":views">Views module</a>. For more information, see the <a href=":handbook">online documentation for the Views UI module</a>.', [ ':views' => Url::fromRoute('help.page', [ 'name' => 'views', ])->toString(), ':handbook' => 'https://www.drupal.org/documentation/modules/views_ui', ]) . '</p>'; - $output .= '<h2>' . t('Uses') . '</h2>'; + $output .= '<h2>' . $this->t('Uses') . '</h2>'; $output .= '<dl>'; - $output .= '<dt>' . t('Creating and managing views') . '</dt>'; - $output .= '<dd>' . t('Views can be created from the <a href=":list">Views list page</a> by using the "Add view" action. Existing views can be managed from the <a href=":list">Views list page</a> by locating the view in the "Enabled" or "Disabled" list and selecting the desired operation action, for example "Edit".', [ + $output .= '<dt>' . $this->t('Creating and managing views') . '</dt>'; + $output .= '<dd>' . $this->t('Views can be created from the <a href=":list">Views list page</a> by using the "Add view" action. Existing views can be managed from the <a href=":list">Views list page</a> by locating the view in the "Enabled" or "Disabled" list and selecting the desired operation action, for example "Edit".', [ ':list' => Url::fromRoute('entity.view.collection', [ 'name' => 'views_ui', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Enabling and disabling views') . '<dt>'; - $output .= '<dd>' . t('Views can be enabled or disabled from the <a href=":list">Views list page</a>. To enable a view, find the view within the "Disabled" list and select the "Enable" operation. To disable a view find the view within the "Enabled" list and select the "Disable" operation.', [ + $output .= '<dt>' . $this->t('Enabling and disabling views') . '<dt>'; + $output .= '<dd>' . $this->t('Views can be enabled or disabled from the <a href=":list">Views list page</a>. To enable a view, find the view within the "Disabled" list and select the "Enable" operation. To disable a view find the view within the "Enabled" list and select the "Disable" operation.', [ ':list' => Url::fromRoute('entity.view.collection', [ 'name' => 'views_ui', ])->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Exporting and importing views') . '</dt>'; - $output .= '<dd>' . t('Views can be exported and imported as configuration files by using the <a href=":config">Configuration Manager module</a>.', [ + $output .= '<dt>' . $this->t('Exporting and importing views') . '</dt>'; + $output .= '<dd>' . $this->t('Views can be exported and imported as configuration files by using the <a href=":config">Configuration Manager module</a>.', [ ':config' => \Drupal::moduleHandler()->moduleExists('config') ? Url::fromRoute('help.page', [ 'name' => 'config', ])->toString() : '#', @@ -197,7 +200,7 @@ public function viewsAnalyze(ViewExecutable $view): array { $ret = []; // Check for something other than the default display: if (count($view->displayHandlers) < 2) { - $ret[] = Analyzer::formatMessage(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning'); + $ret[] = Analyzer::formatMessage($this->t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning'); } // If a display has a path, check that it does not match an existing path // alias. This results in the path alias not working. @@ -208,7 +211,7 @@ public function viewsAnalyze(ViewExecutable $view): array { if ($display->hasPath() && ($path = $display->getOption('path'))) { $normal_path = \Drupal::service('path_alias.manager')->getPathByAlias($path); if ($path != $normal_path) { - $ret[] = Analyzer::formatMessage(t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', ['%display' => $display->display['display_title']]), 'warning'); + $ret[] = Analyzer::formatMessage($this->t('You have configured display %display with a path which is an path alias as well. This might lead to unwanted effects so better use an internal path.', ['%display' => $display->display['display_title']]), 'warning'); } } } @@ -230,7 +233,7 @@ public function entityOperation(EntityInterface $entity) : array { $view = View::load($view_id); if ($view && $view->access('edit')) { $operations['view-edit'] = [ - 'title' => t('Edit view'), + 'title' => $this->t('Edit view'), 'url' => Url::fromRoute('entity.view.edit_display_form', [ 'view' => $view_id, 'display_id' => $display_id, diff --git a/core/modules/workflows/src/Hook/WorkflowsHooks.php b/core/modules/workflows/src/Hook/WorkflowsHooks.php index 6fe0cf68dca0d8a24bd811151e54c079882baf15..833a493bf213d3d845ebda13c3d4de10944594f2 100644 --- a/core/modules/workflows/src/Hook/WorkflowsHooks.php +++ b/core/modules/workflows/src/Hook/WorkflowsHooks.php @@ -2,6 +2,7 @@ namespace Drupal\workflows\Hook; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Hook\Attribute\Hook; @@ -11,6 +12,8 @@ */ class WorkflowsHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,38 +25,38 @@ public function help($route_name, RouteMatchInterface $route_match) { if (\Drupal::moduleHandler()->moduleExists('content_moderation')) { $content_moderation_url = Url::fromRoute('help.page', ['name' => 'content_moderation'])->toString(); } - $output = '<h2>' . t('About') . '</h2>'; + $output = '<h2>' . $this->t('About') . '</h2>'; if ($content_moderation_url) { - $output .= '<p>' . t('The Workflows module provides an API and an interface to create workflows with transitions between different states (for example publication or user status). These have to be provided by other modules such as the <a href=":moderation">Content Moderation module</a>. For more information, see the <a href=":workflow">online documentation for the Workflows module</a>.', [ + $output .= '<p>' . $this->t('The Workflows module provides an API and an interface to create workflows with transitions between different states (for example publication or user status). These have to be provided by other modules such as the <a href=":moderation">Content Moderation module</a>. For more information, see the <a href=":workflow">online documentation for the Workflows module</a>.', [ ':moderation' => $content_moderation_url, ':workflow' => 'https://www.drupal.org/documentation/modules/workflows', ]) . '</p>'; } else { - $output .= '<p>' . t('The Workflows module provides an API and an interface to create workflows with transitions between different states (for example publication or user status). These have to be provided by other modules such as the Content Moderation module. For more information, see the <a href=":workflow">online documentation for the Workflows module</a>.', [':workflow' => 'https://www.drupal.org/documentation/modules/workflows']) . '</p>'; + $output .= '<p>' . $this->t('The Workflows module provides an API and an interface to create workflows with transitions between different states (for example publication or user status). These have to be provided by other modules such as the Content Moderation module. For more information, see the <a href=":workflow">online documentation for the Workflows module</a>.', [':workflow' => 'https://www.drupal.org/documentation/modules/workflows']) . '</p>'; } - $output .= '<h3>' . t('Uses') . '</h3>'; + $output .= '<h3>' . $this->t('Uses') . '</h3>'; $output .= '<dl>'; - $output .= '<dt>' . t('Adding workflows') . '</dt>'; + $output .= '<dt>' . $this->t('Adding workflows') . '</dt>'; if ($content_moderation_url) { - $output .= '<dd>' . t('You can <em>only</em> add workflows on the <a href=":workflows">Workflows page</a>, after you have installed a module that leverages the API such as the <a href=":moderation">Content Moderation module</a>.', [ + $output .= '<dd>' . $this->t('You can <em>only</em> add workflows on the <a href=":workflows">Workflows page</a>, after you have installed a module that leverages the API such as the <a href=":moderation">Content Moderation module</a>.', [ ':moderation' => $content_moderation_url, ':workflows' => Url::fromRoute('entity.workflow.collection')->toString(), ]) . '</dd>'; } else { - $output .= '<dd>' . t('You can <em>only</em> add workflows on the <a href=":workflows">Workflows page</a>, after you have installed a module that leverages the API such as the Content Moderation module.', [':workflow' => 'https://www.drupal.org/documentation/modules/workflows']) . '</dd>'; + $output .= '<dd>' . $this->t('You can <em>only</em> add workflows on the <a href=":workflows">Workflows page</a>, after you have installed a module that leverages the API such as the Content Moderation module.', [':workflow' => 'https://www.drupal.org/documentation/modules/workflows']) . '</dd>'; } - $output .= '<dt>' . t('Adding states') . '<dt>'; - $output .= '<dd>' . t('A workflow requires at least two states. States can be added when you add or edit a workflow on the <a href=":workflows">Workflows page</a>.', [ + $output .= '<dt>' . $this->t('Adding states') . '<dt>'; + $output .= '<dd>' . $this->t('A workflow requires at least two states. States can be added when you add or edit a workflow on the <a href=":workflows">Workflows page</a>.', [ ':workflows' => Url::fromRoute('entity.workflow.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Adding transitions') . '</dt>'; - $output .= '<dd>' . t('A transition defines in which state an item can be save as next. It has one destination state, but can have several states <em>from</em> which the transition can be applied. Transitions can be added when you add or edit a workflow on the <a href=":workflows">Workflows page</a>.', [ + $output .= '<dt>' . $this->t('Adding transitions') . '</dt>'; + $output .= '<dd>' . $this->t('A transition defines in which state an item can be save as next. It has one destination state, but can have several states <em>from</em> which the transition can be applied. Transitions can be added when you add or edit a workflow on the <a href=":workflows">Workflows page</a>.', [ ':workflows' => Url::fromRoute('entity.workflow.collection')->toString(), ]) . '</dd>'; - $output .= '<dt>' . t('Configuring workflows further') . '</dt>'; - $output .= '<dd>' . t('Depending on the installed workflow type, additional configuration can be available in the edit form of a workflow.') . '</dd>'; + $output .= '<dt>' . $this->t('Configuring workflows further') . '</dt>'; + $output .= '<dd>' . $this->t('Depending on the installed workflow type, additional configuration can be available in the edit form of a workflow.') . '</dd>'; $output .= '<dl>'; return $output; } diff --git a/core/modules/workspaces_ui/src/Hook/WorkspacesUiHooks.php b/core/modules/workspaces_ui/src/Hook/WorkspacesUiHooks.php index e1c19eb17591bd5fbce3f599383170c24bcc83e8..83c4a64d0ec187afeb6b752ef33d1d2f20430415 100644 --- a/core/modules/workspaces_ui/src/Hook/WorkspacesUiHooks.php +++ b/core/modules/workspaces_ui/src/Hook/WorkspacesUiHooks.php @@ -6,6 +6,7 @@ use Drupal\Core\Hook\Attribute\Hook; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\Url; /** @@ -13,6 +14,8 @@ */ class WorkspacesUiHooks { + use StringTranslationTrait; + /** * Implements hook_help(). */ @@ -22,8 +25,8 @@ public function help($route_name, RouteMatchInterface $route_match): ?string { // Main module help for the Workspaces UI module. case 'help.page.workspaces_ui': $output = ''; - $output .= '<h2>' . t('About') . '</h2>'; - $output .= '<p>' . t('The Workspaces UI module provides an interface for managing workspaces for the <a href=":workspaces_module">Workspaces module</a>. For more information, see the <a href=":workspaces">online documentation for the Workspaces UI module</a>.', [':workspaces_module' => Url::fromRoute('help.page', ['name' => 'workspaces'])->toString(), ':workspaces' => 'https://www.drupal.org/docs/8/core/modules/workspace/overview']) . '</p>'; + $output .= '<h2>' . $this->t('About') . '</h2>'; + $output .= '<p>' . $this->t('The Workspaces UI module provides an interface for managing workspaces for the <a href=":workspaces_module">Workspaces module</a>. For more information, see the <a href=":workspaces">online documentation for the Workspaces UI module</a>.', [':workspaces_module' => Url::fromRoute('help.page', ['name' => 'workspaces'])->toString(), ':workspaces' => 'https://www.drupal.org/docs/8/core/modules/workspace/overview']) . '</p>'; return $output; } return NULL; @@ -58,7 +61,7 @@ public function toolbar(): array { '#create_placeholder' => TRUE, '#lazy_builder_preview' => [ '#type' => 'link', - '#title' => $active_workspace ? $active_workspace->label() : t('Live'), + '#title' => $active_workspace ? $active_workspace->label() : $this->t('Live'), '#url' => Url::fromRoute('entity.workspace.collection'), '#attributes' => [ 'class' => ['toolbar-tray-lazy-placeholder-link'], diff --git a/core/phpcs.xml.dist b/core/phpcs.xml.dist index 1b7413ebf148b037e731d923c47b03370685b96f..b8902c685c702b3457c35a0afd482ab7cabc99b2 100644 --- a/core/phpcs.xml.dist +++ b/core/phpcs.xml.dist @@ -181,7 +181,7 @@ <include-pattern>*/tests/*</include-pattern> <include-pattern>./core/lib/*</include-pattern> <include-pattern>./core/modules/*</include-pattern> - <exclude-pattern>./core/modules/*/Hook/*</exclude-pattern> + <include-pattern>*/Hook/*</include-pattern> </rule> <!-- Generic sniffs -->