Returns a language object for the given type.
string $type: The language type, e.g. Language::TYPE_INTERFACE.
\Drupal\Core\Language\Language A language object for the given type.
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];
}