Skip to content

Instantly share code, notes, and snippets.

@dharmastyle
Created February 3, 2015 13:32
Show Gist options
  • Save dharmastyle/bba6c387c0642aafda8d to your computer and use it in GitHub Desktop.
Save dharmastyle/bba6c387c0642aafda8d to your computer and use it in GitHub Desktop.
/**
* Return available client language choosen from $availableLanguages array
*/
function getClientLanguage($availableLanguages = null, $default='en'){
// Keeps BC and looks for embedded function instead of pass a parameter
$availableLanguages = $availableLanguages ?: getAvailableLanguages();
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
//start going through each one
foreach ($langs as $value){
$choice=substr($value,0,2);
if(in_array($choice, $availableLanguages)){
return $choice;
}
}
}
return $default;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment