locale_accept_from_http
is a basic wrapper around ICU's API uloc_acceptLanguageFromHTTP
but the PHP/PECL implementation seems fundamentally flawed that it uses the systems entire set of locales instead of taking a list as a parameter?
For example say a user has HTTP_ACCEPT_LANGUAGE = zh-HK;q=0.2, fr
, i.e. the user reads Traditional Chinese or French, preferring the latter. You have, for example, a news site that offers articles in say Traditional Chinese and Simplified Chinese. Using the API
Locale::acceptFromHttp
will only return fr
.
<?php
var_dump (Locale::acceptFromHttp ("zh-HK;q=0.2,fr"));
?>
Outputs:
string(2) "fr"
Correct, PHP wraps ICU's uloc_acceptLanguageFromHTTP
without the ability to pass your locale list. Overall, intl
extension is relatively new (PHP 5.3+) and I did find a couple of bugs myself which were quickly fixed within the next release.
What you could do is:
Submit a bug/feature request. There is a similar bug already reported.
Accept-Language format is really not that complex, I bet you could write your own parser within 20 lines of code. See this article for an example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With