TEXTDOMAIN(3)
π TEXTDOMAIN π
okay bestie so this is textdomain, a lil function from the Library Functions Manual and it's literally the thing that tells your program which translation files to go look in. so unserious of it to be this important tbh π«Ά
β¨ NAME β¨
textdomain β sets the domain for all your future gettext() calls π
πΈ SYNOPSIS πΈ
#include <libintl.h>
char * textdomain (const char * domainname);
like that's it. one include, one function, one little char * and you're in your i18n era β¨
π DESCRIPTION π
okay so textdomain either sets or gets the current message domain. it's giving switch-hitter, honestly. π
and what even is a message domain?? so glad you asked. a message domain is a set of translatable msgid messages. usually every software package has its own message domain β your app gets one, my app gets one, everyone's got their own little folder of translations. no sharing, no drama. the domain name is what gets used to figure out which message catalog a translation is looked up in, and heads up bestie: it must be a non-empty string. empty string? not the vibe. π
now here's where it gets cute. the current message domain is the one that gets used by:
- the
gettextandngettextfunctions - the
dgettext,dcgettext,dngettextanddcngettextfunctions β but only when they're called with aNULLdomainnameargument π«Ά
so like, if you pass NULL, they're like "okay cool I'll just use whatever the current domain is." teamwork. iconic.
if domainname is not NULL: the current message domain gets set to domainname. and the way the function stores it internally? it keeps a copy of the domainname argument. so you can free your own string, she's got her own. self-sufficient queen π
if domainname is NULL: the function just returns the current message domain. no setting, just vibes and information. π
π RETURN VALUE π
if it works, textdomain returns the current message domain β after possibly having changed it. so you get the fresh new one, slay. π
okay but listen: the resulting string is valid until the next textdomain call and it must not be modified or freed. do NOT touch it. do NOT free it. it is not yours. it is hers. hands off bestie π
and if a memory allocation failure happens? she sets errno to ENOMEM and returns NULL. tragic. anyway. π
π¦ ERRORS π¦
here's the error that can happen (among others, so like, stay alert):
ENOMEMβ not enough memory available. the computer is broke, the memory is gone, it's over. π
π BUGS π
okay so this one's a lil legacy situation. the return type ought to be const char *... but it's char *. why? to avoid warnings in C code predating ANSI C. so basically it's a historical artifact holding the whole thing hostage. we love a vintage design decision that we simply cannot change now. π
π SEE ALSO π
and that's the whole page, bestie!! this one's from GNU gettext 1.0, dated May 2001 β so like, older than most of us, but still out here doing her lil domain-setting job. periodt. πβ¨π¦
π¦ where this page comes from
- alpine 3.24: gettext-doc 1.0-r0 Β· GPL-3.0-or-later AND LGPL-2.1-or-later AND MIT
- arch rolling: gettext 1.0-2 Β· GFDL-1.2-only AND GPL-2.0-only AND GPL-2.0-or-later AND LGPL-2.0-only
- nixos 26.05: gettext 1.0
- nixpkgs unstable: gettext 1.0
- ubuntu stonking: gettext-base 1.0-3 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms