function LanguageManager::getLanguageName

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::getLanguageName()
  2. 10 core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::getLanguageName()
  3. 11.x core/lib/Drupal/Core/Language/LanguageManager.php \Drupal\Core\Language\LanguageManager::getLanguageName()

Overrides LanguageManagerInterface::getLanguageName

File

core/lib/Drupal/Core/Language/LanguageManager.php, line 163

Class

LanguageManager
Class responsible for providing language support on language-unaware sites.

Namespace

Drupal\Core\Language

Code

public function getLanguageName($langcode) {
    if ($langcode == LanguageInterface::LANGCODE_NOT_SPECIFIED) {
        return new TranslatableMarkup('None');
    }
    if ($language = $this->getLanguage($langcode)) {
        return $language->getName();
    }
    if (empty($langcode)) {
        return new TranslatableMarkup('Unknown');
    }
    return new TranslatableMarkup('Unknown (@langcode)', [
        '@langcode' => $langcode,
    ]);
}

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