Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

internationalization - Is there a way to get the list of available locales in PHP?

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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'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('');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...