base_language = ''; $base_language = ''; $this->default_language = $default_language; //An array of available languages based on the ISO 639-1 standard $available_languages_array = array( "ar", // "Arabic", "en", // "English", "de", // "German", "el", // "Greek", "es", // "Spanish", "fr", // "French", "it", // "Italian", "zh", // "Chinese", ); //GH - strtolower changes the returned string to lower case to match the keys of the $languages_array if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){ $languages_from_browser = strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]); }else{ $languages_from_browser = null;// it'a bot or search engine } //Get position of ";" in languages (for values such as "en,es;q=0.5") $pos = stripos($languages_from_browser,";"); if ($pos>0){ //Get the string from the first character onwards excluding chars after the ; character. $languages_from_browser = substr($languages_from_browser,0,$pos); } //chop string into chunks using ; as delimiter $full_data = array_map("trim", explode(";", $languages_from_browser)); //further chop the string using , to leave the full language-country pair. $full_data = array_map("trim", explode(",", $full_data[0])); $this->full_browser_string = $full_data[0]; $browser_string = $this->full_browser_string; /******************************* Next Bit *******************************/ //Now need to compare the results to the available languages in the $available_languages_array to find if there is a match or not //If there is a match the matched language become the default language and is loaded either in the form of web pages or dictionaries //If there is no match then the language default remains the $default_language set by the user. //We look through to find an exact match of the language-country pair to the $available_languages_array foreach ($available_languages_array as $arrayItem){ if ($arrayItem == $browser_string){ $default_language = $arrayItem; $this->default_language = $arrayItem;//Load the relevant dictionaries or language files return; } } //Else find the language (1st 2 letters) part of the language country pair and set the default language to the language part. foreach ($available_languages_array as $arrayItem){ $pos=stripos($browser_string,"-"); if ($pos>0){ $base_language = substr($browser_string,0,$pos); } if ($arrayItem == $base_language){ $default_language = $arrayItem; $this->default_language = $arrayItem;//Load the relevant dictionaries or language files return; } } // Didn't find a matching language in the $available_languages_array, load the relevant dictionaries or language files. $this->default_language = $default_language; } } $default_language = 'en';//Default page language is set by the site administrator $locale = new browser_language_detect($default_language); ?>