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;
|
$selected_country = (int)$this->_address->id_country;
|
||||||
else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
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])))
|
if (!Validate::isLanguageIsoCode($array[0]) || !($selected_country = Country::getByIso($array[0])))
|
||||||
$selected_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
$selected_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,9 @@ class AuthControllerCore extends FrontController
|
|||||||
|
|
||||||
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
|
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]) || !($sl_country = Country::getByIso($array[0])))
|
if (!Validate::isLanguageIsoCode($array[0]) || !($sl_country = Country::getByIso($array[0])))
|
||||||
$sl_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
$sl_country = (int)Configuration::get('PS_COUNTRY_DEFAULT');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user