NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |BUGS |SEE ALSO |COLOPHON | |
GETTEXT(3) Library Functions ManualGETTEXT(3)gettext, dgettext, dcgettext - translate message
#include <libintl.h>char * gettext (const char *msgid);char * dgettext (const char *domainname, const char *msgid);char * dcgettext (const char *domainname, const char *msgid,intcategory);
Thegettext,dgettextanddcgettextfunctions attempt to translate a text string into the user's native language, by looking up the translation in a message catalog. Themsgid argument identifies the message to be translated. By convention, it is the English version of the message, with non- ASCII characters replaced by ASCII approximations. This choice allows the translators to work with message catalogs, called PO files, that contain both the English and the translated versions of each message, and can be installed using themsgfmtutility. A message domain is a set of translatablemsgid messages. Usually, every software package has its own message domain. The domain name is used to determine the message catalog where the translation is looked up; it must be a non-empty string. For thegettext function, it is specified through a precedingtextdomaincall. For thedgettextanddcgettextfunctions, it is passed as thedomainname argument; if this argument is NULL, the domain name specified through a precedingtextdomaincall is used instead. Translation lookup operates in the context of the current locale. For thegettextanddgettextfunctions, theLC_MESSAGESlocale facet is used. It is determined by a preceding call to thesetlocalefunction.setlocale (LC_ALL, "")initializes theLC_MESSAGESlocale based on the first nonempty value of the three environment variablesLC_ALL,LC_MESSAGES,LANG; seesetlocale(3). For thedcgettextfunction, the locale facet is determined by thecategory argument, which should be one of theLC_xxxconstants defined in the <locale.h> header, excludingLC_ALL. In both cases, the functions also use theLC_CTYPElocale facet in order to convert the translated message from the translator's codeset to the current locale's codeset, unless overridden by a prior call to thebind_textdomain_codesetfunction. The message catalog used by the functions is at the pathnamedirname/locale/category/domainname.mo. Heredirname is the directory specified throughbindtextdomain. Its default is system and configuration dependent; typically it isprefix/share/locale, whereprefix is the installation prefix of the package.locale is the name of the current locale facet; the GNU implementation also tries generalizations, such as the language name without the territory name.category isLC_MESSAGESfor thegettextanddgettextfunctions, or the argument passed to thedcgettext function. If theLANGUAGEenvironment variable is set to a nonempty value, and the locale is not the "C" locale, the value ofLANGUAGEis assumed to contain a colon separated list of locale names. The functions will attempt to look up a translation ofmsgid in each of the locales in turn. This is a GNU extension. In the "C" locale, or if none of the used catalogs contain a translation formsgid, thegettext,dgettextanddcgettext functions returnmsgid.
If a translation was found in one of the specified catalogs, it is converted to the locale's codeset and returned. The resulting string is statically allocated and must not be modified or freed. Otherwisemsgid is returned.
errnois not modified.
The return type ought to beconst char *, but ischar *to avoid warnings in C code predating ANSI C. When an empty string is used formsgid, the functions may return a nonempty string.
ngettext(3),dngettext(3),dcngettext(3),setlocale(3),textdomain(3),bindtextdomain(3),bind_textdomain_codeset(3),msgfmt(1)
This page is part of thegettext (message translation) project. Information about the project can be found at ⟨http://www.gnu.org/software/gettext/⟩. If you have a bug report for this manual page, see ⟨http://savannah.gnu.org/projects/gettext/⟩. This page was obtained from the tarball gettext-0.26.tar.gz fetched from ⟨https://ftp.gnu.org/gnu/gettext/⟩ on 2025-08-11. If you discover any rendering problems in this HTML version of the page, or you believe there is a better or more up-to-date source for the page, or you have corrections or improvements to the information in this COLOPHON (which isnot part of the original manual page), send a mail to man-pages@man7.orgGNU gettext 0.26 November 2024GETTEXT(3)Pages that refer to this page:bindtextdomain(3), bind_textdomain_codeset(3), ngettext(3), textdomain(3), wprintf(3), environ(7), locale(7)
HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface. For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere. Hosting byjambit GmbH. | ![]() |