(GDS Getting Started): Editorial updates.
[bpt/guile.git] / doc / ref / api-i18n.texi
CommitLineData
fd936c91
MV
1@c -*-texinfo-*-
2@c This is part of the GNU Guile Reference Manual.
3@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004
4@c Free Software Foundation, Inc.
5@c See the file guile.texi for copying conditions.
6
7@page
8@node Internationalization
9@section Support for Internationalization
10
09ecf78c
KR
11Guile provides an interface to GNU @code{gettext} for translating
12message strings (@pxref{Introduction,,, gettext, GNU @code{gettext}
13utilities}).
14
15Messages are collected in domains, so different libraries and programs
16maintain different message catalogues. The @var{domain} parameter in
17the functions below is a string (it becomes part of the message
18catalog filename).
19
20When @code{gettext} is not available, or if Guile was configured
21@samp{--without-nls}, dummy functions doing no translation are
22provided.
23
24@deffn {Scheme Procedure} gettext msg [domain [category]]
25@deffnx {C Function} scm_gettext (msg, domain, category)
26Return the translation of @var{msg} in @var{domain}. @var{domain} is
27optional and defaults to the domain set through @code{textdomain}
28below. @var{category} is optional and defaults to @code{LC_MESSAGES}
29(@pxref{Locales}).
30
31Normal usage is for @var{msg} to be a literal string.
32@command{xgettext} can extract those from the source to form a message
33catalogue ready for translators (@pxref{xgettext Invocation,, Invoking
34the @command{xgettext} Program, gettext, GNU @code{gettext}
35utilities}).
36
37@example
38(display (gettext "You are in a maze of twisty passages."))
39@end example
40
41@code{_} is a commonly used shorthand, an application can make that an
42alias for @code{gettext}. Or a library can make a definition that
43uses its specific @var{domain} (so an application can change the
44default without affecting the library).
45
46@example
47(define (_ msg) (gettext msg "mylibrary"))
48(display (_ "File not found."))
49@end example
50
51@code{_} is also a good place to perhaps strip disambiguating extra
52text from the message string, as for instance in @ref{GUI program
53problems,, How to use @code{gettext} in GUI programs, gettext, GNU
54@code{gettext} utilities}.
fd936c91
MV
55@end deffn
56
09ecf78c
KR
57@deffn {Scheme Procedure} ngettext msg msgplural n [domain [category]]
58@deffnx {C Function} scm_ngettext (msg, msgplural, n, domain, category)
59Return the translation of @var{msg}/@var{msgplural} in @var{domain},
60with a plural form chosen appropriately for the number @var{n}.
61@var{domain} is optional and defaults to the domain set through
62@code{textdomain} below. @var{category} is optional and defaults to
63@code{LC_MESSAGES} (@pxref{Locales}).
64
65@var{msg} is the singular form, and @var{msgplural} the plural. When
66no translation is available, @var{msg} is used if @math{@var{n} = 1},
67or @var{msgplural} otherwise. When translated, the message catalogue
68can have a different rule, and can have more than two possible forms.
69
70As per @code{gettext} above, normal usage is for @var{msg} and
71@var{msgplural} to be literal strings, since @command{xgettext} can
72extract them from the source to build a message catalogue. For
73example,
74
75@example
76(define (done n)
77 (format #t (ngettext "~a file processed\n"
78 "~a files processed\n" n)
79 n))
80
81(done 1) @print{} 1 file processed
82(done 3) @print{} 3 files processed
83@end example
84
85It's important to use @code{ngettext} rather than plain @code{gettext}
86for plurals, since the rules for singular and plural forms in English
87are not the same in other languages. Only @code{ngettext} will allow
88translators to give correct forms.
fd936c91
MV
89@end deffn
90
09ecf78c
KR
91@deffn {Scheme Procedure} textdomain [domain]
92@deffnx {C Function} scm_textdomain (domain)
93Get or set the default gettext domain. When called with no parameter
94the current domain is returned. When called with a parameter,
95@var{domain} is set as the current domain, and that new value
96returned. For example,
97
98@example
99(textdomain "myprog")
100@result{} "myprog"
101@end example
fd936c91
MV
102@end deffn
103
09ecf78c
KR
104@deffn {Scheme Procedure} bindtextdomain domain [directory]
105@deffnx {C Function} scm_bindtextdomain (domain, directory)
106Get or set the directory under which to find message files for
107@var{domain}. When called without a @var{directory} the current
108setting is returned. When called with a @var{directory},
109@var{directory} is set for @var{domain} and that new setting returned.
110For example,
111
112@example
113(bindtextdomain "myprog" "/my/tree/share/locale")
114@result{} "/my/tree/share/locale"
115@end example
116
117When using Autoconf/Automake, an application should arrange for the
118configured @code{localedir} to get into the program (by substituting,
119or by generating a config file) and set that for its domain. This
120ensures the catalogue can be found even when installed in a
121non-standard location.
fd936c91
MV
122@end deffn
123
09ecf78c
KR
124@deffn {Scheme Procedure} bind-textdomain-codeset domain [encoding]
125@deffnx {C Function} scm_bind_textdomain_codeset (domain, encoding)
126Get or set the text encoding to be used by @code{gettext} for messages
127from @var{domain}. @var{encoding} is a string, the name of a coding
128system, for instance @nicode{"8859_1"}. (On a Unix/POSIX system the
129@command{iconv} program can list all available encodings.)
130
131When called without an @var{encoding} the current setting is returned,
132or @code{#f} if none yet set. When called with an @var{encoding}, it
133is set for @var{domain} and that new setting returned. For example,
134
135@example
136(bind-textdomain-codeset "myprog")
137@result{} #f
138(bind-textdomain-codeset "myprog" "latin-9")
139@result{} "latin-9"
140@end example
141
142The encoding requested can be different from the translated data file,
143messages will be recoded as necessary. But note that when there is no
144translation, @code{gettext} returns its @var{msg} unchanged, ie.@:
145without any recoding. For that reason source message strings are best
146as plain ASCII.
147
148Currently Guile has no understanding of multi-byte characters, and
149string functions won't recognise character boundaries in multi-byte
150strings. An application will at least be able to pass such strings
151through to some output though. Perhaps this will change in the
152future.
fd936c91
MV
153@end deffn
154
155@c Local Variables:
156@c TeX-master: "guile.texi"
157@c End: