有没有一种方法可以获取PHP中可用语言环境的列表? [英] Is there a way to get the list of available locales in PHP?

查看:76
本文介绍了有没有一种方法可以获取PHP中可用语言环境的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,您可以调用Locale.getAvailableLocales()以获得可用语言环境的列表.

In Java, you can call Locale.getAvailableLocales() to get the list of available locales.

我期望从PHP Locale 类中获得等效的结果,但不能找到一个.

I was expecting an equivalent from the PHP Locale class, but could not find one.

是否可以获取所有有效语言环境的数组?

Is there a way to get an array of all valid Locales?

推荐答案

部分混乱之处在于,PHP具有两个称为"locale"的概念,它们几乎完全分开.

Part of the confusion here is that PHP has two concepts called "locale" that are pretty much totally separate.

第一个是较旧的版本,基本上只使用C语言环境功能.这就是setlocale背后的原因,以及某些PHP函数的语言环境支持(例如money_format).这就是提到在命令行上运行locale -a并使用setlocale的其他答案.

The first is the older one, which basically just uses the C locale features. That's what's behind setlocale and the locale support in some of PHP's functions (like money_format for example). This is what other answers that mention running locale -a on the command line and using setlocale are talking about.

PHP的Locale类和intl扩展名中的其他相关功能是较新的,并且不能以相同的方式工作.它没有使用libc语言环境的东西,而是使用一个称为ICU的库,该库提供了自己的语言环境数据. PHP 确实提供了一种确定系统支持哪些语言环境的方法:

PHP's Locale class and the other related functionality from the intl extension is newer, and doesn't work the same way. Instead of using the libc locale stuff, it uses a library called ICU, which ships its own locale data. PHP does provide a method to determine which locales are supported by this system: ResourceBundle::getLocales. The documentation is a little wooly here, but you can call this as a static method and pass the blank string to use ICU's default resources, thus getting a list of the supported locales for intl:

ResourceBundle::getLocales('');

这篇关于有没有一种方法可以获取PHP中可用语言环境的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