1gettext(3) User Contributed Perl Documentation gettext(3)
2
3
4
6 Locale::gettext - message handling functions
7
9 use Locale::gettext;
10 use POSIX; # Needed for setlocale()
11
12 setlocale(LC_MESSAGES, "");
13
14 # OO interface
15 my $d = Locale::gettext->domain("my_program");
16
17 print $d->get("Welcome to my program"), "\n";
18 # (printed in the local language)
19
20 # Direct access to C functions
21 textdomain("my_program");
22
23 print gettext("Welcome to my program"), "\n";
24 # (printed in the local language)
25
27 The gettext module permits access from perl to the gettext() family of
28 functions for retrieving message strings from databases constructed to
29 internationalize software.
30
31 $d = Locale::gettext->domain(DOMAIN)
32 $d = Locale::gettext->domain_raw(DOMAIN)
33 Creates a new object for retrieving strings in the domain DOMAIN and
34 returns it. "domain" requests that strings be returned as Perl
35 strings (possibly with wide characters) if possible while
36 "domain_raw" requests that octet strings directly from functions like
37 dgettext().
38
39 $d->get(MSGID)
40 Calls dgettext() to return the translated string for the given MSGID.
41
42 $d->cget(MSGID, CATEGORY)
43 Calls dcgettext() to return the translated string for the given MSGID
44 in the given CATEGORY.
45
46 $d->nget(MSGID, MSGID_PLURAL, N)
47 Calls dngettext() to return the translated string for the given MSGID
48 or MSGID_PLURAL depending on N.
49
50 $d->ncget(MSGID, MSGID_PLURAL, N, CATEGORY)
51 Calls dngettext() to return the translated string for the given MSGID
52 or MSGID_PLURAL depending on N in the given CATEGORY.
53
54 $d->dir([NEWDIR])
55 If NEWDIR is given, calls "bindtextdomain" to set the name of the
56 directory where messages for the domain represented by $d are found.
57 Returns the (possibly changed) current directory name.
58
59 $d->codeset([NEWCODE])
60 For instances created with "Locale::gettext->domain_raw", manuiplates
61 the character set of the returned strings. If NEWCODE is given,
62 calls "bind_textdomain_codeset" to set the character encoding in
63 which messages for the domain represented by $d are returned. Returns
64 the (possibly changed) current encoding name.
65
66 gettext(), dgettext(), and dcgettext() attempt to retrieve a string
67 matching their "msgid" parameter within the context of the current
68 locale. dcgettext() takes the message's category and the text domain as
69 parameters while dgettext() defaults to the LC_MESSAGES category and
70 gettext() defaults to LC_MESSAGES and uses the current text domain. If
71 the string is not found in the database, then "msgid" is returned.
72
73 ngettext(), dngettext(), and dcngettext() function similarily but
74 implement differentiation of messages between singular and plural. See
75 the documentation for the corresponding C functions for details.
76
77 textdomain() sets the current text domain and returns the previously
78 active domain.
79
80 bindtextdomain(domain, dirname) instructs the retrieval functions to
81 look for the databases belonging to domain "domain" in the directory
82 "dirname"
83
84 bind_textdomain_codeset(domain, codeset) instructs the retrieval
85 functions to translate the returned messages to the character encoding
86 given by codeset if the encoding of the message catalog is known.
87
89 Not all platforms provide all of the functions. Functions that are not
90 available in the underlying C library will not be available in Perl
91 either.
92
93 Perl programs should use the object interface. In addition to being
94 able to return native Perl wide character strings,
95 "bind_textdomain_codeset" will be emulated if the C library does not
96 provide it.
97
99 1.07.
100
102 gettext(3i), gettext(1), msgfmt(1)
103
105 Kim Vandry <vandry@TZoNE.ORG>
106
107
108
109perl v5.38.0 2023-07-21 gettext(3)