function i18n_get_browser_lang in Internationalization 5.3
Same name and namespace in other branches
- 5 i18n.module \i18n_get_browser_lang()
- 5.2 i18n.module \i18n_get_browser_lang()
Get language from browser settings, but only if it is a valid language
1 call to i18n_get_browser_lang()
- i18n.module in ./
i18n.module - Internationalization (i18n) module
File
- ./
i18n.module, line 474 - Internationalization (i18n) module
Code
function i18n_get_browser_lang() {
$languages = i18n_supported_languages();
$exploded_server = explode(";", $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
$accept = explode(',', array_shift($exploded_server));
foreach ($accept as $lang) {
if (empty($lang)) {
continue;
}
elseif (array_key_exists($lang, $languages)) {
return $lang;
}
elseif (array_key_exists(substr($lang, 0, 2), $languages)) {
return substr($lang, 0, 2);
}
}
}