TranslationStatusForm::prepareUpdateData

protected TranslationStatusForm::prepareUpdateData(array $status)

Prepare information about projects with available translation updates.

Parameters

array $status: Translation update status as an array keyed by Project ID and langcode.

Return value

array Translation update status as an array keyed by language code and translation update status.

File

core/modules/locale/src/Form/TranslationStatusForm.php, line 185

Class

TranslationStatusForm
Provides a translation status form.

Namespace

Drupal\locale\Form

Code

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
  //   https://www.drupal.org/node/1842362 the project name will be stored to
  //   display use, like here.
  $this->moduleHandler->loadInclude('locale', 'compare.inc');
  $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 (empty($project_info->type)) {
        $updates[$langcode]['not_found'][] = array(
          'name' => $project_info->name == 'drupal' ? $this->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_info->name == 'drupal' ? $this->t('Drupal core') : $project_data[$project_info->name]->info['name'],
          'version' => $project_info->version,
          'timestamp' => $recent->timestamp,
        );
      }
    }
  }
  return $updates;
}
doc_Drupal
2016-10-29 09:49:23
Comments
Leave a Comment

Please login to continue.