commit 11fe639dafa8350b4407529f5888822e6f4d6540 Author: Pancho Date: Mon May 20 08:55:46 2013 +0200 1978926-5 diff --git a/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php b/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php index 2743bd1..d66d12b 100644 --- a/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php +++ b/core/modules/locale/lib/Drupal/locale/Form/TranslationStatusForm.php @@ -7,32 +7,47 @@ namespace Drupal\locale\Form; +use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\ControllerInterface; use Drupal\Core\Form\FormInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** * {@inheritdoc} */ -class TranslationStatusForm implements FormInterface { +class TranslationStatusForm implements FormInterface, ControllerInterface { + /** + * The module handler service. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static(); + return new static( + $container->get('module_handler') + ); } /** - * {@inheritdoc} + * Constructs a TranslationStatusForm object. + * + * @param ModuleHandlerInterface $module_handler + * A module handler. */ - public function __construct() { + public function __construct(ModuleHandlerInterface $module_handler) { + $this->moduleHandler = $module_handler; } + /** * {@inheritdoc} */ public function getFormID() { - return 'locale_translation_status'; + return 'locale_translation_status_form'; } /** @@ -41,58 +56,35 @@ class TranslationStatusForm implements FormInterface { * @ingroup forms */ public function buildForm(array $form, array &$form_state) { - \Drupal::moduleHandler()->loadInclude('locale', 'translation.inc'); - \Drupal::moduleHandler()->loadInclude('locale', 'compare.inc'); - $updates = $options = array(); - $languages_update = $languages_not_found = array(); + $this->moduleHandler->loadInclude('locale', 'translation.inc'); + $this->moduleHandler->loadInclude('locale', 'compare.inc'); - // @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'); - + $options = array(); + $languages_update = array(); + $languages_not_found = array(); // 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); + $updates = $this->prepareUpdateData($status); // Build data options for the select table. - foreach($updates as $langcode => $update) { + 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)), ); + if (!empty($update['not_found'])) { + $languages_not_found[$langcode] = $langcode; + } + else if (!empty($update['updates'])) { + $languages_update[$langcode] = $langcode; + } } // Sort the table data on language name. uasort($options, 'drupal_sort_title'); + $languages_not_found = array_diff($languages_not_found, $languages_update); } $last_checked = state()->get('locale.translation_last_checked'); @@ -149,6 +141,89 @@ class TranslationStatusForm implements FormInterface { } /** + * Prepare information about projects with available translation updates. + * + * @param array $status + * Translation update status as an array keyed by Project ID and langcode. + * + * @return array + * Translation update status as an array keyed by language code and + * translation update status. + */ + protected function prepareUpdateData(array $status) { + $updates = 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(); + + 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' => $this->createInfoString($project_info), + ); + } + // 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, + ); + } + } + } + return $updates; + } + + + + /** + * Provides debug info for projects in case translation files are not found. + * + * Translations files are being fetched either from Drupal translation server + * and local files or only from the local filesystem depending on the + * "Translation source" setting at admin/config/regional/translate/settings. + * This method will produce debug information including the respective path(s) + * based on this setting. + * + * Translations for development versions are never fetched, so the debug info + * for that is a fixed message. + * + * @param array $project_info + * An array which is the project information of the source. + * + * @return string + * The string which contains debug information. + */ + protected function createInfoString($project_info) { + $remote_path = isset($project_info->files['remote']->uri) ? $project_info->files['remote']->uri : FALSE; + $local_path = isset($project_info->files['local']->uri) ? $project_info->files['local']->uri : FALSE; + + if (strpos($project_info->version, 'dev') !== FALSE) { + return t('No translation files are provided for development releases.'); + } + if ($remote_path && $local_path && locale_translation_use_remote_source()) { + return t('File not found at %remote_path nor at %local_path', array( + '%remote_path' => $remote_path, + '%local_path' => $local_path, + )); + } + elseif ($local_path) { + return t('File not found at %local_path', array('%local_path' => $local_path)); + } + return t('Translation file location could not be determined.'); + } + + /** * {@inheritdoc} */ public function validateForm(array &$form, array &$form_state) { @@ -162,8 +237,8 @@ class TranslationStatusForm implements FormInterface { * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { - \Drupal::moduleHandler()->loadInclude('locale', 'translation.inc'); - \Drupal::moduleHandler()->loadInclude('locale', 'fetch.inc'); + $this->moduleHandler->loadInclude('locale', 'translation.inc'); + $this->moduleHandler->loadInclude('locale', 'fetch.inc'); $langcodes = array_filter($form_state['values']['langcodes']); // Set the translation import options. This determines if existing @@ -184,4 +259,5 @@ class TranslationStatusForm implements FormInterface { batch_set($batch); } } + } diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index 3c2e318..97260ed 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -507,43 +507,6 @@ function locale_translation_language_table($form_element) { } /** - * Provides debug info for projects in case translation files are not found. - * - * Translations files are being fetched either from Drupal translation server - * and local files or only from the local filesystem depending on the - * "Translation source" setting at admin/config/regional/translate/settings. - * This method will produce debug information including the respective path(s) - * based on this setting. - * - * Translations for development versions are never fetched, so the debug info - * for that is a fixed message. - * - * @param array $source - * An array which is the project information of the source. - * - * @return string - * The string which contains debug information. - */ -function _locale_translation_status_debug_info($source) { - $remote_path = isset($source->files['remote']->uri) ? $source->files['remote']->uri : ''; - $local_path = isset($source->files['local']->uri) ? $source->files['local']->uri : ''; - - if (strpos($source->version, 'dev') !== FALSE) { - return t('No translation files are provided for development releases.'); - } - if (locale_translation_use_remote_source() && $remote_path && $local_path) { - return t('File not found at %remote_path nor at %local_path', array( - '%remote_path' => $remote_path, - '%local_path' => $local_path, - )); - } - elseif ($local_path) { - return t('File not found at %local_path', array('%local_path' => $local_path)); - } - return t('Translation file location could not be determined.'); -} - -/** * Returns HTML for translation edit form. * * @param array $variables