Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /**
|
Chris@0
|
4 * @file
|
Chris@0
|
5 * Interface translation summary, editing and deletion user interfaces.
|
Chris@0
|
6 */
|
Chris@0
|
7
|
Chris@0
|
8 use Drupal\Core\Url;
|
Chris@0
|
9 use Symfony\Component\HttpFoundation\RedirectResponse;
|
Chris@0
|
10
|
Chris@0
|
11 /**
|
Chris@0
|
12 * Page callback: Checks for translation updates and displays the status.
|
Chris@0
|
13 *
|
Chris@0
|
14 * Manually checks the translation status without the use of cron.
|
Chris@0
|
15 *
|
Chris@0
|
16 * @see locale_menu()
|
Chris@0
|
17 */
|
Chris@0
|
18 function locale_translation_manual_status() {
|
Chris@0
|
19 module_load_include('compare.inc', 'locale');
|
Chris@0
|
20
|
Chris@0
|
21 // Check the translation status of all translatable projects in all languages.
|
Chris@0
|
22 // First we clear the cached list of projects. Although not strictly
|
Chris@0
|
23 // necessary, this is helpful in case the project list is out of sync.
|
Chris@0
|
24 locale_translation_flush_projects();
|
Chris@0
|
25 locale_translation_check_projects();
|
Chris@0
|
26
|
Chris@0
|
27 // Execute a batch if required. A batch is only used when remote files
|
Chris@0
|
28 // are checked.
|
Chris@0
|
29 if (batch_get()) {
|
Chris@0
|
30 return batch_process('admin/reports/translations');
|
Chris@0
|
31 }
|
Chris@0
|
32 return new RedirectResponse(\Drupal::url('locale.translate_status', [], ['absolute' => TRUE]));
|
Chris@0
|
33 }
|
Chris@0
|
34
|
Chris@0
|
35 /**
|
Chris@0
|
36 * Prepares variables for translation status information templates.
|
Chris@0
|
37 *
|
Chris@0
|
38 * Translation status information is displayed per language.
|
Chris@0
|
39 *
|
Chris@0
|
40 * Default template: locale-translate-edit-form-strings.html.twig.
|
Chris@0
|
41 *
|
Chris@0
|
42 * @param array $variables
|
Chris@0
|
43 * An associative array containing:
|
Chris@0
|
44 * - updates: The projects which have updates.
|
Chris@0
|
45 * - not_found: The projects which updates are not found.
|
Chris@0
|
46 *
|
Chris@0
|
47 * @see \Drupal\locale\Form\TranslationStatusForm
|
Chris@0
|
48 */
|
Chris@0
|
49 function template_preprocess_locale_translation_update_info(array &$variables) {
|
Chris@0
|
50 foreach ($variables['updates'] as $update) {
|
Chris@0
|
51 $variables['modules'][] = $update['name'];
|
Chris@0
|
52 }
|
Chris@0
|
53 }
|
Chris@0
|
54
|
Chris@0
|
55 /**
|
Chris@0
|
56 * Prepares variables for most recent translation update templates.
|
Chris@0
|
57 *
|
Chris@0
|
58 * Displays the last time we checked for locale update data. In addition to
|
Chris@0
|
59 * properly formatting the given timestamp, this function also provides a "Check
|
Chris@0
|
60 * manually" link that refreshes the available update and redirects back to the
|
Chris@0
|
61 * same page.
|
Chris@0
|
62 *
|
Chris@0
|
63 * Default template: locale-translation-last-check.html.twig.
|
Chris@0
|
64 *
|
Chris@0
|
65 * @param array $variables
|
Chris@0
|
66 * An associative array containing:
|
Chris@0
|
67 * - last: The timestamp when the site last checked for available updates.
|
Chris@0
|
68 *
|
Chris@0
|
69 * @see \Drupal\locale\Form\TranslationStatusForm
|
Chris@0
|
70 */
|
Chris@0
|
71 function template_preprocess_locale_translation_last_check(array &$variables) {
|
Chris@0
|
72 $last = $variables['last'];
|
Chris@0
|
73 $variables['last_checked'] = ($last != NULL);
|
Chris@0
|
74 $variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($last);
|
Chris@0
|
75 $variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', [], ['query' => \Drupal::destination()->getAsArray()]));
|
Chris@0
|
76 }
|