1 language.inc language_types_initialize($type)

Chooses a language based on language negotiation provider settings.

Parameters

$type: The type of language to retrieve as provided by hook_language_types_info(). In Backdrop core, the available language types will be one of the following:

  • language
  • language_content
  • language_url

Return value

The negotiated language object.:

Related topics

File

core/includes/language.inc, line 114
Language Negotiation API.

Code

function language_types_initialize($type) {
  // Execute the language negotiation providers in the order they were set up
  // and return the first valid language found.
  $negotiation_order = language_negotiation_order($type);

  if (empty($negotiation_order)) {
    $language_types = language_types_info();
    if (isset($language_types[$type]['fixed'])) {
      $negotiation_order = $language_types[$type]['fixed'];
    }
  }

  foreach ($negotiation_order as $provider_id) {
    $language = language_provider_invoke($provider_id);
    if ($language) {
      // Remember the provider key used to detect the language.
      $language->provider = $provider_id;
      return $language;
    }
  }

  // If no other language was found use the default one.
  $language = language_default();
  $language->provider = LANGUAGE_NEGOTIATION_DEFAULT;
  return $language;
}