diff --git a/base.php b/base.php index bae8407..6f3eeaa 100644 --- a/base.php +++ b/base.php @@ -197,7 +197,12 @@ function getAcceptLanguages() { if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { // break up string into pieces (languages and q factors) - preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_parse); + $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE']; + if (preg_match('/^(\w{2})-\w{2}$/', $accept, $matches)) { + // Special fix for IE11 which send fr-FR and nothing else + $accept = $accept . "," . $matches[1] . ";q=0.8"; + } + preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $accept, $lang_parse); if (count($lang_parse[1])) { $langs = array(); diff --git a/test/baseTest.php b/test/baseTest.php index 5a8947e..4b46443 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -106,7 +106,10 @@ class BaseTest extends PHPUnit_Framework_TestCase return array ( array ("en", "en"), array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), + array ("fr-FR", "fr"), array ("pt,en-us;q=0.7,en;q=0.3", "en"), + array ("pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3", "pt_BR"), + array ("pt-pt,pt;q=0.8,en;q=0.5,en-us;q=0.3", "pt_PT"), array ("zl", "en"), ); } @@ -129,8 +132,9 @@ class BaseTest extends PHPUnit_Framework_TestCase return array ( array ("en", "en"), array ("en-US", "en_US"), - array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), - array ("fr-fr,fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr_FR"), + array ("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3", "fr"), // French locale with Firefox + array ("fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4", "fr_FR"), // French locale with Chrome + array ("fr-FR", "fr_FR"), // French locale with IE11 array ("pt-br,pt;q=0.8,en-us;q=0.5,en;q=0.3", "pt_BR"), array ("zl", "zl"), );