diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index db230ff..0436ce1 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -239,6 +239,9 @@ function locale_theme() { 'render element' => 'form', 'file' => 'locale.pages.inc', ), + 'locale_project_language_update_info' => array( + 'arguments' => array('projects' => array(), 'type' => ''), + ), ); } diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index f0c05e6..1f6df82 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -591,34 +591,95 @@ function locale_translate_settings_submit($form, &$form_state) { * @see locale_menu() */ function locale_translation_status_form($form, &$form_state) { - module_load_include('compare.inc', 'locale'); - //locale_translation_flush_projects(); - $languages = locale_translatable_language_list(); + if (!$languages) { + drupal_set_message(t('No translatable languages available. Add language first.', array('@add_language' => url('admin/config/regional/language'))), 'warning'); + return $form; + } + + module_load_include('compare.inc', 'locale'); + locale_translation_flush_projects(); + $projects = locale_translation_get_projects(); $status = state()->get('locale.translation_status'); - if (!$languages) { - drupal_set_message(t('No translatable languages available. Add language first.', array('@add_lanuage' => url('admin/config/regional/language'))), 'warning'); + // Prepare information about projects which have available translation + // updates. + $projects_to_update = array(); + foreach ($status as $project_id => $project) { + foreach ($project as $langcode => $project_info) { + if (!isset($project_info->type)) { + $projects_to_update[$langcode]['not_found'][] = array( + 'name' => $project_info->name, + 'version' => $project_info->version, + ); + } + elseif ($project_info->type != 'current') { + $projects_to_update[$langcode]['updates'][] = array( + 'name' => $project_info->name, + 'version' => $project_info->version, + ); + } + } } - // @todo Add user interface update for translation update. - // Followup issues: Display translation status http://drupal.org/node/1804702 - // and Translations update feature user experience http://drupal.org/node/1029554 - $form['langcodes'] = array( - '#type' => 'value', - '#value' => drupal_map_assoc(array_keys($languages)), + // @todo It could be useful to consider refactoring theme_update_last_check(). + $last = state()->get('locale.translation_last_checked'); + $markup = '
'; + $markup .= $last ? t('Last checked: @time ago', array('@time' => format_interval(REQUEST_TIME - $last))) : t('Last checked: never'); + $markup .= ' (' . l(t('Check manually'), 'admin/reports/translations/check', array('query' => drupal_get_destination())) . ')'; + $markup .= "
\n"; + $form['last_checked'] = array( + '#markup' => $markup, ); + $form['langcodes_title'] = array( + '#type' => 'item', + '#title' => t('Languages'), + ); + $header = array( + 'title' => t('Title'), + 'operations' => t('Operations'), + ); + $options = array(); + foreach ($languages as $langcode => $language) { + if (isset($projects_to_update[$langcode])) { + $options[$langcode] = array( + 'title' => $language->name, + 'operations' => array( + 'class' => 'operations', + 'data' => theme('locale_project_language_update_info', array( + 'projects' => array( + 'updates' => isset($projects_to_update[$langcode]['updates']) ? $projects_to_update[$langcode]['updates'] : NULL, + 'not_found' => isset($projects_to_update[$langcode]['not_found']) ? $projects_to_update[$langcode]['not_found'] : NULL, + ), + 'langcode' => $langcode, + )), + ), + ); + } + } + $form['langcodes'] = array( + '#type' => 'tableselect', + '#header' => $header, + '#options' => $options, + '#default_value' => drupal_map_assoc(array_keys($options)), + ); $form['actions'] = array( - '#type' => 'actions' + '#type' => 'actions', ); $form['actions']['submit'] = array( '#type' => 'submit', - '#value' => t('Update') + '#value' => t('Update'), + ); + $form['#attached']['js'] = array( + drupal_get_path('module', 'locale') . '/locale.toggle-interface-update-details.js' => array( + 'type' => 'file', + ), ); return $form; } + /** * Form submission handler for locale_translation_status(). */ @@ -679,3 +740,78 @@ function theme_locale_translate_edit_form_strings($variables) { $output .= theme('pager'); return $output; } + +/** + * Returns HTML for interface translation update status. + * + * Output contains the list of projects which language updates will be applied + * to. A separated list is rendered which contains projects which language + * updates were not found for. + * + * @param $variables + * An associative array containing: + * - projects: An array containing the list of projects. List is divided into + * two arrays with the following keys: + * - updates: An array containing the projects which language + * updates will be applied to. Each element of the array is an associative + * array with the following keys: + * - project: Human readable name of the project. + * - version: Version of the project. + * - not_found: An array containing the projects which language updates were + * not found for. Each element of the array is an associative array with + * the following keys: + * - project: Human readable name of the project. + * - version: Version of the project. + * + * @ingroup themeable + */ +function theme_locale_project_language_update_info($variables) { + $output = array(); + $project_list = array(); + if (isset($variables['projects']['updates'])) { + foreach ($variables['projects']['updates'] as $project) { + $project_list['flat'][] = $project['name']; + $project_list['details'][] = format_string('!name (!version)', array( + '!name' => $project['name'], + '!version' => $project['version'], + )); + } + $output['updates_summary'] = array( + '#type' => 'markup', + '#markup' => '

' . t('This applies language updates to %projects.', array( + '%projects' => implode(', ', $project_list['flat']), + )) . "

", + ); + $output['updates_details'] = array( + '#theme' => 'item_list', + '#items' => $project_list['details'], + '#attributes' => array( + 'class' => array('details'), + ), + ); + } + $project_list = array('count' => 0); + if (isset($variables['projects']['not_found'])) { + foreach ($variables['projects']['not_found'] as $project) { + $project_list['count']++; + $project_list['details'][] = format_string('!name (!version)', array( + '!name' => $project['name'], + '!version' => $project['version'], + )); + } + $output['not_found_summary'] = array( + '#type' => 'markup', + '#markup' => '

' . t('No updates were found for %count projects.', array( + '%count' => $project_list['count'], + )) . '

', + ); + $output['not_found_details'] = array( + '#theme' => 'item_list', + '#items' => $project_list['details'], + '#attributes' => array( + 'class' => array('details'), + ), + ); + } + return $output; +}