locale.pages.inc 2.6 KB

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