Re: gettext documentation not accurate for Debian?
Martin Schulze <joey@finlandia.infodrom.north.de> writes:
> Avery Pennarun wrote:
> > > b) "remove these definitions" will end up in the following errors:
> > >
> > > this.o: In function `main':
> > > this.o(.text+0x28): undefined reference to `_'
> > >
> > > Instead you have to turn these definitions into the following in
> > > order to get your program compiled.
> > >
> > > #define _(String) (String)
> > > #define N_(String) (String)
> >
> > Hmm, my understanding was that _(String) was just another way to say
> > gettext(String). So, you can #define this:
> >
> > #define _(String) gettext(String)
>
> Indeed. I quoted the wrong line. I added your line to my program
> and it worked.
>
> > And you should be okay. Now, I've never actually used gettext, so I don't
> > know if this macro used to be defined, but now isn't in libc6.
> >
> > In any case, libintl.h certainly doesn't seem to have the _() define
> > nowadays. I don't know what N_() does, but perhaps something else in
> > libintl.h will look right.
>
> _(string) will be added to the pot file, N_(string) won't be added.
Nope. Both _() and N_() marked strings are added to the pot file. If
you don't want it to be added, don't mark the string. The usual usage is
#define _(s) gettext(s)
#define N_(s) (s)
This is useful to mark static strings, since you can't initialize a
static string with a function call return.
char *string_table[] ={ N_("Hi"), N_("Howdy"), N_("Do") };
int main()
{
for (i = 0; i < sizeof string_table/sizeofstring_table[0];++i)
puts(gettext(string_table[i]));
}
- Hari
--
Raja R Harinath ------------------------------ harinath@cs.umn.edu
"When all else fails, read the instructions." -- Cahn's Axiom
"Our policy is, when in doubt, do the right thing." -- Roy L Ash
Reply to: