Re: BUG #7664: Program using libpq and ecpglib can not output native language

From: Chen Huajun <chenhj(at)cn(dot)fujitsu(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #7664: Program using libpq and ecpglib can not output native language
Date: 2012-11-16 08:02:18
Message-ID: 50A5F30A.60405@cn.fujitsu.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi,tom lane

> No, it would most certainly be inappropriate for a library to do that.
> setlocale could completely break a program that wasn't expecting it.
> The effects would be global across the whole process, not confined to
> the library.

First,does you agree with the need of native language support without writing
"setlocale(LC_ALL, "")"in user's program is rational?
If the answer is yes, let see if there is a mothod to solve it.
Simply write "setlocale(LC_ALL, "")" in libpq and ecpglib may cause other
problems as you said. But how about only call setlocale() before call dgettext(),
and soon restore to the original value after called.

*)Excuse me for my English.

for example:
libpq_gettext(const char *msgid):
=====================================================
return dgettext(PG_TEXTDOMAIN("libpq"), msgid);

==>
char *result;
if(strcmp(setlocale(LC_MESSAGES,NULL),"C")==0)
{
setlocale(LC_MESSAGES, "");
result = dgettext(PG_TEXTDOMAIN("libpq"), msgid);
setlocale(LC_MESSAGES, "C");
}else
{
result = dgettext(PG_TEXTDOMAIN("libpq"), msgid);
}
return result;
=====================================================

(2012/11/16 13:22), Tom Lane wrote:
> chenhj(at)cn(dot)fujitsu(dot)com writes:
>> I knows reason. The default locale of a program is "C" in Linux,regardless
>> the Environment Variables.
>> if add the following line in my program,everything is OK.
>
>> setlocale(LC_ALL, "");
>
>> But I found no document tell users should do so.And I think it's not a easy
>> way.Can libpq and ecpglib do it for users?
>
> No, it would most certainly be inappropriate for a library to do that.
> setlocale could completely break a program that wasn't expecting it.
> The effects would be global across the whole process, not confined to
> the library.
>
> regards, tom lane
>
>

--
Best Regards,
chen hujuan

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Kapila 2012-11-16 11:40:03 Re: Re: [BUGS] BUG #7534: walreceiver takes long time to detect n/w breakdown
Previous Message Tom Lane 2012-11-16 05:22:16 Re: BUG #7664: Program using libpq and ecpglib can not output native language