class LocaleRequirements
Requirements for the Locale module.
Hierarchy
- class \Drupal\locale\Hook\LocaleRequirements uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of LocaleRequirements
File
-
core/
modules/ locale/ src/ Hook/ LocaleRequirements.php, line 16
Namespace
Drupal\locale\HookView source
class LocaleRequirements {
use StringTranslationTrait;
/**
* Implements hook_runtime_requirements().
*/
public function runtime() : array {
$requirements = [];
$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' => $this->t('Translation update status'),
'value' => Link::fromTextAndUrl($this->t('Updates available'), Url::fromRoute('locale.translate_status'))
->toString(),
'severity' => RequirementSeverity::Warning,
'description' => $this->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' => $this->t('Translation update status'),
'value' => $this->t('Missing translations'),
'severity' => RequirementSeverity::Info,
'description' => $this->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' => $this->t('Translation update status'),
'value' => $this->t('Up to date'),
'severity' => RequirementSeverity::OK,
];
}
}
else {
$requirements['locale_translation'] = [
'title' => $this->t('Translation update status'),
'value' => Link::fromTextAndUrl($this->t('Can not determine status'), Url::fromRoute('locale.translate_status'))
->toString(),
'severity' => RequirementSeverity::Warning,
'description' => $this->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;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
LocaleRequirements::runtime | public | function | Implements hook_runtime_requirements(). | |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | |
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | |
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | 1 |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.