ConfigurableLanguageManager::getCurrentLanguage

public ConfigurableLanguageManager::getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE)

Returns the current language for the given type.

Parameters

string $type: (optional) The language type; e.g., the interface or the content language. Defaults to \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE.

Return value

\Drupal\Core\Language\LanguageInterface The current language object for the given type of language.

Overrides LanguageManager::getCurrentLanguage

File

core/modules/language/src/ConfigurableLanguageManager.php, line 210

Class

ConfigurableLanguageManager
Overrides default LanguageManager to provide configured languages.

Namespace

Drupal\language

Code

public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE) {
  if (!isset($this->negotiatedLanguages[$type])) {
    // Ensure we have a valid value for this language type.
    $this->negotiatedLanguages[$type] = $this->getDefaultLanguage();

    if ($this->negotiator && $this->isMultilingual()) {
      if (!$this->initializing) {
        $this->initializing = TRUE;
        $negotiation = $this->negotiator->initializeType($type);
        $this->negotiatedLanguages[$type] = reset($negotiation);
        $this->negotiatedMethods[$type] = key($negotiation);
        $this->initializing = FALSE;
      }
      // If the current interface language needs to be retrieved during
      // initialization we return the system language. This way string
      // translation calls happening during initialization will return the
      // original strings which can be translated by calling them again
      // afterwards. This can happen for instance while parsing negotiation
      // method definitions.
      elseif ($type == LanguageInterface::TYPE_INTERFACE) {
        return new Language(array('id' => LanguageInterface::LANGCODE_SYSTEM));
      }
    }
  }

  return $this->negotiatedLanguages[$type];
}
doc_Drupal
2016-10-29 08:55:14
Comments
Leave a Comment

Please login to continue.