Chooses a language based on language negotiation method settings.
$type: The language type key to find the language for.
$request: The HttpReqeust object representing the current request.
The negotiated language object.
function language_types_initialize($type, $request = NULL) {
// Execute the language negotiation methods in the order they were set up and
// return the first valid language found.
$negotiation = variable_get("language_negotiation_{$type}", array());
foreach ($negotiation as $method_id => $method) {
// Skip negotiation methods not appropriate for this type.
if (isset($method['types']) && !in_array($type, $method['types'])) {
continue;
}
$language = language_negotiation_method_invoke($method_id, $method, $request);
if ($language) {
// Remember the method ID used to detect the language.
$language->method_id = $method_id;
return $language;
}
}
// If no other language was found use the default one.
$language = language_default();
$language->method_id = LANGUAGE_NEGOTIATION_SELECTED;
return $language;
}