I'm setting up locales so that I can later use PHP's strftime function to output date strings correctly according to a user's language.

echo setlocale(LC_ALL, $code.'.UTF8') ? $name : 'Failed to set to '.$name;

(variables are set, this is just an exerpt)

When run from the command line, the script works, sets the locale and later outputs the day and month names in the correct language through strftime.

When run from a webpage (powered by Apache), the script fails to set the locale.

The server is running Debian. The odd thing is, the same script works properly from both cil and apache in another, local Debian box. Language packs were installed on both machines using apt-get install locales-all.

Is there a setting somewhere that could be causing the locale setting to fail on the live box?

link|improve this question

80% accept rate
I don't deal with locale's much at all, but what does running locale -a return? Does it show the locale you are trying to set? – Rob Jun 15 '11 at 14:18
Yes. The locales are settable - but only from PHP CLI. – bcmcfc Jun 15 '11 at 16:16
'Have you turned it on and off again?' In this case, meaning have you restarted Apache? Probably have, just checking. Beyond that I'm no help here! :) – Rob Jun 15 '11 at 16:17
feedback

1 Answer

might be too late but good for other debian users like me who had the same problem I found mine worked after I did this below. I think on some debians the LANGUAGE had to be used instead of just LANG

<?php
$locale = 'th_TH.UTF-8';
putenv("LC_ALL=$locale");
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
setlocale(LC_ALL, $locale);

bindtextdomain ("messages", "./lang");
textdomain ("messages");

echo _("Say this in thai"), "\n";

?>
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.