Problems with internationalization

W

WujcioL

//this is the code
#include <stdio.h>
#include <locale.h>
#include <libintl.h>

#define _(String) gettext(String)

int main()
{
setlocale(LC_ALL,"");
bindtextdomain("test","lang");
textdomain("test");
printf(_("abcd"));
return 0;

}

// $ gcc test.c -o test
// xgettext test.c -k_ -o test.po
// msgfmt test.po -o test.mo
// cp test.mo lang/pl/LC_MESSAGES/test.mo
// But it don't work. Can you tell me why?
 
K

Kenny McCormack

pete said:
I don't know what <libintl.h> is.
I don't know what gettext is.
I don't know what bindtextdomain is.
I don't know what textdomain is.

You're not very well informed, are you?

Hint: Most people try to be a little discrete about the gaps in their
knowledge.
 
I

Ian Collins

WujcioL said:
//this is the code
#include <stdio.h>
#include <locale.h>
#include <libintl.h>
The other ill informed responder should have simply said try
comp.unix.programmer.
#define _(String) gettext(String)
Why do something this gross?
 
N

Nick Keighley

You're not very well informed, are you?

Hint: Most people try to be a little discrete about the gaps in their
knowledge.

only marketing and sales people
 
K

Keith Thompson

Ian Collins said:
The other ill informed responder should have simply said try
comp.unix.programmer.

Why do something this gross?

I believe it's common practice in code that uses <libintl.h>.

It actually doesn't bother me. Using "_" it as a macro name allows
internationalized messages to be marked clearly but unobtrusively.
You can replace something like this:

fprintf(stderr, "Warning: Something bad just happened\n");

with:

fprintf(stderr, _("Warning: Something bad just happened\n"));

and, assuming the translation tables and so forth have been set up
properly, the message will appear in the correct language. It seems
to me that having to write:

fprintf(stderr, gettext("Warning: Something bad just happened\n"));

would clutter the code.

Note that if the point were to save typing, I'd dislike it. But if
calls to gettext() are pervasive, using a short and distinctive
abbreviation can actually make the code more readable. It's almost
like an operator rather than just another function call.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top