开发者

How to use Locale::acceptFromHttp without a filter list?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