{
    "mode": "man",
    "parameter": "GETTEXT",
    "section": "3",
    "url": "https://www.chedong.com/phpMan.php/man/GETTEXT/3/json",
    "generated": "2026-05-30T07:10:19Z",
    "synopsis": "",
    "sections": {
        "NAME": {
            "content": "gettext, dgettext, dcgettext - translate message\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "",
            "subsections": [
                {
                    "name": "#include <libintl.h>",
                    "content": "char * gettext (const char * msgid);\nchar * dgettext (const char * domainname, const char * msgid);\nchar * dcgettext (const char * domainname, const char * msgid,\nint category);\n"
                }
            ]
        },
        "DESCRIPTION": {
            "content": "The  gettext,  dgettext  and  dcgettext functions attempt to translate a text string into the\nuser's native language, by looking up the translation in a message catalog.\n\nThe msgid argument identifies the message to be translated. By convention, it is the  English\nversion  of  the  message,  with  non-ASCII characters replaced by ASCII approximations. This\nchoice allows the translators to work with message catalogs, called PO  files,  that  contain\nboth  the English and the translated versions of each message, and can be installed using the\nmsgfmt utility.\n\nA message domain is a set of translatable msgid messages. Usually, every software package has\nits  own  message  domain. The domain name is used to determine the message catalog where the\ntranslation is looked up; it must be a non-empty string. For  the  gettext  function,  it  is\nspecified  through  a preceding textdomain call. For the dgettext and dcgettext functions, it\nis passed as the domainname argument; if this argument is NULL,  the  domain  name  specified\nthrough a preceding textdomain call is used instead.\n\nTranslation  lookup  operates in the context of the current locale. For the gettext and dget‐‐\ntext functions, the LCMESSAGES locale facet is used. It is determined by a preceding call to\nthe  setlocale function. setlocale(LCALL,\"\") initializes the LCMESSAGES locale based on the\nfirst nonempty value of the three environment variables LCALL, LCMESSAGES, LANG; see setlo‐‐\ncale(3). For the dcgettext function, the locale facet is determined by the category argument,\nwhich should be one of the LCxxx constants  defined  in  the  <locale.h>  header,  excluding\nLCALL.  In  both cases, the functions also use the LCCTYPE locale facet in order to convert\nthe translated message from the translator's codeset to the current locale's codeset,  unless\noverridden by a prior call to the bindtextdomaincodeset function.\n\nThe  message catalog used by the functions is at the pathname dirname/locale/category/domain‐\nname.mo. Here dirname is the directory specified through bindtextdomain. Its default is  sys‐\ntem and configuration dependent; typically it is prefix/share/locale, where prefix is the in‐\nstallation prefix of the package. locale is the name of the current locale facet; the GNU im‐\nplementation  also  tries  generalizations,  such  as the language name without the territory\nname. category is LCMESSAGES for the gettext and dgettext functions, or the argument  passed\nto the dcgettext function.\n\nIf  the  LANGUAGE  environment variable is set to a nonempty value, and the locale is not the\n\"C\" locale, the value of LANGUAGE is assumed to contain a  colon  separated  list  of  locale\nnames. The functions will attempt to look up a translation of msgid in each of the locales in\nturn. This is a GNU extension.\n\nIn the \"C\" locale, or if none of the used catalogs contain a translation for msgid, the  get‐‐\ntext, dgettext and dcgettext functions return msgid.\n",
            "subsections": []
        },
        "RETURN VALUE": {
            "content": "If  a translation was found in one of the specified catalogs, it is converted to the locale's\ncodeset and returned. The resulting string is statically allocated and must not  be  modified\nor freed. Otherwise msgid is returned.\n",
            "subsections": []
        },
        "ERRORS": {
            "content": "errno is not modified.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The return type ought to be const char *, but is char * to avoid warnings in C code predating\nANSI C.\n\nWhen an empty string is used for msgid, the functions may return a nonempty string.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "ngettext(3), dngettext(3),  dcngettext(3),  setlocale(3),  textdomain(3),  bindtextdomain(3),\nbindtextdomaincodeset(3), msgfmt(1)\n\n\n\nGNU gettext 0.20.1.124-32cf                   May 2001                                    GETTEXT(3)",
            "subsections": []
        }
    },
    "summary": "gettext, dgettext, dcgettext - translate message",
    "flags": [],
    "examples": [],
    "see_also": [
        {
            "name": "ngettext",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/ngettext/3/json"
        },
        {
            "name": "dngettext",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/dngettext/3/json"
        },
        {
            "name": "dcngettext",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/dcngettext/3/json"
        },
        {
            "name": "setlocale",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/setlocale/3/json"
        },
        {
            "name": "textdomain",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/textdomain/3/json"
        },
        {
            "name": "bindtextdomain",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/bindtextdomain/3/json"
        },
        {
            "name": "bindtextdomaincodeset",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/bindtextdomaincodeset/3/json"
        },
        {
            "name": "msgfmt",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/msgfmt/1/json"
        }
    ]
}