本文介绍了如何在没有过滤器列表的情况下使用Locale :: acceptFromHttp?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

locale_accept_from_http是围绕ICU API uloc_acceptLanguageFromHTTP 的基本包装但是PHP/PECL实现似乎从根本上存在缺陷,即它使用系统的整个语言环境集而不是使用列表作为参数?

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?

例如,假设某用户具有HTTP_ACCEPT_LANGUAGE = zh-HK;q=0.2, fr,即该用户阅读繁体中文或法语,则偏爱后者.例如,您有一个新闻网站,提供用繁体中文和简体中文撰写的文章.使用API​​ Locale::acceptFromHttp仅返回fr.

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"));
?>

输出:

string(2) "fr"

推荐答案

正确的,PHP包装了ICU的uloc_acceptLanguageFromHTTP而没有传递语言环境列表的能力.总体而言,intl扩展是相对较新的(PHP 5.3+),我自己也发现了一些错误,这些错误已在下一发行版中迅速修复.

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.

您可以做的是:

  • Submit a bug/feature request. There is a similar bug already reported.

Accept-Language格式实际上并不那么复杂,我敢打赌,您可以在20行代码中编写自己的解析器.有关示例,请参见本文.

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.

这篇关于如何在没有过滤器列表的情况下使用Locale :: acceptFromHttp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 12:36