1502 Remove conversion cruft from manpages
[unleashed.git] / usr / src / man / man3c / gettext.3c
blobd213b9cbbb48de18187622c425d917669e95ba07
1 '\" te
2 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH GETTEXT 3C "Jun 4, 2008"
7 .SH NAME
8 gettext, dgettext, dcgettext, ngettext, dngettext, dcngettext, textdomain,
9 bindtextdomain, bind_textdomain_codeset \- message handling functions
10 .SH SYNOPSIS
11 .SS "Solaris and GNU-compatible"
12 .LP
13 .nf
14 #include <libintl.h>
16 \fBchar *\fR\fBgettext\fR(\fBconst char *\fR\fImsgid\fR);
17 .fi
19 .LP
20 .nf
21 \fBchar *\fR\fBdgettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid\fR);
22 .fi
24 .LP
25 .nf
26 \fBchar *\fR\fBtextdomain\fR(\fBconst char *\fR\fIdomainname\fR);
27 .fi
29 .LP
30 .nf
31 \fBchar *\fR\fBbindtextdomain\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fIdirname\fR);
32 .fi
34 .LP
35 .nf
36 #include <libintl.h>
37 #include <locale.h>
39 \fBchar *\fR\fBdcgettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid\fR,
40      \fBint\fR \fIcategory\fR);
41 .fi
43 .SS "GNU-compatible"
44 .LP
45 .nf
46 #include <libintl.h>
48 \fBchar *\fR\fBngettext\fR(\fBconst char *\fR\fImsgid1\fR, \fBconst char *\fR\fImsgid2\fR,
49      \fBunsigned long int\fR \fIn\fR);
50 .fi
52 .LP
53 .nf
54 \fBchar *\fR\fBdngettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid1\fR,
55      \fBconst char *\fR\fImsgid2\fR, \fBunsigned long int\fR \fIn\fR);
56 .fi
58 .LP
59 .nf
60 \fBchar *\fR\fBbind_textdomain_codeset\fR(\fBconst char *\fR\fIdomainname\fR,
61      \fBconst char *\fR\fIcodeset\fR);
62 .fi
64 .LP
65 .nf
66 extern int _nl_msg_cat_cntr;
67 extern int *_nl_domain_bindings;
68 .fi
70 .LP
71 .nf
72 #include <libintl.h>
73 #include <locale.h>
75 \fBchar *\fR\fBdcngettext\fR(\fBconst char *\fR\fIdomainname\fR, \fBconst char *\fR\fImsgid1\fR,
76      \fBconst char *\fR\fImsgid2\fR, \fBunsigned long int\fR \fIn\fR, \fBint\fR \fIcategory\fR);
77 .fi
79 .SH DESCRIPTION
80 .sp
81 .LP
82 The \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR functions attempt
83 to retrieve a target string based on the specified \fImsgid\fR argument within
84 the context of a specific domain and the current locale. The length of strings
85 returned by \fBgettext()\fR,  \fBdgettext()\fR, and \fBdcgettext()\fR is
86 undetermined until the function is called. The \fImsgid\fR argument is a
87 null-terminated string.
88 .sp
89 .LP
90 The \fBngettext()\fR, \fBdngettext()\fR, and \fBdcngettext()\fR functions are
91 equivalent to \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR,
92 respectively, except for the handling of plural forms.  These functions work
93 only with GNU-compatible message catalogues.  The \fBngettext()\fR,
94 \fBdngettext()\fR, and \fBdcngettext()\fR functions search for the message
95 string using the \fImsgid1\fR argument as the key and the \fIn\fR argument to
96 determine the plural form.  If no message catalogues are found, \fImsgid1\fR is
97 returned if \fIn\fR == 1, otherwise \fImsgid2\fR is returned.
98 .sp
99 .LP
100 The \fBNLSPATH\fR environment variable (see \fBenviron\fR(5)) is searched first
101 for the location of the  \fBLC_MESSAGES\fR catalogue. The setting of the
102 \fBLC_MESSAGES\fR category of the current locale determines the locale used by
103 \fBgettext()\fR and \fBdgettext()\fR for string retrieval. The \fIcategory\fR
104 argument determines the locale used by \fBdcgettext(\|).\fR If \fBNLSPATH\fR is
105 not defined and the current locale is "C", \fBgettext()\fR, \fBdgettext()\fR,
106 and \fBdcgettext()\fR simply return the message string that was passed.  In a
107 locale  other than "C", if \fBNLSPATH\fR is not defined or if a message
108 catalogue is not found in any of the components specified by \fBNLSPATH\fR, the
109 routines search for the message catalogue using the scheme described in the
110 following paragraph.
113 The \fBLANGUAGE\fR environment variable is examined to determine the
114 GNU-compatible message catalogues to be used. The value of \fBLANGUAGE\fR is a
115 list of locale names separated by a colon (':') character.  If \fBLANGUAGE\fR
116 is defined, each locale name is tried in the specified order and if a
117 GNU-compatible message catalogue is found, the message is returned.  If a
118 GNU-compatible message catalogue is found but failed to find a corresponding
119 \fImsgid\fR, the \fImsgid\fR string is return. If \fBLANGUAGE\fR is not defined
120 or if a Solaris message catalogue is found or no GNU-compatible message
121 catalogue is found in processing \fBLANGUAGE\fR, the pathname used to locate
122 the message catalogue is
123 \fIdirname\fR/\fIlocale\fR/\fIcategory\fR/\fIdomainname\fR.mo, where
124 \fIdirname\fR is the directory specified by \fBbindtextdomain()\fR,
125 \fIlocale\fR is a locale name, and \fIcategory\fR is either \fBLC_MESSAGES\fR
126 if \fBgettext()\fR, \fBdgettext()\fR, \fBngettext()\fR, or \fBdngettext()\fR is
127 called, or \fBLC_XXX\fR where the name is the same as the locale category name
128 specified by the \fIcategory\fR argument to \fBdcgettext()\fR or
129 \fBdcngettext()\fR.
132 For \fBgettext()\fR and \fBngettext()\fR, the domain used is set by the last
133 valid call to \fBtextdomain()\fR. If a valid call to \fBtextdomain()\fR has not
134 been made, the default domain  (called \fBmessages\fR) is used.
137 For \fBdgettext()\fR, \fBdcgettext()\fR, \fBdngettext()\fR, and
138 \fBdcngettext()\fR, the domain used is specified by the \fIdomainname\fR
139 argument. The \fIdomainname\fR argument is equivalent in syntax and meaning to
140 the \fIdomainname\fR argument to \fBtextdomain()\fR, except that the selection
141 of the domain is valid only for the duration of the \fBdgettext()\fR,
142 \fBdcgettext()\fR, \fBdngettext()\fR, or \fBdcngettext()\fR function call.
145 The \fBtextdomain()\fR function sets or queries the name of the current domain
146 of the active  \fBLC_MESSAGES\fR locale category. The \fIdomainname\fR argument
147 is a null-terminated string that can contain only the characters allowed in
148 legal filenames.
151 The \fIdomainname\fR argument is the unique name of a domain on the system. If
152 there are multiple versions of the same domain on one system, namespace
153 collisions can be avoided by using  \fBbindtextdomain()\fR. If
154 \fBtextdomain()\fR is not called, a default domain is selected. The setting of
155 domain made by the last valid call to \fBtextdomain()\fR remains valid across
156 subsequent calls to  \fBsetlocale\fR(3C), and \fBgettext()\fR.
159 The  \fIdomainname\fR argument is applied to the currently active
160 \fBLC_MESSAGES\fR locale.
163 The current setting of the domain can be queried without affecting the current
164 state of the domain by calling \fBtextdomain()\fR with \fIdomainname\fR set to
165 the null pointer. Calling \fBtextdomain()\fR with a  \fIdomainname\fR argument
166 of a null string sets the domain to the default domain (\fBmessages\fR).
169 The \fBbindtextdomain()\fR function binds the path predicate for a message
170 domain \fIdomainname\fR to the value contained in \fIdirname\fR. If
171 \fIdomainname\fR is a non-empty string and has not been bound previously,
172 \fBbindtextdomain()\fR binds  \fIdomainname\fR with  \fIdirname\fR.
175 If  \fIdomainname\fR is a non-empty string and has been bound previously,
176 \fBbindtextdomain()\fR replaces the old binding with  \fIdirname\fR. The
177 \fIdirname\fR argument can be an absolute or relative pathname being resolved
178 when  \fBgettext()\fR, \fBdgettext()\fR, or \fBdcgettext()\fR are called. If
179 \fIdomainname\fR is a null pointer or an empty string,  \fBbindtextdomain()\fR
180 returns \fINULL.\fR User defined domain names cannot begin with the string
181 \fBSYS_\fR. Domain names beginning with this string are reserved for system
182 use.
185 The \fBbind_textdomain_codeset()\fR function can be used to specify the output
186 codeset for message catalogues for domain \fIdomainname\fR.  The \fIcodeset\fR
187 argument must be a valid codeset name that can be used for the
188 \fBiconv_open\fR(3C) function, or a null pointer. If the \fIcodeset\fR argument
189 is the null pointer, \fBbind_textdomain_codeset()\fR returns the currently
190 selected codeset for the domain with the name \fIdomainname\fR.  It returns a
191 null pointer if a codeset has not yet been selected. The
192 \fBbind_textdomain_codeset()\fR function can be used multiple times.  If used
193 multiple times with the same \fIdomainname\fR argument, the later call
194 overrides the settings made by the earlier one. The
195 \fBbind_textdomain_codeset()\fR function returns a pointer to a string
196 containing the name of the selected codeset. The string is allocated internally
197 in the function and must not be changed by the user.
200 The external variables \fB_nl_msg_cat_cntr\fR and \fB_nl_domain_bindings\fR are
201 provided for the compatibility with the GNU \fBgettext()\fR implementation.
202 .SH RETURN VALUES
205 The \fBgettext()\fR, \fBdgettext()\fR, and \fBdcgettext()\fR functions return
206 the message string if the search succeeds. Otherwise they return the
207 \fImsgid\fR string.
210 The \fBngettext()\fR, \fBdngettext()\fR, and \fBdcngettext()\fR functions
211 return the message string if the search succeeds.  If the search fails,
212 \fImsgid1\fR is returned if \fIn\fR == 1. Otherwise \fImsgid2\fR is returned.
215 The individual bytes of the string returned by \fBgettext()\fR,
216 \fBdgettext()\fR, \fBdcgettext()\fR, \fBngettext()\fR, \fBdngettext()\fR, or
217 \fBdcngettext()\fR can contain any value other than \fINULL\fR. If \fImsgid\fR
218 is a null pointer, the return value is undefined. The string returned must not
219 be modified by the program and can be invalidated by a subsequent call to
220 \fBbind_textdomain_codeset()\fR or \fBsetlocale\fR(3C). If the
221 \fIdomainname\fR argument to  \fBdgettext()\fR,\fBdcgettext()\fR,
222 \fBdngettext()\fR, or \fBdcngettext()\fR is a null pointer, the the domain
223 currently bound by \fBtextdomain()\fR is used.
226 The normal return value from \fBtextdomain()\fR is a pointer to a string
227 containing the current setting of the domain. If \fIdomainname\fR is a null
228 pointer, \fBtextdomain()\fR returns a pointer to the string containing the
229 current domain. If \fBtextdomain()\fR was not previously called and
230 \fIdomainname\fR is a null string, the name of the default domain is returned.
231 The name of the default domain is \fBmessages\fR. If \fBtextdomain()\fR fails,
232 a null pointer is returned.
235 The return value from \fBbindtextdomain()\fR is a null-terminated string
236 containing \fIdirname\fR or the directory binding associated with
237 \fIdomainname\fR if \fIdirname\fR is \fINULL.\fR If no binding is found, the
238 default return value is  \fB/usr/lib/locale\fR. If  \fIdomainname\fR is a null
239 pointer or an empty string, \fBbindtextdomain()\fR takes no action and returns
240 a null pointer. The string returned must not be modified by the caller. If
241 \fBbindtextdomain()\fR fails, a null pointer is returned.
242 .SH USAGE
245 These functions impose no limit on message length. However, a text
246 \fIdomainname\fR is limited to \fBTEXTDOMAINMAX\fR (256) bytes.
249 The \fBgettext()\fR, \fBdgettext()\fR, \fBdcgettext()\fR, \fBngettext()\fR,
250 \fBdngettext()\fR, \fBdcngettext()\fR, \fBtextdomain()\fR, and
251 \fBbindtextdomain()\fR functions can be used safely in multithreaded
252 applications, as long as \fBsetlocale\fR(3C) is not being called to change the
253 locale.
256 The \fBgettext()\fR, \fBdgettext()\fR, \fBdcgettext()\fR, \fBtextdomain()\fR,
257 and \fBbindtextdomain()\fR functions work with both Solaris message catalogues
258 and GNU-compatible message catalogues.  The \fBngettext()\fR,
259 \fBdngettext()\fR, \fBdcngettext()\fR, and \fBbind_textdomain_codeset()\fR
260 functions work only with GNU-compatible message catalogues.  See
261 \fBmsgfmt\fR(1) for information about Solaris message catalogues and
262 GNU-compatible message catalogues.
263 .SH FILES
265 .ne 2
267 \fB\fB/usr/lib/locale\fR\fR
269 .sp .6
270 .RS 4n
271 default path predicate for message domain files
275 .ne 2
277 \fB\fB/usr/lib/locale/\fR\fIlocale\fR\fB/LC_MESSAGES/\fR\fIdomainname\fR\fB\&.m
278 o\fR\fR
280 .sp .6
281 .RS 4n
282 system default location for file containing messages for  language
283 \fIlocale\fR and \fIdomainname\fR
287 .ne 2
289 \fB\fB/usr/lib/locale/\fR\fIlocale\fR\fB/LC_XXX/\fR\fIdomainname\fR\fB\&.mo\fR\
292 .sp .6
293 .RS 4n
294 system default location for file containing messages for  language
295 \fIlocale\fR and \fIdomainname\fR for \fBdcgettext()\fR calls where
296 \fBLC_XXX\fR is  \fBLC_CTYPE\fR, \fBLC_NUMERIC\fR, \fBLC_TIME\fR,
297 \fBLC_COLLATE\fR, \fBLC_MONETARY\fR, or \fBLC_MESSAGES\fR
301 .ne 2
303 \fB\fB\fR\fIdirname\fR\fB/\fR\fIlocale\fR\fB/LC_MESSAGES/\fR\fIdomainname\fR\fB
304 \&.mo\fR\fR
306 .sp .6
307 .RS 4n
308 location for file containing messages for domain \fIdomainname\fR and path
309 predicate \fIdirname\fR after a successful call to \fBbindtextdomain()\fR
313 .ne 2
315 \fB\fB\fR\fIdirname\fR\fB/\fR\fIlocale\fR\fB/LC_XXX/\fR\fIdomainname\fR\fB\&.mo
316 \fR\fR
318 .sp .6
319 .RS 4n
320 location for files containing messages for domain \fIdomainname,\fR language
321 \fIlocale,\fR and path predicate \fIdirname\fR after a successful call to
322 \fBbindtextdomain()\fR for \fBdcgettext()\fR calls where \fBLC_XXX\fR is one of
323 \fBLC_CTYPE\fR, \fBLC_NUMERIC\fR, \fBLC_TIME\fR, \fBLC_COLLATE\fR,
324 \fBLC_MONETARY\fR, or \fBLC_MESSAGES\fR
327 .SH ATTRIBUTES
330 See \fBattributes\fR(5) for descriptions of the following attributes:
335 box;
336 c | c
337 l | l .
338 ATTRIBUTE TYPE  ATTRIBUTE VALUE
340 Interface Stability     See below.
342 MT-Level        Safe with exceptions
347 The external variables \fB_nl_msg_cat_cntr\fR and \fB_nl_domain_bindings\fR are
348 Uncommitted.
349 .SH SEE ALSO
352 \fBmsgfmt\fR(1), \fBxgettext\fR(1), \fBiconv_open\fR(3C),
353 \fBlibintl.h\fR(3HEAD), \fBsetlocale\fR(3C), \fBattributes\fR(5),
354 \fBenviron\fR(5)