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?
Locale information is language, monetary, time and other information specific for a geographical area. Note: The setlocale() function changes the locale only for the current script. Tip: The locale information can be set to system default with setlocale(LC_ALL,NULL)
fr is the locale name for standard French. fr_FR is the locale name for French in France. fr_CA is the locale name for French in Canada.
In computing, a locale is a set of parameters that defines the user's language, region and any special variant preferences that the user wants to see in their user interface. Usually a locale identifier consists of at least a language code and a country/region code.
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('');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With