reverted: --- b/core/modules/locale/lib/Drupal/locale/Controller/LocaleController.php +++ /dev/null @@ -1,54 +0,0 @@ -get('keyvalue')->get('state')); - } - - /** - * Constructs a TranslateEditForm object. - */ - public function __construct(KeyValueStoreInterface $state) { - $this->state = $state; - } - - /** - * Page callback: Shows the string search screen. - * - * @see locale_menu() - */ - public function translatePage() { - - return array( - 'filter' => drupal_get_form(new TranslateFilterForm($this->state)), - 'form' => drupal_get_form(new TranslateEditForm($this->state)), - ); - } - -} diff -u b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php --- b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateEditForm.php @@ -9,8 +9,17 @@ use Drupal\Core\Form\FormInterface; use Drupal\locale\SourceString; +use Drupal\node\NodeInterface; +use Drupal\Core\KeyValueStore\KeyValueStoreInterface; -class TranslateEditForm implements FormInterface { +class TranslateEditForm extends TranslateFormBase implements FormInterface { + + /** + * Constructs a TranslateEditFrom object. + */ + public function __construct(KeyValueStoreInterface $state) { + $this->state = $state; + } /** * {@inheritdoc} @@ -22,9 +31,8 @@ /** * {@inheritdoc} */ - public function buildForm(array $form, array &$form_state, Node $node = NULL) { - - $filter_values = locale_translate_filter_values(); + public function buildForm(array $form, array &$form_state, NodeInterface $node = NULL) { + $filter_values = $this->translateFilterValues(); $langcode = $filter_values['langcode']; drupal_static_reset('language_list'); @@ -34,7 +42,7 @@ $path = drupal_get_path('module', 'locale'); $form['#attached']['css'] = array( - $path . '/locale.admin.css', + $path . '/css/locale.admin.css', ); $form['#attached']['library'][] = array('locale', 'drupal.locale.admin'); @@ -51,9 +59,9 @@ ); if (isset($langcode)) { - $strings = locale_translate_filter_load_strings(); + $strings = $this->translateFilterLoadStrings(); - $plural_formulas = state()->get('locale.translation.plurals') ?: array(); + $plural_formulas = $this->state->get('locale.translation.plurals') ?: array(); foreach ($strings as $string) { // Cast into source string, will do for our purposes. @@ -140,7 +148,9 @@ } if (count(element_children($form['strings']))) { $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save translations')); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Save translations')); } } return $form; @@ -150,7 +160,6 @@ * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { - $langcode = $form_state['values']['langcode']; foreach ($form_state['values']['strings'] as $lid => $translations) { foreach ($translations['translations'] as $key => $value) { @@ -167,14 +176,13 @@ * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $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 (locale_storage()->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { + foreach (\Drupal::service('locale.storage')->getTranslations(array('lid' => $lids, 'language' => $langcode, 'translated' => TRUE)) as $existing_translation_object) { $existing_translation_objects[$existing_translation_object->lid] = $existing_translation_object; } @@ -203,7 +211,7 @@ if ($is_changed) { // Only update or insert if we have a value to use. - $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : locale_storage()->createTranslation(array('lid' => $lid, 'language' => $langcode)); + $target = isset($existing_translation_objects[$lid]) ? $existing_translation_objects[$lid] : \Drupal::service('locale.storage')->createTranslation(array('lid' => $lid, 'language' => $langcode)); $target->setPlurals($new_translation['translations']) ->setCustomized() ->save(); diff -u b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php --- b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslateFilterForm.php @@ -9,7 +9,7 @@ use Drupal\Core\Form\FormInterface; -class TranslateFilterForm implements FormInterface { +class TranslateFilterForm extends TranslateFormBase implements FormInterface { /** * {@inheritdoc} @@ -22,9 +22,8 @@ * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, Node $node = NULL) { - - $filters = locale_translate_filters(); - $filter_values = locale_translate_filter_values(); + $filters = $this->translateFilters(); + $filter_values = $this->translateFilterValues(); $form['#attached']['css'] = array( drupal_get_path('module', 'locale') . '/locale.admin.css', @@ -90,9 +89,8 @@ * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - $op = $form_state['values']['op']; - $filters = locale_translate_filters(); + $filters = $this->translateFilters(); switch ($op) { case t('Filter'): foreach ($filters as $name => $filter) { @@ -108,5 +106,5 @@ } - $form_state['redirect'] = 'admin/config/regional/translate/translate'; + $form_state['redirect'] = 'admin/config/regional/translate'; } } diff -u b/core/modules/locale/locale.module b/core/modules/locale/locale.module --- b/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -173,9 +173,7 @@ $items['admin/config/regional/translate'] = array( 'title' => 'User interface translation', 'description' => 'Translate the built-in user interface.', - 'page callback' => 'locale_translate_page', - 'access arguments' => array('translate interface'), - 'file' => 'locale.pages.inc', + 'route_name' => 'locale_translate_page', 'weight' => -5, ); $items['admin/config/regional/translate/translate'] = array( @@ -187,7 +185,9 @@ $items['admin/config/regional/translate'] = array( 'title' => 'User interface translation', 'description' => 'Translate the built-in user interface.', - 'route_name' => 'locale_translate_page', + 'page callback' => 'locale_translate_page', + 'access arguments' => array('translate interface'), + 'file' => 'locale.pages.inc', 'weight' => -5, ); $items['admin/config/regional/translate/translate'] = array( @@ -742,7 +742,7 @@ '@total' => $total_strings, '@ratio' => $stats[$langcode]['ratio'], )), - 'admin/config/regional/translate/translate', + 'admin/config/regional/translate', array('query' => array('langcode' => $langcode)) ), ); @@ -1356,132 +1355,0 @@ - -/** - * Builds a string search query and returns an array of string objects. - * - * @return array - * Array of Drupal\locale\TranslationString objects. - */ -function locale_translate_filter_load_strings() { - $filter_values = locale_translate_filter_values(); - - // Language is sanitized to be one of the possible options in - // locale_translate_filter_values(). - $conditions = array('language' => $filter_values['langcode']); - $options = array('pager limit' => 30, 'translated' => TRUE, 'untranslated' => TRUE); - - // Add translation status conditions and options. - switch ($filter_values['translation']) { - case 'translated': - $conditions['translated'] = TRUE; - if ($filter_values['customized'] != 'all') { - $conditions['customized'] = $filter_values['customized']; - } - break; - - case 'untranslated': - $conditions['translated'] = FALSE; - break; - - } - - if (!empty($filter_values['string'])) { - $options['filters']['source'] = $filter_values['string']; - if ($options['translated']) { - $options['filters']['translation'] = $filter_values['string']; - } - } - - return locale_storage()->getTranslations($conditions, $options); -} - -/** - * Build array out of search criteria specified in request variables. - */ -function locale_translate_filter_values() { - $filter_values = &drupal_static(__FUNCTION__); - if (!isset($filter_values)) { - $filter_values = array(); - $filters = locale_translate_filters(); - foreach ($filters as $key => $filter) { - $filter_values[$key] = $filter['default']; - // Let the filter defaults be overwritten by parameters in the URL. - if (isset($_GET[$key])) { - // Only allow this value if it was among the options, or - // if there were no fixed options to filter for. - if (!isset($filter['options']) || isset($filter['options'][$_GET[$key]])) { - $filter_values[$key] = $_GET[$key]; - } - } - elseif (isset($_SESSION['locale_translate_filter'][$key])) { - // Only allow this value if it was among the options, or - // if there were no fixed options to filter for. - if (!isset($filter['options']) || isset($filter['options'][$_SESSION['locale_translate_filter'][$key]])) { - $filter_values[$key] = $_SESSION['locale_translate_filter'][$key]; - } - } - } - } - return $filter_values; -} - -/** - * List locale translation filters that can be applied. - */ -function locale_translate_filters() { - $filters = array(); - - // Get all languages, except English. - drupal_static_reset('language_list'); - $languages = language_list(); - $language_options = array(); - foreach ($languages as $langcode => $language) { - if ($langcode != 'en' || locale_translate_english()) { - $language_options[$langcode] = $language->name; - } - } - - // Pick the current interface language code for the filter. - $default_langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; - if (!isset($language_options[$default_langcode])) { - $available_langcodes = array_keys($language_options); - $default_langcode = array_shift($available_langcodes); - } - - $filters['string'] = array( - 'title' => t('String contains'), - 'description' => t('Leave blank to show all strings. The search is case sensitive.'), - 'default' => '', - ); - - $filters['langcode'] = array( - 'title' => t('Translation language'), - 'options' => $language_options, - 'default' => $default_langcode, - ); - - $filters['translation'] = array( - 'title' => t('Search in'), - 'options' => array( - 'all' => t('Both translated and untranslated strings'), - 'translated' => t('Only translated strings'), - 'untranslated' => t('Only untranslated strings'), - ), - 'default' => 'all', - ); - - $filters['customized'] = array( - 'title' => t('Translation type'), - 'options' => array( - 'all' => t('All'), - LOCALE_NOT_CUSTOMIZED => t('Non-customized translation'), - LOCALE_CUSTOMIZED => t('Customized translation'), - ), - 'states' => array( - 'visible' => array( - ':input[name=translation]' => array('value' => 'translated'), - ), - ), - 'default' => 'all', - ); - - return $filters; -}