Forum Moderators: coopster

Message Too Old, No Replies

outputting a different language dynamically

changing the language of PHP output on the fly

         

dareRock

3:34 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



i can't figure this out, yet it seems so simple.

i have a site with an english and french version - i output the current date on the english one, but need to output the current date in french on the french version.

simple php is date("l F j, Y") for the date

is there a way i can do...

language("French");
echo date("l F j, Y");

?

Thanks in advance

jatar_k

4:01 pm on Feb 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not sure actually

you could build some arrays of the french names and then swap them.

also remember that your format you have there is actually wrong in french, you have to swap the month and day for french. I don't remember how they add day of the week, I don't remember seeing it much actually.

<added>as an aside, there is no fun or easy way to do internationalization, it sucks. I was sitting around with some fairly well known php folk a while back and that was our agreed on unanymous position 'it sucks'.

coopster

4:55 pm on Feb 28, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I won't pretend to be an internationalization expert but I have worked in the area. Apache lends itself nicely as an HTTP server to get a lot of the work done for you in terms of content negotiation. Of course, the content itself still needs to be written.

To serve up the date using PHP I find setlocale [php.net] to be a great tool. I've added a little trick to determine whether or not the server is a Windows server as well since the codes may be different depending on the server you are running and how you have it setup (what I mean is that 'french' could likely be used here for both but sometimes you'll have to check the locale files to be sure). Links to the codes are on the PHP setlocale page. Oh yeah, you can also get fancy by checking the $_SERVER['HTTP_ACCEPT_LANGUAGE'] or extension of the $_SERVER['SCRIPT_NAME'] if you have setup your site with multi documents per language.


if (stristr [php.net](PHP_OS [php.net], 'WIN')) {
setlocale [php.net](LC_ALL, 'fra');
} else {
setlocale [php.net](LC_ALL, 'french');
}
print strftime [php.net]('%A %B %j, %Y ');
?>

I used the original format you laid down, jatar_k knows his French much better than I though so you'll probably want to double-check that format.

dareRock

6:59 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



thanks jatar and coopster...

thats what i figured - 'it sucks'

for the nature of my project and timeline, i think i'm going to use the array method and swap english terms for french....yes, the date ordering needs to be change for french.

ill probably just make a modular method to drop into any php app to return the french formated date.

Thanks for your input on this...always appreciated