protected function MenuLinkTreeManipulator::hasStringTranslation in Menu block current language 8
Check if given string has a string translation.
Parameters
\Drupal\Core\StringTranslation\TranslatableMarkup $markup: The markup.
Return value
bool TRUE if found translation, FALSE if not.
1 call to MenuLinkTreeManipulator::hasStringTranslation()
- MenuLinkTreeManipulator::filterLanguages in src/
MenuLinkTreeManipulator.php - Filter out links that are not translated to the current language.
File
- src/
MenuLinkTreeManipulator.php, line 113
Class
- MenuLinkTreeManipulator
- A menu link tree manipulator.
Namespace
Drupal\menu_block_current_languageCode
protected function hasStringTranslation(TranslatableMarkup $markup) {
// Skip this check for source language.
// @todo This might cause some issues if string source language is not english.
if ($this->languageManager
->getCurrentLanguage() === $this->languageManager
->getDefaultLanguage()) {
return TRUE;
}
$conditions = [
'language' => $this->languageManager
->getCurrentLanguage()
->getId(),
'translated' => TRUE,
];
// Attempt to load translated menu links for current language.
$translations = $this->localeStorage
->getTranslations($conditions, [
'filters' => [
'source' => $markup
->getUntranslatedString(),
],
]);
/** @var \Drupal\locale\TranslationString $translation */
foreach ($translations as $translation) {
// No translation found / original string found.
if ($translation
->isNew()) {
continue;
}
// Make sure source strings are identical as getTranslations()
// load strings with wildcard (%string%) and might return
// an unexpected results.
if ($translation->source == $markup
->getUntranslatedString()) {
return TRUE;
}
}
return FALSE;
}