I have installed the dutch l开发者_运维技巧ocal (nl_NL utf8
) on my webserver (when I execute locale -a
I see nl_NL utf8
so this is allright).
However, the dates on my webpage are in english (I have put setlocale(LC_ALL, 'nl_NL');
in the top of my pages). I have read when you install a locale package after compiling php, I have to recompile php.
But is there any other solution, without recompiling php, to let it work?
Thanks!
I summarize here what I have found facing a similar problem, since here there have been apparently no constructive answer (a wrong one, indeed: setlocale()
does change the output of strftime()
) and it can be useful for others.
PHP manual says
Return Values
Returns the new current locale, or FALSE if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.
so for the diagnosys, first check that the right locale is installed (nl_NL, nl_NL.UTF-8, etc.), either using a shell or in PHP system('locale -a')
. On some ubuntu systems there is a script to install a locale, eg. /usr/share/locales/install-language-pack nl_NL
but installing with apt-get may be considered too.
(For exotic locales, also check that locale is supported: on some systems /usr/share/i18n/SUPPORTED
).
Then you can get the output of setlocale() using var_dump(setlocale('nl_NL'));
(since setlocale()
alone doesn't output anything).
For the cure could be to regenerate locale with locale-gen nl_NL, nl_NL
Thereafter, update-locale
(and dpkg-reconfigure locales
) can be required on some systems.
This may be by design: setlocale()
does not automatically change the output of the format of dates output using date()
and strftime()
. What it does is localize the weekday and month names, but nothing else.
Can you show some examples of how you output dates, and how they fail to get converted?
I would like to add another thing to bear in mind.
If the locale wasn't installed and you just installed the new locale (e.g. via sudo locale-gen nl_NL.utf8
and sudo update-locale
), you also need to make sure to restart php-fpm, e.g. by running sudo service php8.1-fpm restart
if you are running PHP 8.1.
I noticed setting the locale would work just fine in the console, but not in the web app. Locales are obviously cached within the process.
精彩评论