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:
cam.lafit
2013-06-10 10:43:01 +02:00
parent a73326bfb2
commit 663ec76bb9
2 changed files with 6 additions and 2 deletions
+3 -1
View File
@@ -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');
}