BINDTEXTDOMAIN(3)
π BINDTEXTDOMAIN(3) π
okay bestie, sit down, we're learning bindtextdomain from the Library Functions Manual and honestly? it's giving "quietly running the entire translation industry." β¨
πΈ NAME πΈ
bindtextdomain β set the directory that's holding all your message catalogs, no cap π
π SYNOPSIS π
#include <libintl.h>
char * bindtextdomain (const char * domainname, const char * dirname);
like. that's it. that's the whole vibe. π¦
β¨ DESCRIPTION β¨
So the bindtextdomain function sets the base directory of the whole hierarchy that contains message catalogs for a given message domain. Lowkey it's the function that tells your program "hey girl, the translations live over here." π
A message domain is just a set of translatable msgid messages. Usually every software package has its own message domain, because we're all unique and special like that. π The reason you even need to call bindtextdomain is that packages are not always installed with the same prefix as the <libintl.h> header and the libc/libintl libraries. So like, sometimes things are just... living in different houses. π π
Your message catalogs are gonna be expected at these pathnames:
dirname/locale/category/domainname.mo
where locale is a locale name and category is a locale facet such as LC_MESSAGES. Slay. π―
important!! domainname must be a non-empty string. Don't be out here passing empty strings, bestie. π
If dirname is not NULL, the base directory for message catalogs belonging to domain domainname is set to dirname. The function makes copies of the argument strings as needed, so you don't have to keep them alive yourself. π«Ά
And listen β if the program wishes to call the chdir function, it is important that dirname be an absolute pathname; otherwise it cannot be guaranteed that the message catalogs will be found. Like, fr fr, absolute path or you're gambling. π°π
If dirname is NULL, the function returns the previously set base directory for domain domainname. Cute little getter behaviour. π
π RETURN VALUE π
If successful, the bindtextdomain function returns the current base directory for domain domainname, after possibly changing it. Main character energy. β¨
The resulting string is valid until the nextbindtextdomaincall for the samedomainnameand must not be modified or freed. Do not touch. Do not free. Just look at it and say thank you. π
If a memory allocation failure occurs, it sets errno to ENOMEM and returns NULL. π
π ERRORS π
The following error can occur, among others:
ENOMEMβ Not enough memory available. bestie ran out of RAM. it happens to the best of us. π
π BUGS π
The return type ought to be const char *, but is char * to avoid warnings in C code predating ANSI C. So it's technically wrong but we keep it for the ancient ones. respect your elders. π§
π₯ SEE ALSO π₯
gettext(3)dgettext(3)dcgettext(3)ngettext(3)dngettext(3)dcngettext(3)textdomain(3)realpath(3)
the whole friend group. go read them. iykyk. π
and that's the whole page, gorgeous. this one's from GNU gettext 1.0, dated May 2001 β like, the original Y2K baddie π β so go forth, set your domain directories, and stay absolute-path-pilled. mwah πβ¨
π¦ 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