You are here

function lingotek_admin_module_indexing_finished in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.5 lingotek.admin.inc \lingotek_admin_module_indexing_finished()
1 string reference to 'lingotek_admin_module_indexing_finished'
lingotek_admin_load_l10n_update_batch in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 835

Code

function lingotek_admin_module_indexing_finished($success, $results) {

  // TODO: consider rewriting more of this function (adapted from l10n_update module)
  $totals = array();

  // Sum of added, updated and deleted translations.
  $total_skip = 0;

  // Sum of skipped translations
  $messages = array();

  // User feedback messages.
  $project_fail = $project_success = array();

  // Project names of succesfull and failed imports.
  $t = get_t();
  if ($success) {

    // Summarize results of added, updated, deleted and skiped translations.
    // Added, updated and deleted are summarized per language to be displayed accordingly.
    foreach ($results as $result) {

      // convert to array as needed
      if (is_a($result, 'stdClass')) {
        $result = get_object_vars($result);
      }
      if (isset($result['fail'])) {

        // Collect project names of the failed imports.
        $project_fail[$result['file']->name] = $result['file']->name;
      }
      else {
        $language = $result['language'];

        // Initialize variables to prevent PHP Notices.
        if (!isset($totals[$language])) {
          $totals[$language] = array();
          $totals[$language]['add'] = $totals[$language]['update'] = $totals[$language]['delete'] = 0;
        }

        // Summarize added, updated, deleted and skiped translations.
        $totals[$language]['add'] += $result['add'];
        $totals[$language]['update'] += $result['update'];
        $totals[$language]['delete'] += $result['delete'];
        $total_skip += $result['skip'];

        // Collect project names of the succesfull imports.
        $project_success[$result['file']->name] = $result['file']->name;
      }
    }

    // Messages of succesfull translation update results.
    if ($project_success) {
      $messages[] = format_plural(count($project_success), 'One project updated: @projects.', '@count projects updated: @projects.', array(
        '@projects' => implode(', ', $project_success),
      ));
      $languages = language_list();
      foreach ($totals as $language => $total) {
        $messages[] = $t('%language translation strings added: !add, updated: !update, deleted: !delete.', array(
          '%language' => $languages[$language]->name,
          '!add' => $total['add'],
          '!update' => $total['update'],
          '!delete' => $total['delete'],
        ));
      }
      drupal_set_message(implode("<br />\n", $messages));

      // Warning for disallowed HTML.
      if ($total_skip) {
        drupal_set_message(format_plural($total_skip, 'One translation string was skipped because it contains disallowed HTML. See !log_messages for details.', '@count translation strings were skipped because they contain disallowed HTML. See !log_messages for details.', array(
          '!log_messages' => l(t('Recent log messages'), 'admin/reports/dblog'),
        )), 'warning');
      }
    }

    // Error for failed imports.
    if ($project_fail) {
      drupal_set_message(format_plural(count($project_fail), 'Translations of one project were not imported: @projects.', 'Translations of @count projects were not imported: @projects', array(
        '@projects' => implode(', ', $project_fail),
      )), 'error');
    }
  }
  else {
    drupal_set_message($t('Error gathering built-in strings for translation.'), 'error');
  }
}