Thread: libpq messages language

libpq messages language

From
Efraín López
Date:
Hi,
 
I am using Windows, and pg 8.2.5
 
When making a connection with libpq, if it fails I would like to get the errors messages in spanish (PQerrorMessage  )
 
Is this possible? How can this be done?
 
thanks
 

Re: libpq messages language

From
"Albe Laurenz"
Date:
Efraín López wrote:
> I am using Windows, and pg 8.2.5
>
> When making a connection with libpq, if it fails I would like
> to get the errors messages in spanish (PQerrorMessage  )
>
> Is this possible? How can this be done?

Set the program's locale prior to calling libpq functions.

I did not try it on Windows, but Microsoft seems to work like
UNIX in that respect:

http://msdn2.microsoft.com/en-us/library/x99tb11d(VS.80).aspx

Try something like

setlocale(LC_MESSAGES, "Spanish");

or, if your language environment is Spanish, simply

setlocale(LC_MESSAGES, "");

Yours,
Laurenz Albe

Re: libpq messages language

From
Efraín López
Date:
Thank you for your reply

but I got the error 'LC_MESSAGES' : undeclared identifier

locale.h only defines LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME

I tried to set a system variable LC_MESSAGES, but didn't work

Then, I tried to find more information


In libpq, when ENABLE_NLS is not defined,
#define libpq_gettext(x) (x)

If I set ENABLE_NLS to 1, then I think I need the gettext library, because
it needs <libintl.h>

so, there is no simple way in windows to get messages in spanish within
libpq before connecting to server, is correct?

thanks


----- Original Message -----
From: "Albe Laurenz" <laurenz.albe@wien.gv.at>
To: "Efraín López *EXTERN*" <tecnomaya@cabsagt.com>;
<pgsql-general@postgresql.org>
Sent: Tuesday, December 04, 2007 5:33 AM
Subject: RE: [GENERAL] libpq messages language


Efraín López wrote:
> I am using Windows, and pg 8.2.5
>
> When making a connection with libpq, if it fails I would like
> to get the errors messages in spanish (PQerrorMessage  )
>
> Is this possible? How can this be done?

Set the program's locale prior to calling libpq functions.

I did not try it on Windows, but Microsoft seems to work like
UNIX in that respect:

http://msdn2.microsoft.com/en-us/library/x99tb11d(VS.80).aspx

Try something like

setlocale(LC_MESSAGES, "Spanish");

or, if your language environment is Spanish, simply

setlocale(LC_MESSAGES, "");

Yours,
Laurenz Albe



Re: libpq messages language

From
"Usama Dar"
Date:


On Dec 6, 2007 8:03 AM, Efraín López <tecnomaya@cabsagt.com> wrote:
Thank you for your reply

but I got the error 'LC_MESSAGES' : undeclared identifier

locale.h only defines LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERIC, LC_TIME

I tried to set a system variable LC_MESSAGES, but didn't work

Then, I tried to find more information


In libpq, when ENABLE_NLS is not defined,
#define libpq_gettext(x) (x)

If I set ENABLE_NLS to 1, then I think I need the gettext library, because
it needs < libintl.h>

so, there is no simple way in windows to get messages in spanish within
libpq before connecting to server, is correct?

Well libpq like rest of postgres uses gettext for i18N , so i think you need to have your windows locale set to spanish, have the gettext library installed and spanish message catalogs available on your system, which will be if you compiled the source with --enable-nls configure option then it doesn't matter if the connection was made to the server or not, since libpq has its own translated messages catalog.




--
Usama Munir Dar http://linkedin.com/in/usamadar
Consultant Architect
Cell:+92 321 5020666
Skype: usamadar

Re: libpq messages language

From
"Albe Laurenz"
Date:
Efraín López wrote:
>>> I am using Windows, and pg 8.2.5
>>>
>>> When making a connection with libpq, if it fails I would like
>>> to get the errors messages in spanish (PQerrorMessage  )
>>>
>>> Is this possible? How can this be done?

I got it to work with this program:

#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <libpq-fe.h>

int main(int argc, char **argv) {
        PGconn *conn;

        setlocale(LC_ALL, "");
        putenv("PGLOCALEDIR=C:\\Programme\\postgres\\share\\locale");

        conn = PQconnectdb("port=4711");
        if (CONNECTION_OK != PQstatus(conn)) {
                fprintf(stderr, "%s\n", PQerrorMessage(conn));
                PQfinish(conn);
                return 1;
        }

        PQfinish(conn);
        return 0;
}

Instead of setting PGLOCALEDIR in the code, you can also define
it as environment variable on your system, that is maybe better.

It must point to the directory where your message files are installed
(you have spanish message files installed, haven't you?).

The above program assumes that there is no database running
on port 4711, so you get an error message from libpq.

Yours,
Laurenz Albe

Re: libpq messages language

From
Efraín López
Date:
Thank you very much for your help.  It worked for me.

I am using Visual C++ 2005 express
I downloaded gettext-runtime-0.13.1.bin.woe32.zip and
libiconv-1.9.1.bin.woe32.zip from
http://sourceforge.net/project/showfiles.php?group_id=25167

Then I compiled libpq with ENABLE_NLS, gettext and libiconv libs

They, I just got carefull with PGLOCALEDIR,

again, thank you!

----- Original Message -----
From: "Albe Laurenz" <laurenz.albe@wien.gv.at>
To: "Efraín López *EXTERN*" <tecnomaya@cabsagt.com>;
<pgsql-general@postgresql.org>
Sent: Friday, December 07, 2007 2:52 AM
Subject: RE: [GENERAL] libpq messages language


Efraín López wrote:
>>> I am using Windows, and pg 8.2.5
>>>
>>> When making a connection with libpq, if it fails I would like
>>> to get the errors messages in spanish (PQerrorMessage  )
>>>
>>> Is this possible? How can this be done?

I got it to work with this program:

#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
#include <libpq-fe.h>

int main(int argc, char **argv) {
        PGconn *conn;

        setlocale(LC_ALL, "");
        putenv("PGLOCALEDIR=C:\\Programme\\postgres\\share\\locale");

        conn = PQconnectdb("port=4711");
        if (CONNECTION_OK != PQstatus(conn)) {
                fprintf(stderr, "%s\n", PQerrorMessage(conn));
                PQfinish(conn);
                return 1;
        }

        PQfinish(conn);
        return 0;
}

Instead of setting PGLOCALEDIR in the code, you can also define
it as environment variable on your system, that is maybe better.

It must point to the directory where your message files are installed
(you have spanish message files installed, haven't you?).

The above program assumes that there is no database running
on port 4711, so you get an error message from libpq.

Yours,
Laurenz Albe