You are here

function locale_requirements in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/locale/locale.install \locale_requirements()

Implements hook_requirements().

File

core/modules/locale/locale.install, line 249
Install, update, and uninstall functions for the Locale module.

Code

function locale_requirements($phase) {
  $requirements = [];
  if ($phase == 'runtime') {
    $available_updates = [];
    $untranslated = [];
    $languages = locale_translatable_language_list();
    if ($languages) {

      // Determine the status of the translation updates per language.
      $status = locale_translation_get_status();
      if ($status) {
        foreach ($status as $project) {
          foreach ($project as $langcode => $project_info) {
            if (empty($project_info->type)) {
              $untranslated[$langcode] = $languages[$langcode]
                ->getName();
            }
            elseif ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
              $available_updates[$langcode] = $languages[$langcode]
                ->getName();
            }
          }
        }
        if ($available_updates || $untranslated) {
          if ($available_updates) {
            $requirements['locale_translation'] = [
              'title' => t('Translation update status'),
              'value' => Link::fromTextAndUrl(t('Updates available'), Url::fromRoute('locale.translate_status'))
                ->toString(),
              'severity' => REQUIREMENT_WARNING,
              'description' => t('Updates available for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
                '@languages' => implode(', ', $available_updates),
                ':updates' => Url::fromRoute('locale.translate_status')
                  ->toString(),
              ]),
            ];
          }
          else {
            $requirements['locale_translation'] = [
              'title' => t('Translation update status'),
              'value' => t('Missing translations'),
              'severity' => REQUIREMENT_INFO,
              'description' => t('Missing translations for: @languages. See the <a href=":updates">Available translation updates</a> page for more information.', [
                '@languages' => implode(', ', $untranslated),
                ':updates' => Url::fromRoute('locale.translate_status')
                  ->toString(),
              ]),
            ];
          }
        }
        else {
          $requirements['locale_translation'] = [
            'title' => t('Translation update status'),
            'value' => t('Up to date'),
            'severity' => REQUIREMENT_OK,
          ];
        }
      }
      else {
        $requirements['locale_translation'] = [
          'title' => t('Translation update status'),
          'value' => Link::fromTextAndUrl(t('Can not determine status'), Url::fromRoute('locale.translate_status'))
            ->toString(),
          'severity' => REQUIREMENT_WARNING,
          'description' => t('No translation status is available. See the <a href=":updates">Available translation updates</a> page for more information.', [
            ':updates' => Url::fromRoute('locale.translate_status')
              ->toString(),
          ]),
        ];
      }
    }
  }
  return $requirements;
}