Pages

Detect Browser Language

At the point when creating a multilingual site, I truly jump at the chance to recover the browser language and utilize this language as the default language for my site. Here's the way I get the language utilized by the client browser:

function get_client_language($availableLanguages, $default='en'){
 if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
  $langs=explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);

  foreach ($langs as $value){
   $choice=substr($value,0,2);
   if(in_array($choice, $availableLanguages)){
    return $choice;
   }
  }
 } 
 return $default;
}
Source : http://snipplr.com/view/12631/detect-browser-language/php-detect-browser-language