diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php new file mode 100644 index 0000000..2743bd1 --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php @@ -0,0 +1,187 @@ +loadInclude('locale', 'translation.inc'); + \Drupal::moduleHandler()->loadInclude('locale', 'compare.inc'); + $updates = $options = array(); + $languages_update = $languages_not_found = array(); + + // @todo Calling locale_translation_build_projects() is an expensive way to + // get a module name. In follow-up issue http://drupal.org/node/1842362 + // the project name will be stored to display use, like here. + $project_data = locale_translation_build_projects(); + $languages = locale_translatable_language_list(); + $projects = locale_translation_get_projects(); + $status = state()->get('locale.translation_status'); + + // Prepare information about projects which have available translation + // updates. + if ($languages && $status) { + foreach ($status as $project_id => $project) { + foreach ($project as $langcode => $project_info) { + // No translation file found for this project-language combination. + if (!isset($project_info->type)) { + $updates[$langcode]['not_found'][] = array( + 'name' => $project_info->name == 'drupal' ? t('Drupal core') : $project_data[$project_info->name]->info['name'], + 'version' => $project_info->version, + 'info' => _locale_translation_status_debug_info($project_info), + ); + $languages_not_found[$langcode] = $langcode; + } + // Translation update found for this project-language combination. + elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE ) { + $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : NULL; + $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : NULL; + $recent = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local; + $updates[$langcode]['updates'][] = array( + 'name' => $project_data[$project_info->name]->info['name'], + 'version' => $project_info->version, + 'timestamp' => $recent->timestamp, + ); + $languages_update[$langcode] = $langcode; + } + } + } + $languages_not_found = array_diff($languages_not_found, $languages_update); + + // Build data options for the select table. + foreach($updates as $langcode => $update) { + $options[$langcode] = array( + 'title' => check_plain($languages[$langcode]->name), + 'status' => array('class' => array('description', 'expand', 'priority-low'), 'data' => theme('locale_translation_update_info', $update)), + ); + } + // Sort the table data on language name. + uasort($options, 'drupal_sort_title'); + } + + $last_checked = state()->get('locale.translation_last_checked'); + $form['last_checked'] = array( + '#markup' => '

' . theme('locale_translation_last_check', array('last' => $last_checked)) . '

', + ); + + $header = array( + 'title' => array( + 'data' => t('Language'), + 'class' => array('title'), + ), + 'status' => array( + 'data' => t('Status'), + 'class' => array('status', 'priority-low'), + ), + ); + + if (!$languages) { + $empty = t('No translatable languages available. Add a language first.', array('@add_language' => url('admin/config/regional/language'))); + } + elseif ($status) { + $empty = t('All translations up to date.'); + } + else { + $empty = t('No translation status available. Check manually.', array('@check' => url('admin/reports/translations/check'))); + } + + $form['langcodes'] = array( + '#type' => 'tableselect', + '#header' => $header, + '#options' => $options, + '#default_value' => $languages_update, + '#empty' => $empty, + '#js_select' => TRUE, + '#multiple' => TRUE, + '#required' => TRUE, + '#not_found' => $languages_not_found, + '#after_build' => array('locale_translation_language_table'), + ); + + $form['#attached']['library'][] = array('locale', 'drupal.locale.admin'); + $form['#attached']['css'] = array(drupal_get_path('module', 'locale') . '/locale.admin.css'); + + $form['actions'] = array('#type' => 'actions'); + if ($languages_update) { + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => t('Update translations'), + ); + } + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + // Check if a language has been selected. 'tableselect' doesn't. + if (!array_filter($form_state['values']['langcodes'])) { + form_set_error('', t('Select a language to update.')); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + \Drupal::moduleHandler()->loadInclude('locale', 'translation.inc'); + \Drupal::moduleHandler()->loadInclude('locale', 'fetch.inc'); + $langcodes = array_filter($form_state['values']['langcodes']); + + // Set the translation import options. This determines if existing + // translations will be overwritten by imported strings. + $options = _locale_translation_default_update_options(); + + // If the status was updated recently we can immediately start fetching the + // translation updates. If the status is expired we clear it an run a batch to + // update the status and then fetch the translation updates. + $last_checked = state()->get('locale.translation_last_checked'); + if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) { + locale_translation_clear_status(); + $batch = locale_translation_batch_update_build(array(), $langcodes, $options); + batch_set($batch); + } + else { + $batch = locale_translation_batch_fetch_build(array(), $langcodes, $options); + batch_set($batch); + } + } +} diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 75e0a22..2a3d849 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -223,11 +223,8 @@ function locale_menu() { ); $items['admin/reports/translations'] = array( 'title' => 'Available translation updates', + 'route_name' => 'locale_translation_status', 'description' => 'Get a status report about available interface translations for your installed modules and themes.', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('locale_translation_status_form'), - 'access arguments' => array('translate interface'), - 'file' => 'locale.pages.inc', ); $items['admin/reports/translations/check'] = array( 'title' => 'Manual translation update check', diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index a109f5f..3c2e318 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -484,155 +484,6 @@ function locale_translation_manual_status() { } /** - * Page callback: Display the current translation status. - * - * @see locale_menu() - */ -function locale_translation_status_form($form, &$form_state) { - module_load_include('translation.inc', 'locale'); - module_load_include('compare.inc', 'locale'); - $updates = $options = array(); - $languages_update = $languages_not_found = array(); - - // @todo Calling locale_translation_build_projects() is an expensive way to - // get a module name. In follow-up issue http://drupal.org/node/1842362 - // the project name will be stored to display use, like here. - $project_data = locale_translation_build_projects(); - $languages = locale_translatable_language_list(); - $projects = locale_translation_get_projects(); - $status = state()->get('locale.translation_status'); - - // Prepare information about projects which have available translation - // updates. - if ($languages && $status) { - foreach ($status as $project_id => $project) { - foreach ($project as $langcode => $project_info) { - // No translation file found for this project-language combination. - if (!isset($project_info->type)) { - $updates[$langcode]['not_found'][] = array( - 'name' => $project_info->name == 'drupal' ? t('Drupal core') : $project_data[$project_info->name]->info['name'], - 'version' => $project_info->version, - 'info' => _locale_translation_status_debug_info($project_info), - ); - $languages_not_found[$langcode] = $langcode; - } - // Translation update found for this project-language combination. - elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE ) { - $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : NULL; - $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : NULL; - $recent = _locale_translation_source_compare($local, $remote) == LOCALE_TRANSLATION_SOURCE_COMPARE_LT ? $remote : $local; - $updates[$langcode]['updates'][] = array( - 'name' => $project_data[$project_info->name]->info['name'], - 'version' => $project_info->version, - 'timestamp' => $recent->timestamp, - ); - $languages_update[$langcode] = $langcode; - } - } - } - $languages_not_found = array_diff($languages_not_found, $languages_update); - - // Build data options for the select table. - foreach($updates as $langcode => $update) { - $options[$langcode] = array( - 'title' => check_plain($languages[$langcode]->name), - 'status' => array('class' => array('description', 'expand', 'priority-low'), 'data' => theme('locale_translation_update_info', $update)), - ); - } - // Sort the table data on language name. - uasort($options, 'drupal_sort_title'); - } - - $last_checked = state()->get('locale.translation_last_checked'); - $form['last_checked'] = array( - '#markup' => '

