locale.pages.inc 4.35 KB
Newer Older
1 2 3
<?php

/**
4 5
 * @file
 * Interface translation summary, editing and deletion user interfaces.
6 7
 */

8
use Drupal\Component\Utility\SafeMarkup;
9
use Drupal\Core\Url;
10
use Drupal\Core\Render\Element;
11 12
use Drupal\locale\SourceString;
use Drupal\locale\TranslationString;
13
use Symfony\Component\HttpFoundation\RedirectResponse;
14 15
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

16
/**
17
 * Page callback: Checks for translation updates and displays the status.
18
 *
19
 * Manually checks the translation status without the use of cron.
20 21
 *
 * @see locale_menu()
22
 */
23 24
function locale_translation_manual_status() {
  module_load_include('compare.inc', 'locale');
25

26 27 28 29 30
  // Check the translation status of all translatable projects in all languages.
  // First we clear the cached list of projects. Although not strictly
  // necessary, this is helpful in case the project list is out of sync.
  locale_translation_flush_projects();
  locale_translation_check_projects();
31

32 33 34 35
  // Execute a batch if required. A batch is only used when remote files
  // are checked.
  if (batch_get()) {
    return batch_process('admin/reports/translations');
36
  }
37
  return new RedirectResponse(\Drupal::url('locale.translate_status', array(), array('absolute' => TRUE)));
38 39
}

40
/**
41 42 43 44 45
 * Prepares variables for translation status information templates.
 *
 * Translation status information is displayed per language.
 *
 * Default template: locale-translate-edit-form-strings.html.twig.
46 47 48 49 50 51
 *
 * @param array $variables
 *   An associative array containing:
 *   - updates: The projects which have updates.
 *   - not_found: The projects which updates are not found.
 *
52
 * @see \Drupal\locale\Form\TranslationStatusForm
53
 */
54
function template_preprocess_locale_translation_update_info(array &$variables) {
55
  $details = array();
56 57 58

  // Build output for available updates.
  if (isset($variables['updates'])) {
59
    $releases = array();
60 61 62
    if ($variables['updates']) {
      foreach ($variables['updates'] as $update) {
        $modules[] = $update['name'];
63
        $releases[] = SafeMarkup::format('@module (@date)', array(
64 65 66
          '@module' => $update['name'],
          '@date' => format_date($update['timestamp'], 'html_date'),
        ));
67
      }
68
      $variables['modules'] = $modules;
69
    }
70 71 72 73
    $details['available_updates_list'] = array(
      '#theme' => 'item_list',
      '#items' => $releases,
    );
74 75 76 77
  }

  // Build output for updates not found.
  if (isset($variables['not_found'])) {
78
    $releases = array();
79
    $variables['missing_updates_status'] = \Drupal::translation()->formatPlural(count($variables['not_found']), 'Missing translations for one project', 'Missing translations for @count projects');
80 81 82
    if ($variables['not_found']) {
      foreach ($variables['not_found'] as $update) {
        $version = $update['version'] ? $update['version'] : t('no version');
83
        $releases[] = SafeMarkup::format('@module (@version). !info', array(
84 85 86 87
          '@module' => $update['name'],
          '@version' => $version,
          '!info' => $update['info'],
        ));
88 89
      }
    }
90 91 92 93 94 95 96 97
    $details['missing_updates_list'] = array(
      '#theme' => 'item_list',
      '#items' => $releases,
    );
    // Prefix the missing updates list if there is an available updates lists
    // before it.
    if (!empty($details['available_updates_list']['#items'])) {
      $details['missing_updates_list']['#prefix'] = t('Missing translations for:');
98 99
    }
  }
100
  $variables['details'] = $details;
101 102 103
}

/**
104 105 106 107 108 109
 * Prepares variables for most recent translation update templates.
 *
 * Displays the last time we checked for locale update data. In addition to
 * properly formatting the given timestamp, this function also provides a "Check
 * manually" link that refreshes the available update and redirects back to the
 * same page.
110
 *
111
 * Default template: locale-translation-last-check.html.twig.
112
 *
113
 * @param array $variables
114 115 116
 *   An associative array containing:
 *   - last: The timestamp when the site last checked for available updates.
 *
117
 * @see \Drupal\locale\Form\TranslationStatusForm
118
 */
119
function template_preprocess_locale_translation_last_check(array &$variables) {
120
  $last = $variables['last'];
121
  $variables['last_checked'] = ($last != NULL);
122
  $variables['time'] = \Drupal::service('date.formatter')->formatInterval(REQUEST_TIME - $last);
123
  $variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', array(), array('query' => drupal_get_destination())));
124
}