Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZGtx-0001uj-5Q for pgsql-bugs@postgresql.org; Fri, 16 Nov 2012 08:03:49 +0000 Received: from [222.73.24.84] (helo=song.cn.fujitsu.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TZGts-0004pY-IW for pgsql-bugs@postgresql.org; Fri, 16 Nov 2012 08:03:47 +0000 X-IronPort-AV: E=Sophos;i="4.83,262,1352044800"; d="scan'208";a="6213116" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 16 Nov 2012 16:01:48 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id qAG83S6B003128; Fri, 16 Nov 2012 16:03:28 +0800 Received: from [127.0.0.1] ([10.167.159.99]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012111616032081-1201784 ; Fri, 16 Nov 2012 16:03:20 +0800 Message-ID: <50A5F30A.60405@cn.fujitsu.com> Date: Fri, 16 Nov 2012 16:02:18 +0800 From: Chen Huajun User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.2.28) Gecko/20120306 Lightning/1.0b2 Thunderbird/3.1.20 MIME-Version: 1.0 To: Tom Lane CC: pgsql-bugs@postgresql.org Subject: Re: BUG #7664: Program using libpq and ecpglib can not output native language References: <4803.1353043336@sss.pgh.pa.us> In-Reply-To: <4803.1353043336@sss.pgh.pa.us> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/16 16:03:20, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/11/16 16:03:21, Serialize complete at 2012/11/16 16:03:21 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-2022-JP X-Host-Lookup-Failed: Reverse DNS lookup failed for 222.73.24.84 (failed) X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201211/89 X-Sequence-Number: 34647 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