' . theme('locale_translation_last_check', array('last' => $last_checked)) . '

', - ); - - $header = array( - 'title' => array( - 'data' => t('Language'), - 'class' => array('title'), - ), - 'status' => array( - 'data' => t('Status'), - 'class' => array('status', 'priority-low'), - ), - ); - - if (!$languages) { - $empty = t('No translatable languages available. Add a language first.', array('@add_language' => url('admin/config/regional/language'))); - } - elseif ($status) { - $empty = t('All translations up to date.'); - } - else { - $empty = t('No translation status available. Check manually.', array('@check' => url('admin/reports/translations/check'))); - } - - $form['langcodes'] = array( - '#type' => 'tableselect', - '#header' => $header, - '#options' => $options, - '#default_value' => $languages_update, - '#empty' => $empty, - '#js_select' => TRUE, - '#multiple' => TRUE, - '#required' => TRUE, - '#not_found' => $languages_not_found, - '#after_build' => array('locale_translation_language_table'), - ); - - $form['#attached']['library'][] = array('locale', 'drupal.locale.admin'); - $form['#attached']['css'] = array(drupal_get_path('module', 'locale') . '/locale.admin.css'); - - $form['actions'] = array('#type' => 'actions'); - if ($languages_update) { - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => t('Update translations'), - ); - } - - return $form; -} - -/** - * Form validation handler for locale_translation_status_form(). - */ -function locale_translation_status_form_validate($form, &$form_state) { - // Check if a language has been selected. 'tableselect' doesn't. - if (!array_filter($form_state['values']['langcodes'])) { - form_set_error('', t('Select a language to update.')); - } -} - -/** - * Form submission handler for locale_translation_status_form(). - */ -function locale_translation_status_form_submit($form, &$form_state) { - module_load_include('fetch.inc', 'locale'); - $langcodes = array_filter($form_state['values']['langcodes']); - - // Set the translation import options. This determines if existing - // translations will be overwritten by imported strings. - $options = _locale_translation_default_update_options(); - - // If the status was updated recently we can immediately start fetching the - // translation updates. If the status is expired we clear it an run a batch to - // update the status and then fetch the translation updates. - $last_checked = state()->get('locale.translation_last_checked'); - if ($last_checked < REQUEST_TIME - LOCALE_TRANSLATION_STATUS_TTL) { - locale_translation_clear_status(); - $batch = locale_translation_batch_update_build(array(), $langcodes, $options); - batch_set($batch); - } - else { - $batch = locale_translation_batch_fetch_build(array(), $langcodes, $options); - batch_set($batch); - } -} - -/** * Form element callback: After build changes to the language update table. * * Adds labels to the languages and removes checkboxes from languages from which diff --git a/core/modules/locale/locale.routing.yml b/core/modules/locale/locale.routing.yml index a2a5820..a7bf0c7 100644 --- a/core/modules/locale/locale.routing.yml +++ b/core/modules/locale/locale.routing.yml @@ -4,3 +4,10 @@ locale_settings: _form: 'Drupal\locale\Form\LocaleSettingsForm' requirements: _permission: 'translate interface' + +locale_translation_status: + pattern: 'admin/reports/translations' + defaults: + _form: 'Drupal\locale\Form\TranslationStatusForm' + requirements: + _permission: 'translate interface'