1 /* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public License
5 * as published by the Free Software Foundation; either version 3 of
6 * the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include "libguile/_scm.h"
25 #include "libguile/feature.h"
26 #include "libguile/strings.h"
27 #include "libguile/dynwind.h"
29 #include "libguile/gettext.h"
30 #include "libgettext.h"
35 scm_i_to_lc_category (SCM category
, int allow_lc_all
)
37 int c_category
= scm_to_int (category
);
73 #ifdef LC_IDENTIFICATION
74 case LC_IDENTIFICATION
:
83 scm_wrong_type_arg (0, 0, category
);
86 SCM_DEFINE (scm_gettext
, "gettext", 1, 2, 0,
87 (SCM msgid
, SCM domain
, SCM category
),
88 "Return the translation of @var{msgid} in the message domain "
89 "@var{domain}. @var{domain} is optional and defaults to the "
90 "domain set through (textdomain). @var{category} is optional "
91 "and defaults to LC_MESSAGES.")
92 #define FUNC_NAME s_scm_gettext
98 scm_dynwind_begin (0);
100 c_msgid
= scm_to_locale_string (msgid
);
101 scm_dynwind_free (c_msgid
);
103 if (SCM_UNBNDP (domain
))
105 /* 1 argument case. */
106 c_result
= gettext (c_msgid
);
112 c_domain
= scm_to_locale_string (domain
);
113 scm_dynwind_free (c_domain
);
115 if (SCM_UNBNDP (category
))
117 /* 2 argument case. */
118 c_result
= dgettext (c_domain
, c_msgid
);
122 /* 3 argument case. */
125 c_category
= scm_i_to_lc_category (category
, 0);
126 c_result
= dcgettext (c_domain
, c_msgid
, c_category
);
130 if (c_result
== c_msgid
)
133 result
= scm_from_locale_string (c_result
);
141 SCM_DEFINE (scm_ngettext
, "ngettext", 3, 2, 0,
142 (SCM msgid
, SCM msgid_plural
, SCM n
, SCM domain
, SCM category
),
143 "Return the translation of @var{msgid}/@var{msgid_plural} in the "
144 "message domain @var{domain}, with the plural form being chosen "
145 "appropriately for the number @var{n}. @var{domain} is optional "
146 "and defaults to the domain set through (textdomain). "
147 "@var{category} is optional and defaults to LC_MESSAGES.")
148 #define FUNC_NAME s_scm_ngettext
151 char *c_msgid_plural
;
153 const char *c_result
;
156 scm_dynwind_begin (0);
158 c_msgid
= scm_to_locale_string (msgid
);
159 scm_dynwind_free (c_msgid
);
161 c_msgid_plural
= scm_to_locale_string (msgid_plural
);
162 scm_dynwind_free (c_msgid_plural
);
164 c_n
= scm_to_ulong (n
);
166 if (SCM_UNBNDP (domain
))
168 /* 3 argument case. */
169 c_result
= ngettext (c_msgid
, c_msgid_plural
, c_n
);
175 c_domain
= scm_to_locale_string (domain
);
176 scm_dynwind_free (c_domain
);
178 if (SCM_UNBNDP (category
))
180 /* 4 argument case. */
181 c_result
= dngettext (c_domain
, c_msgid
, c_msgid_plural
, c_n
);
185 /* 5 argument case. */
188 c_category
= scm_i_to_lc_category (category
, 0);
189 c_result
= dcngettext (c_domain
, c_msgid
, c_msgid_plural
, c_n
,
194 if (c_result
== c_msgid
)
196 else if (c_result
== c_msgid_plural
)
197 result
= msgid_plural
;
199 result
= scm_from_locale_string (c_result
);
206 SCM_DEFINE (scm_textdomain
, "textdomain", 0, 1, 0,
208 "If optional parameter @var{domainname} is supplied, "
209 "set the textdomain. "
210 "Return the textdomain.")
211 #define FUNC_NAME s_scm_textdomain
213 char const *c_result
;
215 SCM result
= SCM_BOOL_F
;
217 scm_dynwind_begin (0);
219 if (SCM_UNBNDP (domainname
))
223 c_domain
= scm_to_locale_string (domainname
);
224 scm_dynwind_free (c_domain
);
227 c_result
= textdomain (c_domain
);
228 if (c_result
!= NULL
)
229 result
= scm_from_locale_string (c_result
);
230 else if (!SCM_UNBNDP (domainname
))
238 SCM_DEFINE (scm_bindtextdomain
, "bindtextdomain", 1, 1, 0,
239 (SCM domainname
, SCM directory
),
240 "If optional parameter @var{directory} is supplied, "
241 "set message catalogs to directory @var{directory}. "
242 "Return the directory bound to @var{domainname}.")
243 #define FUNC_NAME s_scm_bindtextdomain
247 char const *c_result
;
250 scm_dynwind_begin (0);
252 if (SCM_UNBNDP (directory
))
256 c_directory
= scm_to_locale_string (directory
);
257 scm_dynwind_free (c_directory
);
260 c_domain
= scm_to_locale_string (domainname
);
261 scm_dynwind_free (c_domain
);
263 c_result
= bindtextdomain (c_domain
, c_directory
);
265 if (c_result
!= NULL
)
266 result
= scm_from_locale_string (c_result
);
267 else if (!SCM_UNBNDP (directory
))
277 SCM_DEFINE (scm_bind_textdomain_codeset
, "bind-textdomain-codeset", 1, 1, 0,
278 (SCM domainname
, SCM encoding
),
279 "If optional parameter @var{encoding} is supplied, "
280 "set encoding for message catalogs of @var{domainname}. "
281 "Return the encoding of @var{domainname}.")
282 #define FUNC_NAME s_scm_bind_textdomain_codeset
286 char const *c_result
;
289 scm_dynwind_begin (0);
291 if (SCM_UNBNDP (encoding
))
295 c_encoding
= scm_to_locale_string (encoding
);
296 scm_dynwind_free (c_encoding
);
299 c_domain
= scm_to_locale_string (domainname
);
300 scm_dynwind_free (c_domain
);
302 c_result
= bind_textdomain_codeset (c_domain
, c_encoding
);
304 if (c_result
!= NULL
)
305 result
= scm_from_locale_string (c_result
);
306 else if (!SCM_UNBNDP (encoding
))
319 /* When gettext support was first added (in 1.8.0), it provided feature
320 `i18n'. We keep this as is although the name is a bit misleading
322 scm_add_feature ("i18n");
324 #include "libguile/gettext.x"