pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chen Huajun <chenhj@cn.fujitsu.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7664: Program using libpq and ecpglib can not output native language
Date: Fri, 16 Nov 2012 16:02:18 +0800
Message-ID: <50A5F30A.60405@cn.fujitsu.com> (raw)
In-Reply-To: <4803.1353043336@sss.pgh.pa.us>
References: <E1TZCv4-0002iN-H0@wrigleys.postgresql.org>
	<4803.1353043336@sss.pgh.pa.us>

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@cn.fujitsu.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





view thread (5+ messages)  latest in thread

Message-ID: <50A5F30A.60405@cn.fujitsu.com>
Permalink:  ../50A5F30A.60405@cn.fujitsu.com/
Also on:    postgresql.org/message-id/50A5F30A.60405@cn.fujitsu.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: chenhj@cn.fujitsu.com, tgl@sss.pgh.pa.us
  Subject: Re: BUG #7664: Program using libpq and ecpglib can not output native language
  In-Reply-To: <50A5F30A.60405@cn.fujitsu.com>
  References: <E1TZCv4-0002iN-H0@wrigleys.postgresql.org> <4803.1353043336@sss.pgh.pa.us> <50A5F30A.60405@cn.fujitsu.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox