function language_initialize in Drupal 6
Same name and namespace in other branches
- 7 includes/language.inc \language_initialize()
Choose a language for the page, based on language negotiation settings.
1 call to language_initialize()
- drupal_init_language in includes/
bootstrap.inc - Choose a language for the current page, based on site and user preferences.
File
- includes/
language.inc, line 11 - Multiple language handling functionality.
Code
function language_initialize() {
global $user;
// Configured presentation language mode.
$mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
// Get a list of enabled languages.
$languages = language_list('enabled');
$languages = $languages[1];
switch ($mode) {
case LANGUAGE_NEGOTIATION_NONE:
return language_default();
case LANGUAGE_NEGOTIATION_DOMAIN:
foreach ($languages as $language) {
$parts = parse_url($language->domain);
if (!empty($parts['host']) && $_SERVER['HTTP_HOST'] == $parts['host']) {
return $language;
}
}
return language_default();
case LANGUAGE_NEGOTIATION_PATH_DEFAULT:
case LANGUAGE_NEGOTIATION_PATH:
// $_GET['q'] might not be available at this time, because
// path initialization runs after the language bootstrap phase.
$args = isset($_GET['q']) ? explode('/', $_GET['q']) : array();
$prefix = array_shift($args);
// Search prefix within enabled languages.
foreach ($languages as $language) {
if (!empty($language->prefix) && $language->prefix == $prefix) {
// Rebuild $GET['q'] with the language removed.
$_GET['q'] = implode('/', $args);
return $language;
}
}
if ($mode == LANGUAGE_NEGOTIATION_PATH_DEFAULT) {
// If we did not found the language by prefix, choose the default.
return language_default();
}
break;
}
// User language.
if ($user->uid && isset($languages[$user->language])) {
return $languages[$user->language];
}
// Browser accept-language parsing.
if ($language = language_from_browser()) {
return $language;
}
// Fall back on the default if everything else fails.
return language_default();
}