diff --git a/core/lib/Drupal/Core/Form/ConfirmFormBase.php b/core/lib/Drupal/Core/Form/ConfirmFormBase.php index 2aedb41..5f38839 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormBase.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php @@ -7,10 +7,12 @@ namespace Drupal\Core\Form; +use Drupal\Core\StringTranslation\TranslationBase; + /** * Provides an generic base class for a confirmation form. */ -abstract class ConfirmFormBase implements FormInterface { +abstract class ConfirmFormBase extends TranslationBase implements FormInterface { /** * Returns the question to ask the user. @@ -40,7 +42,7 @@ * The form description. */ protected function getDescription() { - return t('This action cannot be undone.'); + return $this->translate('This action cannot be undone.'); } /** @@ -50,7 +52,7 @@ protected function getDescription() { * The form confirmation text. */ protected function getConfirmText() { - return t('Confirm'); + return $this->translate('Confirm'); } /** @@ -60,7 +62,7 @@ protected function getConfirmText() { * The form cancellation text. */ protected function getCancelText() { - return t('Cancel'); + return $this->translate('Cancel'); } /** diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationBase.php b/core/lib/Drupal/Core/StringTranslation/TranslationBase.php new file mode 100644 index 0000000..17ec375 --- /dev/null +++ b/core/lib/Drupal/Core/StringTranslation/TranslationBase.php @@ -0,0 +1,57 @@ +translation = $translation; + } + + /** + * Retrieves the string translation service to use. + * + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The string translation service. + */ + protected function getTranslation() { + if (!$this->translation) { + $this->translation = \Drupal::translation(); + } + return $this->translation; + } + + /** + * Translates a string to the current language or to a given language. + * + * @return string + * The translated string. + * + * @see \Drupal\Core\StringTranslation\TranslationInterface::translate() + */ + protected function translate($string, array $args = array(), array $options = array()) { + return $this->getTranslation()->translate($string, $args, $options); + } + +} diff --git a/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php new file mode 100644 index 0000000..3a6474a --- /dev/null +++ b/core/lib/Drupal/Core/StringTranslation/TranslationInterface.php @@ -0,0 +1,34 @@ +hasConfigurableActions) { unset($build['action_table']['#header']['operations']); } - $build['action_admin_manage_form'] = drupal_get_form(new ActionAdminManageForm($this->actionManager)); + $build['action_admin_manage_form'] = drupal_get_form(ActionAdminManageForm::create(\Drupal::getContainer())); return $build; } diff --git a/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php index d0244b1..512e536 100644 --- a/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php +++ b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php @@ -11,12 +11,14 @@ use Drupal\Core\Form\FormInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Action\ActionManager; +use Drupal\Core\StringTranslation\TranslationBase; +use Drupal\Core\StringTranslation\TranslationInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Provides a configuration form for configurable actions. */ -class ActionAdminManageForm implements FormInterface, ControllerInterface { +class ActionAdminManageForm extends TranslationBase implements FormInterface, ControllerInterface { /** * The action plugin manager. @@ -30,9 +32,12 @@ class ActionAdminManageForm implements FormInterface, ControllerInterface { * * @param \Drupal\Core\Action\ActionManager $manager * The action plugin manager. + * @return \Drupal\Core\StringTranslation\TranslationInterface + * The string translation service. */ - public function __construct(ActionManager $manager) { + public function __construct(ActionManager $manager, TranslationInterface $translation) { $this->manager = $manager; + $this->setTranslation($translation); } /** @@ -40,7 +45,8 @@ public function __construct(ActionManager $manager) { */ public static function create(ContainerInterface $container) { return new static( - $container->get('plugin.manager.action') + $container->get('plugin.manager.action'), + $container->get('string_translation') ); } @@ -64,22 +70,22 @@ public function buildForm(array $form, array &$form_state) { } $form['parent'] = array( '#type' => 'details', - '#title' => t('Create an advanced action'), + '#title' => $this->translate('Create an advanced action'), '#attributes' => array('class' => array('container-inline')), ); $form['parent']['action'] = array( '#type' => 'select', - '#title' => t('Action'), + '#title' => $this->translate('Action'), '#title_display' => 'invisible', '#options' => $actions, - '#empty_option' => t('Choose an advanced action'), + '#empty_option' => $this->translate('Choose an advanced action'), ); $form['parent']['actions'] = array( '#type' => 'actions' ); $form['parent']['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Create'), + '#value' => $this->translate('Create'), ); return $form; } diff --git a/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php index eb82bdc..ee71d47 100644 --- a/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php +++ b/core/modules/system/lib/Drupal/system/SystemConfigFormBase.php @@ -11,12 +11,13 @@ use Drupal\Core\Controller\ControllerInterface; use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Config\Context\ContextInterface; +use Drupal\Core\StringTranslation\TranslationBase; use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for implementing system configuration forms. */ -abstract class SystemConfigFormBase implements FormInterface, ControllerInterface { +abstract class SystemConfigFormBase extends TranslationBase implements FormInterface, ControllerInterface { /** * Stores the configuration factory. @@ -55,7 +56,7 @@ public function buildForm(array $form, array &$form_state) { $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Save configuration'), + '#value' => $this->translate('Save configuration'), '#button_type' => 'primary', ); @@ -75,7 +76,7 @@ public function validateForm(array &$form, array &$form_state) { * Implements \Drupal\Core\Form\FormInterface::submitForm(). */ public function submitForm(array &$form, array &$form_state) { - drupal_set_message(t('The configuration options have been saved.')); + drupal_set_message($this->translate('The configuration options have been saved.')); } }