public function LanguageManager::getLanguage

Returns a language object for the given type.

Parameters

string $type: The language type, e.g. Language::TYPE_INTERFACE.

Return value

\Drupal\Core\Language\Language A language object for the given type.

1 call to LanguageManager::getLanguage()
LanguageManager::init in drupal/core/lib/Drupal/Core/Language/LanguageManager.php
Initializes each language type to a language object.

File

drupal/core/lib/Drupal/Core/Language/LanguageManager.php, line 84
Contains \Drupal\Core\Language\LanguageManager.

Class

LanguageManager
Class responsible for initializing each language type.

Namespace

Drupal\Core\Language

Code

public function getLanguage($type) {
  if (isset($this->languages[$type])) {
    return $this->languages[$type];
  }
  if ($this
    ->isMultilingual() && $this->request) {
    if (!$this->initializing) {
      $this->initializing = TRUE;

      // @todo Objectify the language system so that we don't have to load an
      //   include file and call out to procedural code. See
      //   http://drupal.org/node/1862202
      include_once DRUPAL_ROOT . '/core/includes/language.inc';
      $this->languages[$type] = language_types_initialize($type, $this->request);
      $this->initializing = FALSE;
    }
    else {

      // Config has called getLanguage() during initialization of a language
      // type. Simply return the default language without setting it on the
      // $this->languages property. See the TODO in the docblock for the
      // $initializing property.
      return $this
        ->getLanguageDefault();
    }
  }
  else {
    $this->languages[$type] = $this
      ->getLanguageDefault();
  }
  return $this->languages[$type];
}