summaryrefslogtreecommitdiff
path: root/usr/src/man/man3c/gettext.3c
blob: cade03245ac6f50587116917f9fe259c32335f87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
'\" te
.\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH GETTEXT 3C "April 9, 2016"
.SH NAME
gettext, dgettext, dcgettext, ngettext, dngettext, dcngettext, textdomain,
bindtextdomain, bind_textdomain_codeset \- message handling functions
.SH SYNOPSIS
.SS "Solaris and GNU-compatible"
.LP
.nf
#include <libintl.h>

\fBchar *\fR\fBgettext\fR(\fBconst char *\fR\fImsgid\fR);
.fi

.LP
.nf
\fBchar *\fR\fBdgettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid\fR);
.fi

.LP
.nf
\fBchar *\fR\fBtextdomain\fR(\fBconst char *\fR\fIdomainname\fR);
.fi

.LP
.nf
\fBchar *\fR\fBbindtextdomain\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fIdirname\fR);
.fi

.LP
.nf
#include <libintl.h>
#include <locale.h>

\fBchar *\fR\fBdcgettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid\fR,
     \fBint\fR \fIcategory\fR);
.fi

.SS "GNU-compatible"
.LP
.nf
#include <libintl.h>

\fBchar *\fR\fBngettext\fR(\fBconst char *\fR\fImsgid1\fR, \fBconst char *\fR\fImsgid2\fR,
     \fBunsigned long int\fR \fIn\fR);
.fi

.LP
.nf
\fBchar *\fR\fBdngettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid1\fR,
     \fBconst char *\fR\fImsgid2\fR, \fBunsigned long int\fR \fIn\fR);
.fi

.LP
.nf
\fBchar *\fR\fBbind_textdomain_codeset\fR(\fBconst char *\fR\fIdomainname\fR,
     \fBconst char *\fR\fIcodeset\fR);
.fi

.LP
.nf
extern int _nl_msg_cat_cntr;
extern int *_nl_domain_bindings;
.fi

.LP
.nf
#include <libintl.h>
#include <locale.h>

\fBchar *\fR\fBdcngettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid1\fR,
     \fBconst char *\fR\fImsgid2\fR, \fBunsigned long int\fR \fIn\fR, \fBint\fR \fIcategory\fR);
.fi

