diff --git a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php index 50dffe2..b044aa7 100644 --- a/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php +++ b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php @@ -15,6 +15,7 @@ use Drupal\locale\Form\TranslateFilterForm; use Drupal\locale\Form\TranslateEditForm; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; +use Drupal\Core\StringTranslation\Translator\TranslatorInterface; /** * Return response for manual check translations. @@ -26,24 +27,31 @@ class LocaleController implements ControllerInterface { * @var \Drupal\Core\Extension\ModuleHandlerInterface */ protected $moduleHandler; - + /** - * The state store. + * The container. * - * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + * @var \Symfony\Component\DependencyInjection\ContainerInterface */ - protected $state; + protected $container; /** - * Constructs a \Drupal\locale\Controller\LocaleController object. + * * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. */ - public function __construct(ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, KeyValueStoreInterface $state) { + /** + * Constructs a \Drupal\locale\Controller\LocaleController object. + * + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * @param \Drupal\Core\Routing\PathBasedGeneratorInterface $url_generator + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + */ + public function __construct(ModuleHandlerInterface $module_handler, PathBasedGeneratorInterface $url_generator, ContainerInterface $container) { $this->moduleHandler = $module_handler; $this->urlGenerator = $url_generator; - $this->state = $state; + $this->container = $container; } /** @@ -53,8 +61,7 @@ public static function create(ContainerInterface $container) { return new static( $container->get('module_handler'), $container->get('url_generator'), - $container->get('keyvalue')->get('state'), - $container->get('string_translation') + $container ); } @@ -90,9 +97,10 @@ public function checkTranslation() { * @see locale_menu() */ public function translatePage() { + $state = $this->container->get('keyvalue')->get('state'); return array( - 'filter' => drupal_get_form(new TranslateFilterForm($this->state)), - 'form' => drupal_get_form(new TranslateEditForm($this->state)), + 'filter' => drupal_get_form(new TranslateFilterForm($state)), + 'form' => drupal_get_form(new TranslateEditForm($state, $this->container->get('string_translation'), $this->container->get('locale.storage'))), ); } } diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php index 2bad51b..4f8b644 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php @@ -7,14 +7,22 @@ namespace Drupal\locale\Form; +use Symfony\Component\HttpFoundation\Request; use Drupal\Core\Form\FormInterface; use Drupal\locale\SourceString; use Drupal\node\NodeInterface; use Drupal\Core\KeyValueStore\KeyValueStoreInterface; use Drupal\Core\StringTranslation\Translator\TranslatorInterface; +use Drupal\locale\StringDatabaseStorage; class TranslateEditForm extends TranslateFormBase implements FormInterface { + /** + * The state store. + * + * @var \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + protected $state; /** * The translator service. @@ -25,11 +33,25 @@ class TranslateEditForm extends TranslateFormBase implements FormInterface { /** + * The locale storage. + * + * @var \Drupal\locale\StringDatabaseStorage + */ + protected $localStorage; + + + /** * Constructs a TranslateEditFrom object. */ - public function __construct(KeyValueStoreInterface $state, TranslatorInterface $translator) { + /** + * @param \Drupal\Core\KeyValueStore\KeyValueStoreInterface $state + * @param \Drupal\Core\StringTranslation\Translator\TranslatorInterface $translator + * @param \Drupal\locale\StringDatabaseStorage $local_storage + */ + public function __construct(KeyValueStoreInterface $state, TranslatorInterface $translator, StringDatabaseStorage $local_storage) { $this->state = $state; $this->translator = $translator; + $this->localStorage = $local_storage; } /** @@ -88,7 +110,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = ); $form['strings'][$string->lid]['original'] = array( '#type' => 'item', - '#title' => t('Source string'), + '#title' => $this->translator->translate('Source string'), '#title_display' => 'invisible', '#markup' => check_plain($source_array[0]), ); @@ -101,12 +123,12 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = ); $form['strings'][$string->lid]['original_singular'] = array( '#type' => 'item', - '#title' => t('Singular form'), + '#title' => $this->translator->translate('Singular form'), '#markup' => check_plain($source_array[0]), ); $form['strings'][$string->lid]['original_plural'] = array( '#type' => 'item', - '#title' => t('Plural form'), + '#title' => $this->translator->translate('Plural form'), '#markup' => check_plain($source_array[1]), ); } @@ -121,7 +143,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = if (empty($form['strings'][$string->lid]['plural']['#value'])) { $form['strings'][$string->lid]['translations'][0] = array( '#type' => 'textarea', - '#title' => t('Translated string'), + '#title' => $this->translator->translate('Translated string'), '#title_display' => 'invisible', '#rows' => $rows, '#default_value' => $translation_array[0], @@ -134,7 +156,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = for ($i = 0; $i < $plural_formulas[$langcode]['plurals']; $i++) { $form['strings'][$string->lid]['translations'][$i] = array( '#type' => 'textarea', - '#title' => ($i == 0 ? t('Singular form') : format_plural($i, 'First plural form', '@count. plural form')), + '#title' => ($i == 0 ? $this->translator->translate('Singular form') : format_plural($i, 'First plural form', '@count. plural form')), '#rows' => $rows, '#default_value' => isset($translation_array[$i]) ? $translation_array[$i] : '', ); @@ -144,13 +166,13 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = // Fallback for unknown number of plurals. $form['strings'][$string->lid]['translations'][0] = array( '#type' => 'textarea', - '#title' => t('Singular form'), + '#title' => $this->translator->translate('Singular form'), '#rows' => $rows, '#default_value' => $translation_array[0], ); $form['strings'][$string->lid]['translations'][1] = array( '#type' => 'textarea', - '#title' => t('Plural form'), + '#title' => $this->translator->translate('Plural form'), '#rows' => $rows, '#default_value' => isset($translation_array[1]) ? $translation_array[1] : '', ); @@ -161,7 +183,7 @@ public function buildForm(array $form, array &$form_state, NodeInterface $node = $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Save translations')); + '#value' => $this->translator->translate('Save translations')); } } return $form; @@ -175,8 +197,8 @@ public function validateForm(array &$form, array &$form_state) { foreach ($form_state['values']['strings'] as $lid => $translations) { foreach ($translations['translations'] as $key => $value) { if (!locale_string_is_safe($value)) { - form_set_error("strings][$lid][translations][$key", t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); - form_set_error("translations][$langcode][$key", t('The submitted string contains disallowed HTML: %string', array('%string' => $value))); + form_set_error("strings][$lid][translations][$key", $this->translator->translate('The submitted string contains disallowed HTML: %string', array('%string' => $value))); + form_set_error("translations][$langcode][$key", $this->translator->translate('The submitted string contains disallowed HTML: %string', array('%string' => $value))); watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING); } } @@ -186,14 +208,14 @@ public function validateForm(array &$form, array &$form_state) { /** * {@inheritdoc} */ - public function submitForm(array &$form, array &$form_state) { + public function submitForm(array &$form, array &$form_state, Request $request = NULL) { $langcode = $form_state['values']['langcode']; $updated = array(); // Preload all translations for strings in the form. $lids = array_keys($form_state['values']['strings']); $existing_translation_objects = array(); - foreach (\Drupal::service('locale.storage')->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { + foreach ($this->localStorage->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { $existing_translation_objects[$existing_translation_object->lid] = $existing_translation_object; } @@ -222,7 +244,7 @@ public function submitForm(array &$form, array &$form_state) { if ($is_changed) { // Only update or insert if we have a value to use. - $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : \Drupal::service('locale.storage')->createTranslation(array('lid' => $lid, 'language' => $langcode)); + $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : $this->localStorage->createTranslation(array('lid' => $lid, 'language' => $langcode)); $target->setPlurals($new_translation['translations']) ->setCustomized() ->save(); @@ -235,11 +257,12 @@ public function submitForm(array &$form, array &$form_state) { } } - drupal_set_message(t('The strings have been saved.')); + drupal_set_message($this->translator->translate('The strings have been saved.')); // Keep the user on the current pager page. - if (isset($_GET['page'])) { - $form_state['redirect'] = array('admin/config/regional/translate', array('query' => array('page' => $_GET['page']))); + $page = $request->query->get('page'); + if (isset($page)) { + $form_state['redirect'] = array('admin/config/regional/translate', array('query' => array('page' => $page))); } if ($updated) {