Node:Locating gettext catalog, Next:Advanced gettext functions, Previous:Translation with gettext, Up:Message catalogs with gettext
The functions to retrieve the translations for a given message have a remarkable simple interface. But to provide the user of the program still the opportunity to select exactly the translation s/he wants and also to provide the programmer the possibility to influence the way to locate the search for catalogs files there is a quite complicated underlying mechanism which controls all this. The code is complicated the use is easy.
Basically we have two different tasks to perform which can also be
performed by the catgets
functions:
There can be arbitrary many packages installed and they can follow different guidelines for the placement of their files.
This is the functionality required by the specifications for
gettext
and this is also what the catgets
functions are
able to do. But there are some problems unresolved:
de
, german
, or
deutsch
and the program should always react the same.
de_DE.ISO-8859-1
which means German, spoken in Germany,
coded using the ISO 8859-1 character set there is the possibility
that a message catalog matching this exactly is not available. But
there could be a catalog matching de
and if the character set
used on the machine is always ISO 8859-1 there is no reason why this
later message catalog should not be used. (We call this message
inheritance.)
We can divide the configuration actions in two parts: the one is performed by the programmer, the other by the user. We will start with the functions the programmer can use since the user configuration will be based on this.
As the functions described in the last sections already mention separate
sets of messages can be selected by a domain name. This is a
simple string which should be unique for each program part with uses a
separate domain. It is possible to use in one program arbitrary many
domains at the same time. E.g., the GNU C Library itself uses a domain
named libc
while the program using the C Library could use a
domain named foo
. The important point is that at any time
exactly one domain is active. This is controlled with the following
function.
char * textdomain (const char *domainname) | Function |
The textdomain function sets the default domain, which is used in
all future gettext calls, to domainname. Please note that
dgettext and dcgettext calls are not influenced if the
domainname parameter of these functions is not the null pointer.
Before the first call to The function returns the value which is from now on taken as the default
domain. If the system went out of memory the returned value is
If the domainname parameter is the null pointer no new default domain is set. Instead the currently selected default domain is returned. If the domainname parameter is the empty string the default domain
is reset to its initial value, the domain with the name |
char * bindtextdomain (const char *domainname, const char *dirname) | Function |
The bindtextdomain function can be used to specify the directory
which contains the message catalogs for domain domainname for the
different languages. To be correct, this is the directory where the
hierarchy of directories is expected. Details are explained below.
For the programmer it is important to note that the translations which
come with the program have be placed in a directory hierarchy starting
at, say, The If the program which wish to use If the dirname parameter is the null pointer The |