Is there an easy way to parse the user's HTTP_ACCEPT_LANGUAGE and set the locale in PHP?

有没有一种简单的方法来解析用户的HTTP_ACCEPT_LANGUAGE并在PHP中设置语言环境?

I know the Zend framework has a method to do this, but I'd rather not install the whole framework just to use that one bit of functionality.

我知道Zend框架有一个方法可以做到这一点,但我宁愿不安装整个框架只是为了使用那一点功能。

The PEAR I18Nv2 package is in beta and hasn't been changed for almost three years, so I'd rather not use that if possible.

PEAR I18Nv2软件包处于测试阶段,并且近三年没有改变,所以如果可能的话我宁愿不使用它。

Also nice would be if it could figure out if the server was running on Windows or not, since Windows's locale strings are different from the rest of the world's... (German is "deu" or "german" instead of "de".)

如果它可以判断服务器是否在Windows上运行,那也很好,因为Windows的语言环境字符串与世界其他地方不同......(德语是“deu”或“german”而不是“de”。 )

4 个解决方案

#1


2

Nice solution is on its way.

好的解决方案即将推出。

Without that you'll need to parse that header. It's a comma-separated list of semicolon-separated locales and attributes.

如果没有它,您将需要解析该标头。它是以逗号分隔的以分号分隔的区域设置和属性的列表。

It can look like this:

它看起来像这样:

en_US, en;q=0.8, fr_CA;q=0.2, *;q=0.1

and then try each locale until setlocale() accepts it. Be prepared that none of them may match.

然后尝试每个语言环境,直到setlocale()接受它。做好准备,没有一个可以匹配。

Don't base on it anything too important or allow users to override it, because some users may have misconfigured browsers.

不要基于它太重要或允许用户覆盖它,因为一些用户可能有错误配置的浏览器。


For Windows locale, perhaps you need to convert ISO 639-1 names to ISO 639-2/3?

对于Windows语言环境,您可能需要将ISO 639-1名称转换为ISO 639-2 / 3吗?

更多相关文章

  1. dedecms lnmp 环境搭建。备忘录非教程
  2. Windows7搭建Apache本地服务器+PHP环境
  3. 存储用户所需语言的最佳方式
  4. PHP常量PHP_SAPI与函数php_sapi_name()简介,PHP运行环境检测
  5. php环境中的ini配置
  6. PHP语言的中回车换行
  7. 阿里云ECS服务器Linux环境下配置php服务器(三)--项目部署篇
  8. phpstorm+wamp+xdebug配置php调试环境
  9. [php入门] 1、从安装开发环境环境到(庄B)做个炫酷的登陆应用

随机推荐

  1. android AutoCompleteTextView
  2. android常见问题汇总大全
  3. Android2.2 自带主题themes.xml的源代码
  4. Android 开发笔记 - Android Studio 代码
  5. Android之开启内置闹钟与已安装的应用程
  6. Android 文件浏览器源码
  7. Android命令行启动程序正确使用技巧解析
  8. Android:简单联网获取网页代码
  9. 第一行代码笔记之——Activity启动模式
  10. 设置可见和隐藏