locale.pages.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * @deprecated in Drupal 8.5.0 and will be removed before 9.0.0. It is unused by
  14. * Drupal core. Duplicate this function in your own extension if you need its
  15. * behavior.
  16. *
  17. * @see https://www.drupal.org/node/2931188
  18. */
  19. function locale_translation_manual_status() {
  20. @trigger_error('locale_translation_manual_status() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. It is unused by Drupal core. Duplicate this function in your own extension if you need its behavior.', E_USER_DEPRECATED);
  21. module_load_include('compare.inc', 'locale');
  22. // Check the translation status of all translatable projects in all languages.
  23. // First we clear the cached list of projects. Although not strictly
  24. // necessary, this is helpful in case the project list is out of sync.
  25. locale_translation_flush_projects();
  26. locale_translation_check_projects();
  27. // Execute a batch if required. A batch is only used when remote files
  28. // are checked.
  29. if (batch_get()) {
  30. return batch_process('admin/reports/translations');
  31. }
  32. return new RedirectResponse(\Drupal::url('locale.translate_status', [], ['absolute' => TRUE]));
  33. }
  34. /**
  35. * Prepares variables for translation status information templates.
  36. *
  37. * Translation status information is displayed per language.
  38. *
  39. * Default template: locale-translate-edit-form-strings.html.twig.
  40. *
  41. * @param array $variables
  42. * An associative array containing:
  43. * - updates: The projects which have updates.
  44. * - not_found: The projects which updates are not found.
  45. *
  46. * @see \Drupal\locale\Form\TranslationStatusForm
  47. */
  48. function template_preprocess_locale_translation_update_info(array &$variables) {
  49. foreach ($variables['updates'] as $update) {
  50. $variables['modules'][] = $update['name'];
  51. }
  52. }
  53. /**
  54. * Prepares variables for most recent translation update templates.
  55. *
  56. * Displays the last time we checked for locale update data. In addition to
  57. * properly formatting the given timestamp, this function also provides a "Check
  58. * manually" link that refreshes the available update and redirects back to the
  59. * same page.
  60. *
  61. * Default template: locale-translation-last-check.html.twig.
  62. *
  63. * @param array $variables
  64. * An associative array containing:
  65. * - last: The timestamp when the site last checked for available updates.
  66. *
  67. * @see \Drupal\locale\Form\TranslationStatusForm
  68. */
  69. function template_preprocess_locale_translation_last_check(array &$variables) {
  70. $last = $variables['last'];
  71. $variables['last_checked'] = ($last != NULL);
  72. $variables['time'] = \Drupal::service('date.formatter')->formatTimeDiffSince($last);
  73. $variables['link'] = \Drupal::l(t('Check manually'), new Url('locale.check_translation', [], ['query' => \Drupal::destination()->getAsArray()]));
  74. }