Roman Neuhauser wrote:
> # [EMAIL PROTECTED] / 2006-11-03 22:18:03 +0100:
>> Roman Neuhauser wrote:
>>> # [EMAIL PROTECTED] / 2006-11-03 16:16:11 +0100:
>>>> Roman Neuhauser wrote:
>>>>> # [EMAIL PROTECTED] / 2006-11-03 14:51:39 +0100:
>>>>>> 1. running the command 'locale -a' returns the following [shortened]
>>>>>> list:
>>>>>>
>> ...
>>
>>>>>> in fact I can set any installed locale I want on the commandline BUT
>>>>>> trying to set any other than the originally installed "[EMAIL
>>>>>> PROTECTED]" in
>>>>>> code running via Apache results in FALSE being returned and the locale
>>>>>> not being set.
>>>>>>
>>>>>> has anybody got a clue for me?
>>>>> You don't mention what warning(s) the failing setlocale() call
>>>>> produces.
>>>> it just returns false, telling me that the chosen locale(s) was/were not
>>>> set - there
>>>> is no PHP error at all.
>>> I just checked the setlocale() code (in HEAD), and surely it can
>>> return false without a warning, it can even be an almost empty (and
>>> just as quiet) stub that just returns false, depending on the value
>>> of HAVE_SETLOCALE during compilation.
>> thank you for doing this ... turns out that indeed the locale is being set
>> but the return value is false, I've settled for not checking the return
>> value and
>> just assuming (blindly hoping) the setlocale worked - I don't really know
>> what
>> else there is to do, besides ik works :-)
>
> How did you confirmed that the locale got set?
there is no simple way to determine if the locale was set because setlocale()
is returning
false even when a locale has been successfully set, given that for each
langauge I have a list
of locales (to be able to handle different server/OS setups) I can never be
sure which locale
in the list was actually set - now I suppose you could check the output of a
locale aware function
to see if the output is in the desired locale BUT this would mean having to
have some know output
to check against for each locale - that sounds like a recipe for messy,
horrible (and quite
likely brittle if not unreliable) code.
>
>>> Try a simple CGI script, does
>>> locale manipulation succeed there?
>> I'd have to look up how to setup a php-cgi ...
>
> It doesn't have to be written in PHP.
>
> Compile the following program and try it from the command line:
ok, wow - I'm definitely going to have a play with this when I have a
quite moment! nice one Roman! thank you.
>
> #include <errno.h>
> #include <string.h>
> #include <stdio.h>
> #include <locale.h>
>
> int
> main(int argc, char **argv)
> {
> if (2 > argc) {
> return printf("usage: %s <locale>\n", *argv);
> }
> char *old = setlocale(LC_ALL, NULL);
> printf("old: %p \"%s\"\n", old, old);
> char *loc = setlocale(LC_ALL, argv[1]);
> char *check = setlocale(LC_ALL, NULL);
> printf("check: %p \"%s\"\n", check, check);
> if (0 == loc) {
> printf("setlocale: \"%s\"\n", strerror(errno));
> return 1;
> }
> return printf("new: %p \"%s\"\n", loc, loc);
> }
>
> Put "AddHandler cgi-script .cgi" in your apache config
> and call the above from the script below, does the output differ?
>
> foo.cgi:
>
> #!/bin/sh
> printf "Content-Type: text/plain\r\n\r\n"
> /path/to/the-above-program en_GB
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php