Forum Moderators: coopster

Message Too Old, No Replies

I need to format dates in different languages

Is setlocale the way forward or is another method better?

         

theskintman

5:49 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



I have dates stored in a database on a multilingual site. I need to print them out to different people in different languages (using abbreviated month names).

The date() function page says I should use setlocale() and strftime(), but setlocale() also says "The locale information is maintained per process, not per thread."

I'm not really up on what this means - I want the change of setting to only last for the length of the current page's processing - I don't want to change the core PHP locale, only the presentation of the current date from English to, say, Spanish.

Am I OK to use setlocale(), or should I use something different?

coopster

10:01 pm on Nov 27, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It depends on the server. You need to continue reading that help note on that page:


The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server api like IIS or Apache on Windows you may experience sudden changes of locale settings while a script is running although the script itself never called setlocale() itself. This happens due to other scripts running in different threads of the same process at the same time changing the processwide locale using setlocale().

theskintman

9:17 am on Nov 28, 2006 (gmt 0)

10+ Year Member



My server is Apache on Debian. I think what I interpret from this is that each time I change the locale, it changes it at the core of PHP (process) and would therefore affect each other page being processed (thread).

Is this right? I'm not really up on all this thread/process stuff.

coopster

3:27 pm on Nov 29, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are likely going to be fine using setlocale(). I use it in the same manner you are describing without issue. Default installs on *nix platforms should be fine. If you really want to start learning more about threading, you can start with the Apache worker [httpd.apache.org] docs but you will find even more information by searching the internet for terms like "server threads". Grab some coffee first, the reading is going to require some ;)