Better regexp to get country browser from HTTP_ACCEPT_LANGUAGE
With HTTP_ACCEPT_LANGUAGE we have two choices : * Country == language (displayed with two letter as fr,de,en,...) * Country with multi language (displayes as fr-CH, de-CH, it-CH) Previous regexp find only first case.
This commit is contained in:
@@ -303,7 +303,9 @@ class AddressControllerCore extends FrontController
|
||||
$selected_country = (int)$this->_address->id_country;
|
||||
else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
||||
{
|
||||
$array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
||||
// get all countries as language (xy) or language-country (wz-XY)
|
||||
$array = array();
|
||||
preg_match("#(?<=-)\w\w|\w\w(?!-)#",$_SERVER['HTTP_ACCEPT_LANGUAGE'],$array);
|
||||
if (!Validate::isLanguageIsoCode($array[0]) || !($selected_country = Country::getByIso($array[0])))
|
||||
$selected_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user