Using Yii 1.1.14, I encounter a problem with preferred languages detection in Android’s built-in browser (not Chrome). Here is the code of the method which I have been using before I moved to 1.1.14, and this implementation works as expected, so I patched 1.1.14 for myself. I did not dig into the code to pinpoint where is the bug in Yii’s implementation. Just want to let you know that the code below (it is borrowed from some Yii commits in the past) is free from the bug.
public function getPreferredLanguages()
{
if($this->_preferredLanguages===null)
{
$sortedLanguages = array();
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && ($n=preg_match_all('/([\w\-_]+)\s*(;\s*q\s*=\s*(\d*\.\d*))?/',$_SERVER['HTTP_ACCEPT_LANGUAGE'],$matches))>0)
{
$languages=array();
for($i=0;$i<$n;++$i) {
$prefVal=empty($matches[3][$i]) ? 1.0 : floatval($matches[3][$i]);
if (!isset($languages[$matches[1][$i]]) || $languages[$matches[1][$i]][0] < $prefVal) {
$languages[$matches[1][$i]][0] = $prefVal;
$languages[$matches[1][$i]][1] = $i;
$languages[$matches[1][$i]][2] = $matches[1][$i];
}
}
usort($languages, create_function('$a, $b', 'if ($a[0] < $b[0]) { return 1; } else if ($a[0] > $b[0]) { return -1; } else if ($a[1] < $b[1]) { return -1; } else if($a[1] > $b[1]) { return 1; } else { return 0; }'));
for($i=0;$i<count($languages);$i++) {
$sortedLanguages[] = $languages[$i][2];
}
}
$this->_preferredLanguages = $sortedLanguages;
}
return $this->_preferredLanguages;
}