You are here

function _language_cookie_get_language in Language Cookie 7.2

See also

language_initialize.

1 call to _language_cookie_get_language()
language_cookie_boot in ./language_cookie.module
Implements hook_boot().

File

./language_cookie.module, line 212
Language Cookie module.

Code

function _language_cookie_get_language() {
  require_once DRUPAL_ROOT . '/includes/locale.inc';

  // We assume the interface language will be used to set the cookie.
  // If you want to use another language type instead (ie. content/URL),
  // you can use the "language_cookie_language_type" variable.
  $type = variable_get('language_cookie_language_type', LANGUAGE_TYPE_INTERFACE);

  // Execute the language negotiation providers in the order they were set up and return the
  // first valid language found.
  $negotiation = variable_get("language_negotiation_{$type}", array());
  foreach ($negotiation as $provider_id => $provider) {

    // Do not consider language providers with a lower priority than the cookie
    // language provider, nor the cookie provider itself.
    if ($provider_id == LANGUAGE_COOKIE_NEGOTIATION) {
      return FALSE;
    }
    $language = language_provider_invoke($provider_id, $provider);
    if ($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;
}