Is there a way to get the list of available locales in PHP?(有没有办法在 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 有两个被称为语言环境"的概念,它们几乎完全分开.
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 extension 较新,但工作方式不同.它没有使用 libc 语言环境的东西,而是使用一个名为 ICU 的库,该库提供自己的语言环境数据.PHP确实提供了一种方法来确定这个系统支持哪些语言环境:ResourceBundle::getLocales.这里的文档有点冗长,但是您可以将其作为静态方法调用并传递空白字符串以使用 ICU 的默认资源,从而获得 intl 支持的语言环境列表:
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 中获取可用语言环境的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有办法在 PHP 中获取可用语言环境的列表?
基础教程推荐
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
