gettext
grok
To fully exploit the functionality of the GNU gettext
library it
is surely helpful to read the source code. But for those who don't want
to spend that much time in reading the (sometimes complicated) code here
is a list comments:
gettext
function. The method which is presented here only works correctly
with the GNU implementation of the gettext
functions. It is not
possible with underlying catgets
functions or gettext
functions from the systems C library. The exception is of course the
GNU C Library which uses the GNU gettext Library for message handling.
In the function dcgettext
at every call the current setting of
the highest priority environment variable is determined and used.
Highest priority means here the following list with decreasing
priority:
LANGUAGE
LC_ALL
LC_xxx
, according to selected locale
LANG
LANGUAGE
changes. According
to the process explained above the new value of this variable is found
as soon as the dcgettext
function is called. But this also means
the (perhaps) different message catalog file is loaded. In other
words: the used language is changed.
But there is one little hook. The code for gcc-2.7.0 and up provides
some optimization. This optimization normally prevents the calling of
the dcgettext
function as long as now new catalog is loaded. But
if dcgettext
is not called we program also cannot find the
LANGUAGE
variable be changed (see section Optimization of the *gettext functions). But the
solution is very easy. Include the following code in the language
switching function.
/* Change language. */ setenv ("LANGUAGE", "fr", 1); /* Make change known. */ { extern int _nl_msg_cat_cntr; ++_nl_msg_cat_cntr; }The variable
_nl_msg_cat_cntr
is defined in `loadmsgcat.c'.
Go to the first, previous, next, last section, table of contents.