Next: , Previous: , Up: About gettext   [Contents][Index]


11.2.2 Solving Ambiguities

While this single name domain works well for most applications there might be the need to get translations from more than one domain. Of course one could switch between different domains with calls to textdomain, but this is really not convenient nor is it fast. A possible situation could be one case subject to discussion during this writing: all error messages of functions in the set of common used functions should go into a separate domain error. By this mean we would only need to translate them once. Another case are messages from a library, as these have to be independent of the current domain set by the application.

For this reasons there are two more functions to retrieve strings:

char *dgettext (const char *domain_name, const char *msgid);
char *dcgettext (const char *domain_name, const char *msgid,
                 int category);

Both take an additional argument at the first place, which corresponds to the argument of textdomain. The third argument of dcgettext allows to use another locale category but LC_MESSAGES. But I really don’t know where this can be useful. If the domain_name is NULL or category has an value beside the known ones, the result is undefined. It should also be noted that this function is not part of the second known implementation of this function family, the one found in Solaris.

A second ambiguity can arise by the fact, that perhaps more than one domain has the same name. This can be solved by specifying where the needed message catalog files can be found.

char *bindtextdomain (const char *domain_name,
                      const char *dir_name);

Calling this function binds the given domain to a file in the specified directory (how this file is determined follows below). Especially a file in the systems default place is not favored against the specified file anymore (as it would be by solely using textdomain). A NULL pointer for the dir_name parameter returns the binding associated with domain_name. If domain_name itself is NULL nothing happens and a NULL pointer is returned. Here again as for all the other functions is true that none of the return value must be changed!

It is important to remember that relative path names for the dir_name parameter can be trouble. Since the path is always computed relative to the current directory different results will be achieved when the program executes a chdir command. Relative paths should always be avoided to avoid dependencies and unreliabilities.

wchar_t *wbindtextdomain (const char *domain_name,
                          const wchar_t *dir_name);

This function is provided only on native Windows platforms. It is like bindtextdomain, except that the dir_name parameter is a wide string (in UTF-16 encoding, as usual on Windows).


Next: Locating Message Catalog Files, Previous: The Interface, Up: About gettext   [Contents][Index]