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

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

8
use Drupal\Core\Url;
9
use Drupal\Core\Render\Element;
10
use Symfony\Component\HttpFoundation\RedirectResponse;
11

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

22 23 24 25 26
  // 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();
27

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

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

/**
57 58 59 60 61 62
 * 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.
63
 *
64
 * Default template: locale-translation-last-check.html.twig.
65
 *
66
 * @param array $variables
67 68 69
 *   An associative array containing:
 *   - last: The timestamp when the site last checked for available updates.
 *
70
 * @see \Drupal\locale\Form\TranslationStatusForm
71
 */
72
function template_preprocess_locale_translation_last_check(array &$variables) {
73
  $last = $variables['last'];
74
  $variables['last_checked'] = ($last != NULL);
75
  $variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($last);
76
  $variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', array(), array('query' => \Drupal::destination()->getAsArray())));
77
}