function i18n_get_browser_lang in Internationalization 5
Same name and namespace in other branches
- 5.3 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_get_lang in ./
i18n.module - Gets language, checking in order:
File
- ./
i18n.module, line 430 - 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);
}
}
}