locale.pages.inc 3.1 KB

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