.SH DESCRIPTION
.LP
The \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR functions attempt
to retrieve a target string based on the specified \fImsgid\fR argument within
the context of a specific domain and the current locale. The length of strings
returned by \fBgettext()\fR,  \fBdgettext()\fR, and \fBdcgettext()\fR is
undetermined until the function is called. The \fImsgid\fR argument is a
null-terminated string.
.sp
.LP
The \fBngettext()\fR, \fBdngettext()\fR, and \fBdcngettext()\fR functions are
equivalent to \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR,
respectively, except for the handling of plural forms.  These functions work
only with GNU-compatible message catalogues.  The \fBngettext()\fR,
\fBdngettext()\fR, and \fBdcngettext()\fR functions search for the message
string using the \fImsgid1\fR argument as the key and the \fIn\fR argument to
determine the plural form.  If no message catalogues are found, \fImsgid1\fR is
returned if \fIn\fR == 1, otherwise \fImsgid2\fR is returned.
.sp
.LP
The \fBNLSPATH\fR environment variable (see \fBenviron\fR(7)) is searched first
for the location of the  \fBLC_MESSAGES\fR catalogue. The setting of the
\fBLC_MESSAGES\fR category of the current locale determines the locale used by
\fBgettext()\fR and \fBdgettext()\fR for string retrieval. The \fIcategory\fR
argument determines the locale used by \fBdcgettext(\|).\fR If \fBNLSPATH\fR is
not defined and the current locale is "C", \fBgettext()\fR, \fBdgettext()\fR,
and \fBdcgettext()\fR simply return the message string that was passed.  In a
locale  other than "C", if \fBNLSPATH\fR is not defined or if a message
catalogue is not found in any of the components specified by \fBNLSPATH\fR, the
routines search for the message catalogue using the scheme described in the
following paragraph.
.sp
.LP
The \fBLANGUAGE\fR environment variable is examined to determine the
GNU-compatible message catalogues to be used. The value of \fBLANGUAGE\fR is a
list of locale names separated by a colon (':') character.  If \fBLANGUAGE\fR
is defined, each locale name is tried in the specified order and if a
GNU-compatible message catalogue is found, the message is returned.  If a
GNU-compatible message catalogue is found but failed to find a corresponding
\fImsgid\fR, the \fImsgid\fR string is return. If \fBLANGUAGE\fR is not defined
or if a Solaris message catalogue is found or no GNU-compatible message
catalogue is found in processing \fBLANGUAGE\fR, the pathname used to locate
the message catalogue is
\fIdirname\fR/\fIlocale\fR/\fIcategory\fR/\fIdomainname\fR.mo, where
\fIdirname\fR is the directory specified by \fBbindtextdomain()\fR,
\fIlocale\fR is a locale name, and \fIcategory\fR is either \fBLC_MESSAGES\fR
if \fBgettext()\fR, \fBdgettext()\fR, \fBngettext()\fR, or \fBdngettext()\fR is
called, or \fBLC_XXX\fR where the name is the same as the locale category name
specified by the \fIcategory\fR argument to \fBdcgettext()\fR or
\fBdcngettext()\fR.
.sp
.LP
For \fBgettext()\fR and \fBngettext()\fR, the domain used is set by the last
valid call to \fBtextdomain()\fR. If a valid call to \fBtextdomain()\fR has not
been made, the default domain  (called \fBmessages\fR) is used.
.sp
.LP
For \fBdgettext()\fR, \fBdcgettext()\fR, \fBdngettext()\fR, and
\fBdcngettext()\fR, the domain used is specified by the \fIdomainname\fR
argument. The \fIdomainname\fR argument is equivalent in syntax and meaning to
the \fIdomainname\fR argument to \fBtextdomain()\fR, except that the selection
of the domain is valid only for the duration of the \fBdgettext()\fR,
\fBdcgettext()\fR, \fBdngettext()\fR, or \fBdcngettext()\fR function call.
.sp
.LP
The \fBtextdomain()\fR function sets or queries the name of the current domain
of the active  \fBLC_MESSAGES\fR locale category. The \fIdomainname\fR argument
is a null-terminated string that can contain only the characters allowed in
legal filenames.
.sp
.LP
The \fIdomainname\fR argument is the unique name of a domain on the system. If
there are multiple versions of the same domain on one system, namespace
collisions can be avoided by using  \fBbindtextdomain()\fR. If
\fBtextdomain()\fR is not called, a default domain is selected. The setting of
domain made by the last valid call to \fBtextdomain()\fR remains valid across
subsequent calls to  \fBsetlocale\fR(3C), and \fBgettext()\fR.
.sp
.LP
The  \fIdomainname\fR argument is applied to the currently active
\fBLC_MESSAGES\fR locale.
.sp
.LP
The current setting of the domain can be queried without affecting the current
state of the domain by calling \fBtextdomain()\fR with \fIdomainname\fR set to
the null pointer. Calling \fBtextdomain()\fR with a  \fIdomainname\fR argument
of a null string sets the domain to the default domain (\fBmessages\fR).
.sp
.LP
The \fBbindtextdomain()\fR function binds the path predicate for a message
domain \fIdomainname\fR to the value contained in \fIdirname\fR. If
\fIdomainname\fR is a non-empty string and has not been bound previously,
\fBbindtextdomain()\fR binds  \fIdomainname\fR with  \fIdirname\fR.
.sp
.LP
If  \fIdomainname\fR is a non-empty string and has been bound previously,
\fBbindtextdomain()\fR replaces the old binding with  \fIdirname\fR. The
\fIdirname\fR argument can be an absolute or relative pathname being resolved
when  \fBgettext()\fR, \fBdgettext()\fR, or \fBdcgettext()\fR are called. If
\fIdomainname\fR is a null pointer or an empty string,  \fBbindtextdomain()\fR
returns \fINULL.\fR User defined domain names cannot begin with the string
\fBSYS_\fR. Domain names beginning with this string are reserved for system
use.
.sp
.LP
The \fBbind_textdomain_codeset()\fR function can be used to specify the output
codeset for message catalogues for domain \fIdomainname\fR.  The \fIcodeset\fR
argument must be a valid codeset name that can be used for the
\fBiconv_open\fR(3C) function, or a null pointer. If the \fIcodeset\fR argument
is the null pointer, \fBbind_textdomain_codeset()\fR returns the currently
selected codeset for the domain with the name \fIdomainname\fR.  It returns a
null pointer if a codeset has not yet been selected. The
\fBbind_textdomain_codeset()\fR function can be used multiple times.  If used
multiple times with the same \fIdomainname\fR argument, the later call
overrides the settings made by the earlier one. The
\fBbind_textdomain_codeset()\fR function returns a pointer to a string
containing the name of the selected codeset. The string is allocated internally
in the function and must not be changed by the user.
.sp
.LP
The external variables \fB_nl_msg_cat_cntr\fR and \fB_nl_domain_bindings\fR are
provided for the compatibility with the GNU \fBgettext()\fR implementation.
.SH RETURN VALUES
.LP
The \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR functions return
the message string if the search succeeds. Otherwise they return the
\fImsgid\fR string.
.sp
.LP
The \fBngettext()\fR, \fBdngettext()\fR, and \fBdcngettext()\fR functions
return the message string if the search succeeds.  If the search fails,
\fImsgid1\fR is returned if \fIn\fR == 1. Otherwise \fImsgid2\fR is returned.
.sp
.LP
The individual bytes of the string returned by \fBgettext()\fR,
\fBdgettext()\fR, \fBdcgettext()\fR, \fBngettext()\fR, \fBdngettext()\fR, or
\fBdcngettext()\fR can contain any value other than \fINULL\fR. If \fImsgid\fR
is a null pointer, the return value is undefined. The string returned must not
be modified by the program and can be invalidated by a subsequent call to
\fBbind_textdomain_codeset()\fR or \fBsetlocale\fR(3C). If the
\fIdomainname\fR argument to  \fBdgettext()\fR,\fBdcgettext()\fR,
\fBdngettext()\fR, or \fBdcngettext()\fR is a null pointer, the domain
currently bound by \fBtextdomain()\fR is used.
.sp
.LP
The normal return value from \fBtextdomain()\fR is a pointer to a string
containing the current setting of the domain. If \fIdomainname\fR is a null
pointer, \fBtextdomain()\fR returns a pointer to the string containing the
current domain. If \fBtextdomain()\fR was not previously called and
\fIdomainname\fR is a null string, the name of the default domain is returned.
The name of the default domain is \fBmessages\fR. If \fBtextdomain()\fR fails,
a null pointer is returned.
.sp
.LP
The return value from \fBbindtextdomain()\fR is a null-terminated string
containing \fIdirname\fR or the directory binding associated with
\fIdomainname\fR if \fIdirname\fR is \fINULL.\fR If no binding is found, the
default return value is  \fB/usr/lib/locale\fR. If  \fIdomainname\fR is a null
pointer or an empty string, \fBbindtextdomain()\fR takes no action and returns
a null pointer. The string returned must not be modified by the caller. If
\fBbindtextdomain()\fR fails, a null pointer is returned.
.SH USAGE
.LP
These functions impose no limit on message length. However, a text
\fIdomainname\fR is limited to \fBTEXTDOMAINMAX\fR (256) bytes.
.sp
.LP
The \fBgettext()\fR, \fBdgettext()\fR, \fBdcgettext()\fR, \fBngettext()\fR,
\fBdngettext()\fR, \fBdcngettext()\fR, \fBtextdomain()\fR, and
\fBbindtextdomain()\fR functions can be used safely in multithreaded
applications, as long as \fBsetlocale\fR(3C) is not being called to change the
locale.
.sp
.LP
The \fBgettext()\fR, \fBdgettext()\fR, \fBdcgettext()\fR, \fBtextdomain()\fR,
and \fBbindtextdomain()\fR functions work with both Solaris message catalogues
and GNU-compatible message catalogues.  The \fBngettext()\fR,
\fBdngettext()\fR, \fBdcngettext()\fR, and \fBbind_textdomain_codeset()\fR
functions work only with GNU-compatible message catalogues.  See
\fBmsgfmt\fR(1) for information about Solaris message catalogues and
GNU-compatible message catalogues.
.SH FILES
.ne 2
.na
\fB\fB/usr/lib/locale\fR\fR
.ad
.sp .6
.RS 4n
default path predicate for message domain files
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/locale/\fR\fIlocale\fR\fB/LC_MESSAGES/\fR\fIdomainname\fR\fB\&.m
o\fR\fR
.ad
.sp .6
.RS 4n
system default location for file containing messages for  language
\fIlocale\fR and \fIdomainname\fR
.RE

