Re: BUG #7664: Program using libpq and ecpglib can not output native language
От | Chen Huajun |
---|---|
Тема | Re: BUG #7664: Program using libpq and ecpglib can not output native language |
Дата | |
Msg-id | 50A5F30A.60405@cn.fujitsu.com обсуждение исходный текст |
Ответ на | Re: BUG #7664: Program using libpq and ecpglib can not output native language (Tom Lane <tgl@sss.pgh.pa.us>) |
Ответы |
Re: BUG #7664: Program using libpq and ecpglib can not output native language
|
Список | 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$B!)(B 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
В списке pgsql-bugs по дате отправления: