I'm using fRequest 'accept' methods as a lighter replacement for the language detection routines I was using (http://techpatterns.com/downloads/php_language_detection.php). However, I have noted some odd behaviour in detected languages (with PHP 5.3.2).
For example, var_dump(fRequest::getAcceptLanguages()) returns the correct languages as defined in my Mac Firefox 3.6.3, that is:
array(8) { ["es-es"]=> float(1) ["es"]=> float(0.9) ["en-gb"]=> float(0.8) ["en-us"]=> float(0.6) ["en"]=> float(0.5) ["fr-fr"]=> float(0.4) ["fr-be"]=> float(0.3) ["it"]=> float(0.1) }
But var_dump(fRequest::getBestAcceptLanguage()) doesn't return string(5) "es-es", as would be expected, but:
string(2) "es"
Changing the order of both calls doesn't make any difference. Looking at the code in fRequest, it seems that, in absence of any filters defined in the call, it should just return the first key in the languages array:
if (!$options) {
return key($items);
}
However, for some reason, key() is not pointing to the first array element, but to the second one. Maybe a reset() should be added to be assured that we really start picking from the first element:
$items = self::processAcceptHeader($header);
reset($items); // Be sure we start from the first element
if (!$options) {
return key($items);
}
Regards,
A.