.sp
.ne 2
.na
\fB\fB/usr/lib/locale/\fR\fIlocale\fR\fB/LC_XXX/\fR\fIdomainname\fR\fB\&.mo\fR\fR
.ad
.sp .6
.RS 4n
system default location for file containing messages for  language
\fIlocale\fR and \fIdomainname\fR for \fBdcgettext()\fR calls where
\fBLC_XXX\fR is  \fBLC_CTYPE\fR, \fBLC_NUMERIC\fR, \fBLC_TIME\fR,
\fBLC_COLLATE\fR, \fBLC_MONETARY\fR, or \fBLC_MESSAGES\fR
.RE

.sp
.ne 2
.na
\fB\fB\fR\fIdirname\fR\fB/\fR\fIlocale\fR\fB/LC_MESSAGES/\fR\fIdomainname\fR\fB
\&.mo\fR\fR
.ad
.sp .6
.RS 4n
location for file containing messages for domain \fIdomainname\fR and path
predicate \fIdirname\fR after a successful call to \fBbindtextdomain()\fR
.RE

.sp
.ne 2
.na
\fB\fB\fR\fIdirname\fR\fB/\fR\fIlocale\fR\fB/LC_XXX/\fR\fIdomainname\fR\fB\&.mo
\fR\fR
.ad
.sp .6
.RS 4n
location for files containing messages for domain \fIdomainname,\fR language
\fIlocale,\fR and path predicate \fIdirname\fR after a successful call to
\fBbindtextdomain()\fR for \fBdcgettext()\fR calls where \fBLC_XXX\fR is one of
\fBLC_CTYPE\fR, \fBLC_NUMERIC\fR, \fBLC_TIME\fR, \fBLC_COLLATE\fR,
\fBLC_MONETARY\fR, or \fBLC_MESSAGES\fR
.RE

.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	See below.
_
MT-Level	Safe with exceptions
.TE

.sp
.LP
The external variables \fB_nl_msg_cat_cntr\fR and \fB_nl_domain_bindings\fR are
Uncommitted.
.SH SEE ALSO
.LP
.BR msgfmt (1),
.BR xgettext (1),
.BR iconv_open (3C),
.BR setlocale (3C),
.BR libintl.h (3HEAD),
.BR attributes (7),
.BR environ (7)