gettext -- perform lookup in message catalog for the current LC_MESSAGES locale


#include <libintl.h>

extern char *gettext(const char *msgid);


gettext attempts to retrieve a target string based on the specified key from msgid within the context of a specific domain and the current locale.

The LANGUAGE environment variable is examined first to determine the message catalogs to be used. LANGUAGE is a list of locale names separated by ":" character. If LANGUAGE is defined, each locale name is tried in the specified order and if a message catalog containing the requested message is found, the message is returned. If LANGUAGE is defined but failed to locate a message catalog, the msgid string is returned. If LANGUAGE is not defined, the LC_ALL, LC_xxx, and LANG environment variables are examined to locate the message catalog, following the convention used by the setlocale function.

The pathname used to locate the message catalog is dirname/locale/category/, where dirname is the directory specified by the bindtextdomain function, locale is a locale name determined by the definition of environment variables, and category is LC_MESSAGES.

If the LC_MESSAGES locale category of the current locale is the standard C locale or the standard POSIX locale, gettext returns msgid without looking in any message catalog.



A NULL-terminated string to be matched in the catalogue with respect to a specific domain and the current locale.

Return Value

If the function query above succeeds with msgid, then a translated NULL-terminated string is returned. If the search fails, then the original msgid is returned. The length of the string returned is undetermined until the function is called.


gettext does not modify the global variable errno.

See Also

gettext, dgettext, ngettext, dngettext, dcgettext, dcngettext, textdomain, bindtextdomain, bind_textdomain_codeset