function locale_requirements

Same name and namespace in other branches
  1. 9 core/modules/locale/locale.install \locale_requirements()
  2. 10 core/modules/locale/locale.install \locale_requirements()
  3. 11.x core/modules/locale/locale.install \locale_requirements()

Implements hook_requirements().

File

core/modules/locale/locale.install, line 250

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.