Skip to content

Instantly share code, notes, and snippets.

@aabril
Created July 7, 2011 15:27
Show Gist options
  • Select an option

  • Save aabril/1069760 to your computer and use it in GitHub Desktop.

Select an option

Save aabril/1069760 to your computer and use it in GitHub Desktop.
CodeIgniter method that extends Language.php for get the language by browser.
public function get_langname_byBrowser()
{
$this->CI = & get_instance();
// inicializamos, por si no detecta ninguna el navegador
$name = "";
//prepare user language array
$languages = array();
$languages[0] = '';
//check to see if language is set
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
{
//explode languages into array
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
$languages = explode( ",", $languages );
}
$pos = strpos(strtolower($languages[0]),'es');
if ( $pos !== false )
$name = "spanish";
else
$name = "english";
return $name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment