I have the following code which I believe should output fr_FR
as the locale but for some reason is outputting en_US_POSIX
(it does this on any timezone). What have I done wrong?
$loc = IntlCalendar::createInstance(new DateTimeZone('Europe/Paris'));
echo $loc->getLocale(Locale::VALID_LOCALE);
For refs:
https://www.php.net/manual/en/intlcalendar.createinstance.php and https://www.php.net/manual/en/intlcalendar.getlocale.php
2
Answers
You set the time zone to that of Paris. But you didn’t set the locale. They’re different things. Locale defines language and formatting conventions, whereas time zone sets the rules for converting UTC to local time and back again. What you have defined is suitable for An American in Paris. That’s a valid use case, especially in August!
Try this:
The ICU/INTL locale is not based on the timezone. It’s using the default value that can be set either through the PHP ini settings or anywhere in your code.
In order for the locale to be different you can change it in the INI settings (this will be used by any PHP script that runs using that INI file). Alternatively, you can specify it in your code either very early on (similar to using the INI setting), or you can specify it in various INTL class methods (such as when you have a user-specific locale you want to use to display information formatted in a way the user might expect), but not affect code outside of the user-specific portion: