gettext(3)
π NAME π
Okay bestie, this is gettext(3) β the Locale::gettext page from the User Contributed Perl Documentation β and the whole vibe is: Locale::gettext - message handling functions. Periodt. π
β¨ SYNOPSIS β¨
Here's the little starter pack, fr fr:
use Locale::gettext;
use POSIX; # Needed for setlocale()
setlocale(LC_MESSAGES, "");
# OO interface
my $d = Locale::gettext->domain("my_program");
print $d->get("Welcome to my program"), "\n";
# (printed in the local language)
# Direct access to C functions
textdomain("my_program");
print gettext("Welcome to my program"), "\n";
# (printed in the local language)
πΈ DESCRIPTION πΈ
So basically, the gettext module lets Perl access the gettext() family of functions for retrieving message strings from databases constructed to internationalize software. It's giving global main character energy, honestly. πβ¨
Here's the function lineup, no details skipped:
$d = Locale::gettext->domain(DOMAIN)and$d = Locale::gettext->domain_raw(DOMAIN)β Creates a new object for retrieving strings in the domainDOMAINand returns it.domainrequests that strings be returned as Perl strings (possibly with wide characters) if possible, whiledomain_rawrequests octet strings directly from functions likedgettext().$d->get(MSGID)β Callsdgettext()to return the translated string for the givenMSGID.$d->cget(MSGID, CATEGORY)β Callsdcgettext()to return the translated string for the givenMSGIDin the givenCATEGORY.$d->nget(MSGID, MSGID_PLURAL, N)β Callsdngettext()to return the translated string for the givenMSGIDorMSGID_PLURALdepending onN.$d->ncget(MSGID, MSGID_PLURAL, N, CATEGORY)β Callsdngettext()to return the translated string for the givenMSGIDorMSGID_PLURALdepending onNin the givenCATEGORY.$d->dir([NEWDIR])β IfNEWDIRis given, callsbindtextdomainto set the name of the directory where messages for the domain represented by$dare found. Returns the (possibly changed) current directory name.$d->codeset([NEWCODE])β For instances created withLocale::gettext->domain_raw, manuiplates the character set of the returned strings. IfNEWCODEis given, callsbind_textdomain_codesetto set the character encoding in which messages for the domain represented by$dare returned. Returns the (possibly changed) current encoding name.
gettext(), dgettext(), and dcgettext() attempt to retrieve a string matching their msgid parameter within the context of the current locale. dcgettext() takes the message's category and the text domain as parameters while dgettext() defaults to the LC_MESSAGES category and gettext() defaults to LC_MESSAGES and uses the current text domain. If the string is not found in the database, then msgid is returned. That part is lowkey important, okay? π
ngettext(), dngettext(), and dcngettext() function similarily but implement differentiation of messages between singular and plural. See the documentation for the corresponding C functions for details.
textdomain() sets the current text domain and returns the previously active domain.
bindtextdomain(domain, dirname) instructs the retrieval functions to look for the databases belonging to domain domain in the directory dirname
bind_textdomain_codeset(domain, codeset) instructs the retrieval functions to translate the returned messages to the character encoding given by codeset if the encoding of the message catalog is known.
π¦ NOTES π¦
Not all platforms provide all of the functions. Functions that are not available in the underlying C library will not be available in Perl either. So likeβ¦ vibe check your platform first, bestie. π
Perl programs should use the object interface. In addition to being able to return native Perl wide character strings, bind_textdomain_codeset will be emulated if the C library does not provide it. Slay. π«Ά
π VERSION π
1.07. That's the version. Iconic, concise, done. β¨
π SEE ALSO π
Go give these their moment too: gettext(3i), gettext(1), msgfmt(1). iykyk π
π AUTHOR π
Shoutout to Kim Vandry <vandry@TZoNE.ORG> for this one. π
Cute little footer sign-off, because we don't copy-paste headers and footers around here: this page is gettext(3), running with perl v5.42.2, dated 2025-06-30. Byeee π
β¨
π¦ where this page comes from
- alpine 3.24: perl-locale-gettext-doc 1.07-r2 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms