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
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but 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 02110-1301 USA
23 #include "libguile/_scm.h"
24 #include "libguile/feature.h"
25 #include "libguile/strings.h"
26 #include "libguile/dynwind.h"
28 #include "libguile/gettext.h"
29 #include "libgettext.h"
34 scm_i_to_lc_category (SCM category
, int allow_lc_all
)
36 int c_category
= scm_to_int (category
);
72 #ifdef LC_IDENTIFICATION
73 case LC_IDENTIFICATION
:
82 scm_wrong_type_arg (0, 0, category
);
85 SCM_DEFINE (scm_gettext
, "gettext", 1, 2, 0,
86 (SCM msgid
, SCM domain
, SCM category
),
87 "Return the translation of @var{msgid} in the message domain "
88 "@var{domain}. @var{domain} is optional and defaults to the "
89 "domain set through (textdomain). @var{category} is optional "
90 "and defaults to LC_MESSAGES.")
91 #define FUNC_NAME s_scm_gettext
97 scm_dynwind_begin (0);
99 c_msgid
= scm_to_locale_string (msgid
);
100 scm_dynwind_free (c_msgid
);
102 if (SCM_UNBNDP (domain
))
104 /* 1 argument case. */
105 c_result
= gettext (c_msgid
);
111 c_domain
= scm_to_locale_string (domain
);
112 scm_dynwind_free (c_domain
);
114 if (SCM_UNBNDP (category
))
116 /* 2 argument case. */
117 c_result
= dgettext (c_domain
, c_msgid
);
121 /* 3 argument case. */
124 c_category
= scm_i_to_lc_category (category
, 0);
125 c_result
= dcgettext (c_domain
, c_msgid
, c_category
);
129 if (c_result
== c_msgid
)
132 result
= scm_from_locale_string (c_result
);
140 SCM_DEFINE (scm_ngettext
, "ngettext", 3, 2, 0,
141 (SCM msgid
, SCM msgid_plural
, SCM n
, SCM domain
, SCM category
),
142 "Return the translation of @var{msgid}/@var{msgid_plural} in the "
143 "message domain @var{domain}, with the plural form being chosen "
144 "appropriately for the number @var{n}. @var{domain} is optional "
145 "and defaults to the domain set through (textdomain). "
146 "@var{category} is optional and defaults to LC_MESSAGES.")
147 #define FUNC_NAME s_scm_ngettext
150 char *c_msgid_plural
;
152 const char *c_result
;
155 scm_dynwind_begin (0);
157 c_msgid
= scm_to_locale_string (msgid
);
158 scm_dynwind_free (c_msgid
);
160 c_msgid_plural
= scm_to_locale_string (msgid_plural
);
161 scm_dynwind_free (c_msgid_plural
);
163 c_n
= scm_to_ulong (n
);
165 if (SCM_UNBNDP (domain
))
167 /* 3 argument case. */
168 c_result
= ngettext (c_msgid
, c_msgid_plural
, c_n
);
174 c_domain
= scm_to_locale_string (domain
);
175 scm_dynwind_free (c_domain
);
177 if (SCM_UNBNDP (category
))
179 /* 4 argument case. */
180 c_result
= dngettext (c_domain
, c_msgid
, c_msgid_plural
, c_n
);
184 /* 5 argument case. */
187 c_category
= scm_i_to_lc_category (category
, 0);
188 c_result
= dcngettext (c_domain
, c_msgid
, c_msgid_plural
, c_n
,
193 if (c_result
== c_msgid
)
195 else if (c_result
== c_msgid_plural
)
196 result
= msgid_plural
;
198 result
= scm_from_locale_string (c_result
);
205 SCM_DEFINE (scm_textdomain
, "textdomain", 0, 1, 0,
207 "If optional parameter @var{domainname} is supplied, "
208 "set the textdomain. "
209 "Return the textdomain.")
210 #define FUNC_NAME s_scm_textdomain
212 char const *c_result
;
214 SCM result
= SCM_BOOL_F
;
216 scm_dynwind_begin (0);
218 if (SCM_UNBNDP (domainname
))
222 c_domain
= scm_to_locale_string (domainname
);
223 scm_dynwind_free (c_domain
);
226 c_result
= textdomain (c_domain
);
227 if (c_result
!= NULL
)
228 result
= scm_from_locale_string (c_result
);
229 else if (!SCM_UNBNDP (domainname
))
237 SCM_DEFINE (scm_bindtextdomain
, "bindtextdomain", 1, 1, 0,
238 (SCM domainname
, SCM directory
),
239 "If optional parameter @var{directory} is supplied, "
240 "set message catalogs to directory @var{directory}. "
241 "Return the directory bound to @var{domainname}.")
242 #define FUNC_NAME s_scm_bindtextdomain
246 char const *c_result
;
249 scm_dynwind_begin (0);
251 if (SCM_UNBNDP (directory
))
255 c_directory
= scm_to_locale_string (directory
);
256 scm_dynwind_free (c_directory
);
259 c_domain
= scm_to_locale_string (domainname
);
260 scm_dynwind_free (c_domain
);
262 c_result
= bindtextdomain (c_domain
, c_directory
);
264 if (c_result
!= NULL
)
265 result
= scm_from_locale_string (c_result
);
266 else if (!SCM_UNBNDP (directory
))
276 SCM_DEFINE (scm_bind_textdomain_codeset
, "bind-textdomain-codeset", 1, 1, 0,
277 (SCM domainname
, SCM encoding
),
278 "If optional parameter @var{encoding} is supplied, "
279 "set encoding for message catalogs of @var{domainname}. "
280 "Return the encoding of @var{domainname}.")
281 #define FUNC_NAME s_scm_bind_textdomain_codeset
285 char const *c_result
;
288 scm_dynwind_begin (0);
290 if (SCM_UNBNDP (encoding
))
294 c_encoding
= scm_to_locale_string (encoding
);
295 scm_dynwind_free (c_encoding
);
298 c_domain
= scm_to_locale_string (domainname
);
299 scm_dynwind_free (c_domain
);
301 c_result
= bind_textdomain_codeset (c_domain
, c_encoding
);
303 if (c_result
!= NULL
)
304 result
= scm_from_locale_string (c_result
);
305 else if (!SCM_UNBNDP (encoding
))
318 /* When gettext support was first added (in 1.8.0), it provided feature
319 `i18n'. We keep this as is although the name is a bit misleading
321 scm_add_feature ("i18n");
323 #include "libguile/gettext.x"