Improvements to Introduction chapter
[bpt/guile.git] / doc / ref / api-i18n.texi
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, 2006, 2007, 2009
4 @c Free Software Foundation, Inc.
5 @c See the file guile.texi for copying conditions.
6
7 @node Internationalization
8 @section Support for Internationalization
9
10 @cindex internationalization
11 @cindex i18n
12
13 Guile provides internationalization@footnote{For concision and style,
14 programmers often like to refer to internationalization as ``i18n''.}
15 support for Scheme programs in two ways. First, procedures to
16 manipulate text and data in a way that conforms to particular cultural
17 conventions (i.e., in a ``locale-dependent'' way) are provided in the
18 @code{(ice-9 i18n)}. Second, Guile allows the use of GNU
19 @code{gettext} to translate program message strings.
20
21 @menu
22 * i18n Introduction:: Introduction to Guile's i18n support.
23 * Text Collation:: Sorting strings and characters.
24 * Character Case Mapping:: Case mapping.
25 * Number Input and Output:: Parsing and printing numbers.
26 * Accessing Locale Information:: Detailed locale information.
27 * Gettext Support:: Translating message strings.
28 @end menu
29
30
31 @node i18n Introduction, Text Collation, Internationalization, Internationalization
32 @subsection Internationalization with Guile
33
34 In order to make use of the functions described thereafter, the
35 @code{(ice-9 i18n)} module must be imported in the usual way:
36
37 @example
38 (use-modules (ice-9 i18n))
39 @end example
40
41 @cindex cultural conventions
42
43 The @code{(ice-9 i18n)} module provides procedures to manipulate text
44 and other data in a way that conforms to the cultural conventions
45 chosen by the user. Each region of the world or language has its own
46 customs to, for instance, represent real numbers, classify characters,
47 collate text, etc. All these aspects comprise the so-called
48 ``cultural conventions'' of that region or language.
49
50 @cindex locale
51 @cindex locale category
52
53 Computer systems typically refer to a set of cultural conventions as a
54 @dfn{locale}. For each particular aspect that comprise those cultural
55 conventions, a @dfn{locale category} is defined. For instance, the
56 way characters are classified is defined by the @code{LC_CTYPE}
57 category, while the language in which program messages are issued to
58 the user is defined by the @code{LC_MESSAGES} category
59 (@pxref{Locales, General Locale Information} for details).
60
61 @cindex locale object
62
63 The procedures provided by this module allow the development of
64 programs that adapt automatically to any locale setting. As we will
65 see later, many of these procedures can optionally take a @dfn{locale
66 object} argument. This additional argument defines the locale
67 settings that must be followed by the invoked procedure. When it is
68 omitted, then the current locale settings of the process are followed
69 (@pxref{Locales, @code{setlocale}}).
70
71 The following procedures allow the manipulation of such locale
72 objects.
73
74 @deffn {Scheme Procedure} make-locale category-list locale-name [base-locale]
75 @deffnx {C Function} scm_make_locale (category_list, locale_name, base_locale)
76 Return a reference to a data structure representing a set of locale
77 datasets. @var{locale-name} should be a string denoting a particular
78 locale (e.g., @code{"aa_DJ"}) and @var{category-list} should be either
79 a list of locale categories or a single category as used with
80 @code{setlocale} (@pxref{Locales, @code{setlocale}}). Optionally, if
81 @code{base-locale} is passed, it should be a locale object denoting
82 settings for categories not listed in @var{category-list}.
83
84 The following invocation creates a locale object that combines the use
85 of Swedish for messages and character classification with the
86 default settings for the other categories (i.e., the settings of the
87 default @code{C} locale which usually represents conventions in use in
88 the USA):
89
90 @example
91 (make-locale (list LC_MESSAGE LC_CTYPE) "sv_SE")
92 @end example
93
94 The following example combines the use of Esperanto messages and
95 conventions with monetary conventions from Croatia:
96
97 @example
98 (make-locale LC_MONETARY "hr_HR"
99 (make-locale LC_ALL "eo_EO"))
100 @end example
101
102 A @code{system-error} exception (@pxref{Handling Errors}) is raised by
103 @code{make-locale} when @var{locale-name} does not match any of the
104 locales compiled on the system. Note that on non-GNU systems, this
105 error may be raised later, when the locale object is actually used.
106
107 @end deffn
108
109 @deffn {Scheme Procedure} locale? obj
110 @deffnx {C Function} scm_locale_p (obj)
111 Return true if @var{obj} is a locale object.
112 @end deffn
113
114 @defvr {Scheme Variable} %global-locale
115 @defvrx {C Variable} scm_global_locale
116 This variable is bound to a locale object denoting the current process
117 locale as installed using @code{setlocale ()} (@pxref{Locales}). It
118 may be used like any other locale object, including as a third
119 argument to @code{make-locale}, for instance.
120 @end defvr
121
122
123 @node Text Collation, Character Case Mapping, i18n Introduction, Internationalization
124 @subsection Text Collation
125
126 The following procedures provide support for text collation, i.e.,
127 locale-dependent string and character sorting.
128
129 @deffn {Scheme Procedure} string-locale<? s1 s2 [locale]
130 @deffnx {C Function} scm_string_locale_lt (s1, s2, locale)
131 @deffnx {Scheme Procedure} string-locale>? s1 s2 [locale]
132 @deffnx {C Function} scm_string_locale_gt (s1, s2, locale)
133 @deffnx {Scheme Procedure} string-locale-ci<? s1 s2 [locale]
134 @deffnx {C Function} scm_string_locale_ci_lt (s1, s2, locale)
135 @deffnx {Scheme Procedure} string-locale-ci>? s1 s2 [locale]
136 @deffnx {C Function} scm_string_locale_ci_gt (s1, s2, locale)
137 Compare strings @var{s1} and @var{s2} in a locale-dependent way. If
138 @var{locale} is provided, it should be locale object (as returned by
139 @code{make-locale}) and will be used to perform the comparison;
140 otherwise, the current system locale is used. For the @code{-ci}
141 variants, the comparison is made in a case-insensitive way.
142 @end deffn
143
144 @deffn {Scheme Procedure} string-locale-ci=? s1 s2 [locale]
145 @deffnx {C Function} scm_string_locale_ci_eq (s1, s2, locale)
146 Compare strings @var{s1} and @var{s2} in a case-insensitive, and
147 locale-dependent way. If @var{locale} is provided, it should be
148 a locale object (as returned by @code{make-locale}) and will be used to
149 perform the comparison; otherwise, the current system locale is used.
150 @end deffn
151
152 @deffn {Scheme Procedure} char-locale<? c1 c2 [locale]
153 @deffnx {C Function} scm_char_locale_lt (c1, c2, locale)
154 @deffnx {Scheme Procedure} char-locale>? c1 c2 [locale]
155 @deffnx {C Function} scm_char_locale_gt (c1, c2, locale)
156 @deffnx {Scheme Procedure} char-locale-ci<? c1 c2 [locale]
157 @deffnx {C Function} scm_char_locale_ci_lt (c1, c2, locale)
158 @deffnx {Scheme Procedure} char-locale-ci>? c1 c2 [locale]
159 @deffnx {C Function} scm_char_locale_ci_gt (c1, c2, locale)
160 Compare characters @var{c1} and @var{c2} according to either
161 @var{locale} (a locale object as returned by @code{make-locale}) or
162 the current locale. For the @code{-ci} variants, the comparison is
163 made in a case-insensitive way.
164 @end deffn
165
166 @deffn {Scheme Procedure} char-locale-ci=? c1 c2 [locale]
167 @deffnx {C Function} scm_char_locale_ci_eq (c1, c2, locale)
168 Return true if character @var{c1} is equal to @var{c2}, in a case
169 insensitive way according to @var{locale} or to the current locale.
170 @end deffn
171
172 @node Character Case Mapping, Number Input and Output, Text Collation, Internationalization
173 @subsection Character Case Mapping
174
175 The procedures below provide support for ``character case mapping'',
176 i.e., to convert characters or strings to their upper-case or
177 lower-case equivalent. Note that SRFI-13 provides procedures that
178 look similar (@pxref{Alphabetic Case Mapping}). However, the SRFI-13
179 procedures are locale-independent. Therefore, they do not take into
180 account specificities of the customs in use in a particular language
181 or region of the world. For instance, while most languages using the
182 Latin alphabet map lower-case letter ``i'' to upper-case letter ``I'',
183 Turkish maps lower-case ``i'' to ``Latin capital letter I with dot
184 above''. The following procedures allow programmers to provide
185 idiomatic character mapping.
186
187 @deffn {Scheme Procedure} char-locale-downcase chr [locale]
188 @deffnx {C Function} scm_char_locale_upcase (chr, locale)
189 Return the lowercase character that corresponds to @var{chr} according
190 to either @var{locale} or the current locale.
191 @end deffn
192
193 @deffn {Scheme Procedure} char-locale-upcase chr [locale]
194 @deffnx {C Function} scm_char_locale_downcase (chr, locale)
195 Return the uppercase character that corresponds to @var{chr} according
196 to either @var{locale} or the current locale.
197 @end deffn
198
199 @deffn {Scheme Procedure} char-locale-titlecase chr [locale]
200 @deffnx {C Function} scm_char_locale_titlecase (chr, locale)
201 Return the titlecase character that corresponds to @var{chr} according
202 to either @var{locale} or the current locale.
203 @end deffn
204
205 @deffn {Scheme Procedure} string-locale-upcase str [locale]
206 @deffnx {C Function} scm_string_locale_upcase (str, locale)
207 Return a new string that is the uppercase version of @var{str}
208 according to either @var{locale} or the current locale.
209 @end deffn
210
211 @deffn {Scheme Procedure} string-locale-downcase str [locale]
212 @deffnx {C Function} scm_string_locale_downcase (str, locale)
213 Return a new string that is the down-case version of @var{str}
214 according to either @var{locale} or the current locale.
215 @end deffn
216
217 @deffn {Scheme Procedure} string-locale-titlecase str [locale]
218 @deffnx {C Function} scm_string_locale_titlecase (str, locale)
219 Return a new string that is the titlecase version of @var{str}
220 according to either @var{locale} or the current locale.
221 @end deffn
222
223 Note that in the current implementation Guile has no notion of
224 multibyte characters and in a multibyte locale characters may not be
225 converted correctly.
226
227 @node Number Input and Output, Accessing Locale Information, Character Case Mapping, Internationalization
228 @subsection Number Input and Output
229
230 The following procedures allow programs to read and write numbers
231 written according to a particular locale. As an example, in English,
232 ``ten thousand and a half'' is usually written @code{10,000.5} while
233 in French it is written @code{10 000,5}. These procedures allow such
234 differences to be taken into account.
235
236 @findex strtod
237 @deffn {Scheme Procedure} locale-string->integer str [base [locale]]
238 @deffnx {C Function} scm_locale_string_to_integer (str, base, locale)
239 Convert string @var{str} into an integer according to either
240 @var{locale} (a locale object as returned by @code{make-locale}) or
241 the current process locale. If @var{base} is specified, then it
242 determines the base of the integer being read (e.g., @code{16} for an
243 hexadecimal number, @code{10} for a decimal number); by default,
244 decimal numbers are read. Return two values (@pxref{Multiple
245 Values}): an integer (on success) or @code{#f}, and the number of
246 characters read from @var{str} (@code{0} on failure).
247
248 This function is based on the C library's @code{strtol} function
249 (@pxref{Parsing of Integers, @code{strtol},, libc, The GNU C Library
250 Reference Manual}).
251 @end deffn
252
253 @findex strtod
254 @deffn {Scheme Procedure} locale-string->inexact str [locale]
255 @deffnx {C Function} scm_locale_string_to_inexact (str, locale)
256 Convert string @var{str} into an inexact number according to either
257 @var{locale} (a locale object as returned by @code{make-locale}) or
258 the current process locale. Return two values (@pxref{Multiple
259 Values}): an inexact number (on success) or @code{#f}, and the number
260 of characters read from @var{str} (@code{0} on failure).
261
262 This function is based on the C library's @code{strtod} function
263 (@pxref{Parsing of Floats, @code{strtod},, libc, The GNU C Library
264 Reference Manual}).
265 @end deffn
266
267 @deffn {Scheme Procedure} number->locale-string number [fraction-digits [locale]]
268 Convert @var{number} (an inexact) into a string according to the
269 cultural conventions of either @var{locale} (a locale object) or the
270 current locale. Optionally, @var{fraction-digits} may be bound to an
271 integer specifying the number of fractional digits to be displayed.
272 @end deffn
273
274 @deffn {Scheme Procedure} monetary-amount->locale-string amount intl? [locale]
275 Convert @var{amount} (an inexact denoting a monetary amount) into a
276 string according to the cultural conventions of either @var{locale} (a
277 locale object) or the current locale. If @var{intl?} is true, then
278 the international monetary format for the given locale is used
279 (@pxref{Currency Symbol, international and locale monetary formats,,
280 libc, The GNU C Library Reference Manual}).
281 @end deffn
282
283
284 @node Accessing Locale Information, Gettext Support, Number Input and Output, Internationalization
285 @subsection Accessing Locale Information
286
287 @findex nl_langinfo
288 @cindex low-level locale information
289 It is sometimes useful to obtain very specific information about a
290 locale such as the word it uses for days or months, its format for
291 representing floating-point figures, etc. The @code{(ice-9 i18n)}
292 module provides support for this in a way that is similar to the libc
293 functions @code{nl_langinfo ()} and @code{localeconv ()}
294 (@pxref{Locale Information, accessing locale information from C,,
295 libc, The GNU C Library Reference Manual}). The available functions
296 are listed below.
297
298 @deffn {Scheme Procedure} locale-encoding [locale]
299 Return the name of the encoding (a string whose interpretation is
300 system-dependent) of either @var{locale} or the current locale.
301 @end deffn
302
303 The following functions deal with dates and times.
304
305 @deffn {Scheme Procedure} locale-day day [locale]
306 @deffnx {Scheme Procedure} locale-day-short day [locale]
307 @deffnx {Scheme Procedure} locale-month month [locale]
308 @deffnx {Scheme Procedure} locale-month-short month [locale]
309 Return the word (a string) used in either @var{locale} or the current
310 locale to name the day (or month) denoted by @var{day} (or
311 @var{month}), an integer between 1 and 7 (or 1 and 12). The
312 @code{-short} variants provide an abbreviation instead of a full name.
313 @end deffn
314
315 @deffn {Scheme Procedure} locale-am-string [locale]
316 @deffnx {Scheme Procedure} locale-pm-string [locale]
317 Return a (potentially empty) string that is used to denote @i{ante
318 meridiem} (or @i{post meridiem}) hours in 12-hour format.
319 @end deffn
320
321 @deffn {Scheme Procedure} locale-date+time-format [locale]
322 @deffnx {Scheme Procedure} locale-date-format [locale]
323 @deffnx {Scheme Procedure} locale-time-format [locale]
324 @deffnx {Scheme Procedure} locale-time+am/pm-format [locale]
325 @deffnx {Scheme Procedure} locale-era-date-format [locale]
326 @deffnx {Scheme Procedure} locale-era-date+time-format [locale]
327 @deffnx {Scheme Procedure} locale-era-time-format [locale]
328 These procedures return format strings suitable to @code{strftime}
329 (@pxref{Time}) that may be used to display (part of) a date/time
330 according to certain constraints and to the conventions of either
331 @var{locale} or the current locale (@pxref{The Elegant and Fast Way,
332 the @code{nl_langinfo ()} items,, libc, The GNU C Library Reference
333 Manual}).
334 @end deffn
335
336 @deffn {Scheme Procedure} locale-era [locale]
337 @deffnx {Scheme Procedure} locale-era-year [locale]
338 These functions return, respectively, the era and the year of the
339 relevant era used in @var{locale} or the current locale. Most locales
340 do not define this value. In this case, the empty string is returned.
341 An example of a locale that does define this value is the Japanese
342 one.
343 @end deffn
344
345 The following procedures give information about number representation.
346
347 @deffn {Scheme Procedure} locale-decimal-point [locale]
348 @deffnx {Scheme Procedure} locale-thousands-separator [locale]
349 These functions return a string denoting the representation of the
350 decimal point or that of the thousand separator (respectively) for
351 either @var{locale} or the current locale.
352 @end deffn
353
354 @deffn {Scheme Procedure} locale-digit-grouping [locale]
355 Return a (potentially circular) list of integers denoting how digits
356 of the integer part of a number are to be grouped, starting at the
357 decimal point and going to the left. The list contains integers
358 indicating the size of the successive groups, from right to left. If
359 the list is non-circular, then no grouping occurs for digits beyond
360 the last group.
361
362 For instance, if the returned list is a circular list that contains
363 only @code{3} and the thousand separator is @code{","} (as is the case
364 with English locales), then the number @code{12345678} should be
365 printed @code{12,345,678}.
366 @end deffn
367
368 The following procedures deal with the representation of monetary
369 amounts. Some of them take an additional @var{intl?} argument (a
370 boolean) that tells whether the international or local monetary
371 conventions for the given locale are to be used.
372
373 @deffn {Scheme Procedure} locale-monetary-decimal-point [locale]
374 @deffnx {Scheme Procedure} locale-monetary-thousands-separator [locale]
375 @deffnx {Scheme Procedure} locale-monetary-grouping [locale]
376 These are the monetary counterparts of the above procedures. These
377 procedures apply to monetary amounts.
378 @end deffn
379
380 @deffn {Scheme Procedure} locale-currency-symbol intl? [locale]
381 Return the currency symbol (a string) of either @var{locale} or the
382 current locale.
383
384 The following example illustrates the difference between the local and
385 international monetary formats:
386
387 @example
388 (define us (make-locale LC_MONETARY "en_US"))
389 (locale-currency-symbol #f us)
390 @result{} "-$"
391 (locale-currency-symbol #t us)
392 @result{} "USD "
393 @end example
394 @end deffn
395
396 @deffn {Scheme Procedure} locale-monetary-fractional-digits intl? [locale]
397 Return the number of fractional digits to be used when printing
398 monetary amounts according to either @var{locale} or the current
399 locale. If the locale does not specify it, then @code{#f} is
400 returned.
401 @end deffn
402
403 @deffn {Scheme Procedure} locale-currency-symbol-precedes-positive? intl? [locale]
404 @deffnx {Scheme Procedure} locale-currency-symbol-precedes-negative? intl? [locale]
405 @deffnx {Scheme Procedure} locale-positive-separated-by-space? intl? [locale]
406 @deffnx {Scheme Procedure} locale-negative-separated-by-space? intl? [locale]
407 These procedures return a boolean indicating whether the currency
408 symbol should precede a positive/negative number, and whether a
409 whitespace should be inserted between the currency symbol and a
410 positive/negative amount.
411 @end deffn
412
413 @deffn {Scheme Procedure} locale-monetary-positive-sign [locale]
414 @deffnx {Scheme Procedure} locale-monetary-negative-sign [locale]
415 Return a string denoting the positive (respectively negative) sign
416 that should be used when printing a monetary amount.
417 @end deffn
418
419 @deffn {Scheme Procedure} locale-positive-sign-position
420 @deffnx {Scheme Procedure} locale-negative-sign-position
421 These functions return a symbol telling where a sign of a
422 positive/negative monetary amount is to appear when printing it. The
423 possible values are:
424
425 @table @code
426 @item parenthesize
427 The currency symbol and quantity should be surrounded by parentheses.
428 @item sign-before
429 Print the sign string before the quantity and currency symbol.
430 @item sign-after
431 Print the sign string after the quantity and currency symbol.
432 @item sign-before-currency-symbol
433 Print the sign string right before the currency symbol.
434 @item sign-after-currency-symbol
435 Print the sign string right after the currency symbol.
436 @item unspecified
437 Unspecified. We recommend you print the sign after the currency
438 symbol.
439 @end table
440
441 @end deffn
442
443 Finally, the two following procedures may be helpful when programming
444 user interfaces:
445
446 @deffn {Scheme Procedure} locale-yes-regexp [locale]
447 @deffnx {Scheme Procedure} locale-no-regexp [locale]
448 Return a string that can be used as a regular expression to recognize
449 a positive (respectively, negative) response to a yes/no question.
450 For the C locale, the default values are typically @code{"^[yY]"} and
451 @code{"^[nN]"}, respectively.
452
453 Here is an example:
454
455 @example
456 (format #t "Does Guile rock?~%")
457 (let ((answer (read-line)))
458 (cond ((string-match (locale-yes-regexp) answer)
459 "Yes it does.")
460 ((string-match (locale-no-regexp) answer)
461 "No it doesn't.")
462 (else
463 "What do you mean?")))
464 @end example
465
466 For an internationalized yes/no string output, @code{gettext} should
467 be used (@pxref{Gettext Support}).
468 @end deffn
469
470 Example uses of some of these functions are the implementation of the
471 @code{number->locale-string} and @code{monetary-amount->locale-string}
472 procedures (@pxref{Number Input and Output}), as well as that the
473 SRFI-19 date and time conversion to/from strings (@pxref{SRFI-19}).
474
475
476 @node Gettext Support, , Accessing Locale Information, Internationalization
477 @subsection Gettext Support
478
479 Guile provides an interface to GNU @code{gettext} for translating
480 message strings (@pxref{Introduction,,, gettext, GNU @code{gettext}
481 utilities}).
482
483 Messages are collected in domains, so different libraries and programs
484 maintain different message catalogues. The @var{domain} parameter in
485 the functions below is a string (it becomes part of the message
486 catalog filename).
487
488 When @code{gettext} is not available, or if Guile was configured
489 @samp{--without-nls}, dummy functions doing no translation are
490 provided. When @code{gettext} support is available in Guile, the
491 @code{i18n} feature is provided (@pxref{Feature Tracking}).
492
493 @deffn {Scheme Procedure} gettext msg [domain [category]]
494 @deffnx {C Function} scm_gettext (msg, domain, category)
495 Return the translation of @var{msg} in @var{domain}. @var{domain} is
496 optional and defaults to the domain set through @code{textdomain}
497 below. @var{category} is optional and defaults to @code{LC_MESSAGES}
498 (@pxref{Locales}).
499
500 Normal usage is for @var{msg} to be a literal string.
501 @command{xgettext} can extract those from the source to form a message
502 catalogue ready for translators (@pxref{xgettext Invocation,, Invoking
503 the @command{xgettext} Program, gettext, GNU @code{gettext}
504 utilities}).
505
506 @example
507 (display (gettext "You are in a maze of twisty passages."))
508 @end example
509
510 @code{_} is a commonly used shorthand, an application can make that an
511 alias for @code{gettext}. Or a library can make a definition that
512 uses its specific @var{domain} (so an application can change the
513 default without affecting the library).
514
515 @example
516 (define (_ msg) (gettext msg "mylibrary"))
517 (display (_ "File not found."))
518 @end example
519
520 @code{_} is also a good place to perhaps strip disambiguating extra
521 text from the message string, as for instance in @ref{GUI program
522 problems,, How to use @code{gettext} in GUI programs, gettext, GNU
523 @code{gettext} utilities}.
524 @end deffn
525
526 @deffn {Scheme Procedure} ngettext msg msgplural n [domain [category]]
527 @deffnx {C Function} scm_ngettext (msg, msgplural, n, domain, category)
528 Return the translation of @var{msg}/@var{msgplural} in @var{domain},
529 with a plural form chosen appropriately for the number @var{n}.
530 @var{domain} is optional and defaults to the domain set through
531 @code{textdomain} below. @var{category} is optional and defaults to
532 @code{LC_MESSAGES} (@pxref{Locales}).
533
534 @var{msg} is the singular form, and @var{msgplural} the plural. When
535 no translation is available, @var{msg} is used if @math{@var{n} = 1},
536 or @var{msgplural} otherwise. When translated, the message catalogue
537 can have a different rule, and can have more than two possible forms.
538
539 As per @code{gettext} above, normal usage is for @var{msg} and
540 @var{msgplural} to be literal strings, since @command{xgettext} can
541 extract them from the source to build a message catalogue. For
542 example,
543
544 @example
545 (define (done n)
546 (format #t (ngettext "~a file processed\n"
547 "~a files processed\n" n)
548 n))
549
550 (done 1) @print{} 1 file processed
551 (done 3) @print{} 3 files processed
552 @end example
553
554 It's important to use @code{ngettext} rather than plain @code{gettext}
555 for plurals, since the rules for singular and plural forms in English
556 are not the same in other languages. Only @code{ngettext} will allow
557 translators to give correct forms (@pxref{Plural forms,, Additional
558 functions for plural forms, gettext, GNU @code{gettext} utilities}).
559 @end deffn
560
561 @deffn {Scheme Procedure} textdomain [domain]
562 @deffnx {C Function} scm_textdomain (domain)
563 Get or set the default gettext domain. When called with no parameter
564 the current domain is returned. When called with a parameter,
565 @var{domain} is set as the current domain, and that new value
566 returned. For example,
567
568 @example
569 (textdomain "myprog")
570 @result{} "myprog"
571 @end example
572 @end deffn
573
574 @deffn {Scheme Procedure} bindtextdomain domain [directory]
575 @deffnx {C Function} scm_bindtextdomain (domain, directory)
576 Get or set the directory under which to find message files for
577 @var{domain}. When called without a @var{directory} the current
578 setting is returned. When called with a @var{directory},
579 @var{directory} is set for @var{domain} and that new setting returned.
580 For example,
581
582 @example
583 (bindtextdomain "myprog" "/my/tree/share/locale")
584 @result{} "/my/tree/share/locale"
585 @end example
586
587 When using Autoconf/Automake, an application should arrange for the
588 configured @code{localedir} to get into the program (by substituting,
589 or by generating a config file) and set that for its domain. This
590 ensures the catalogue can be found even when installed in a
591 non-standard location.
592 @end deffn
593
594 @deffn {Scheme Procedure} bind-textdomain-codeset domain [encoding]
595 @deffnx {C Function} scm_bind_textdomain_codeset (domain, encoding)
596 Get or set the text encoding to be used by @code{gettext} for messages
597 from @var{domain}. @var{encoding} is a string, the name of a coding
598 system, for instance @nicode{"8859_1"}. (On a Unix/POSIX system the
599 @command{iconv} program can list all available encodings.)
600
601 When called without an @var{encoding} the current setting is returned,
602 or @code{#f} if none yet set. When called with an @var{encoding}, it
603 is set for @var{domain} and that new setting returned. For example,
604
605 @example
606 (bind-textdomain-codeset "myprog")
607 @result{} #f
608 (bind-textdomain-codeset "myprog" "latin-9")
609 @result{} "latin-9"
610 @end example
611
612 The encoding requested can be different from the translated data file,
613 messages will be recoded as necessary. But note that when there is no
614 translation, @code{gettext} returns its @var{msg} unchanged, ie.@:
615 without any recoding. For that reason source message strings are best
616 as plain ASCII.
617
618 Currently Guile has no understanding of multi-byte characters, and
619 string functions won't recognise character boundaries in multi-byte
620 strings. An application will at least be able to pass such strings
621 through to some output though. Perhaps this will change in the
622 future.
623 @end deffn
624
625 @c Local Variables:
626 @c TeX-master: "guile.texi"
627 @c ispell-local-dictionary: "american"
628 @c End: