1 /* Copyright (C) 2004, 2006, 2008 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
22 #include "libguile/_scm.h"
23 #include "libguile/feature.h"
24 #include "libguile/i18n.h"
25 #include "libguile/strings.h"
26 #include "libguile/dynwind.h"
33 scm_i_to_lc_category (SCM category, int allow_lc_all)
35 int c_category = scm_to_int (category);
71 #ifdef LC_IDENTIFICATION
72 case LC_IDENTIFICATION:
81 scm_wrong_type_arg (0, 0, category);
84 SCM_DEFINE (scm_gettext, "gettext", 1, 2, 0,
85 (SCM msgid, SCM domain, SCM category),
86 "Return the translation of @var{msgid} in the message domain "
87 "@var{domain}. @var{domain} is optional and defaults to the "
88 "domain set through (textdomain). @var{category} is optional "
89 "and defaults to LC_MESSAGES.")
90 #define FUNC_NAME s_scm_gettext
96 scm_dynwind_begin (0);
98 c_msgid = scm_to_locale_string (msgid);
99 scm_dynwind_free (c_msgid);
101 if (SCM_UNBNDP (domain))
103 /* 1 argument case. */
104 c_result = gettext (c_msgid);
110 c_domain = scm_to_locale_string (domain);
111 scm_dynwind_free (c_domain);
113 if (SCM_UNBNDP (category))
115 /* 2 argument case. */
116 c_result = dgettext (c_domain, c_msgid);
120 /* 3 argument case. */
123 c_category = scm_i_to_lc_category (category, 0);
124 c_result = dcgettext (c_domain, c_msgid, c_category);
128 if (c_result == c_msgid)
131 result = scm_from_locale_string (c_result);
139 SCM_DEFINE (scm_ngettext, "ngettext", 3, 2, 0,
140 (SCM msgid, SCM msgid_plural, SCM n, SCM domain, SCM category),
141 "Return the translation of @var{msgid}/@var{msgid_plural} in the "
142 "message domain @var{domain}, with the plural form being chosen "
143 "appropriately for the number @var{n}. @var{domain} is optional "
144 "and defaults to the domain set through (textdomain). "
145 "@var{category} is optional and defaults to LC_MESSAGES.")
146 #define FUNC_NAME s_scm_ngettext
149 char *c_msgid_plural;
151 const char *c_result;
154 scm_dynwind_begin (0);
156 c_msgid = scm_to_locale_string (msgid);
157 scm_dynwind_free (c_msgid);
159 c_msgid_plural = scm_to_locale_string (msgid_plural);
160 scm_dynwind_free (c_msgid_plural);
162 c_n = scm_to_ulong (n);
164 if (SCM_UNBNDP (domain))
166 /* 3 argument case. */
167 c_result = ngettext (c_msgid, c_msgid_plural, c_n);
173 c_domain = scm_to_locale_string (domain);
174 scm_dynwind_free (c_domain);
176 if (SCM_UNBNDP (category))
178 /* 4 argument case. */
179 c_result = dngettext (c_domain, c_msgid, c_msgid_plural, c_n);
183 /* 5 argument case. */
186 c_category = scm_i_to_lc_category (category, 0);
187 c_result = dcngettext (c_domain, c_msgid, c_msgid_plural, c_n,
192 if (c_result == c_msgid)
194 else if (c_result == c_msgid_plural)
195 result = msgid_plural;
197 result = scm_from_locale_string (c_result);
204 SCM_DEFINE (scm_textdomain, "textdomain", 0, 1, 0,
206 "If optional parameter @var{domainname} is supplied, "
207 "set the textdomain. "
208 "Return the textdomain.")
209 #define FUNC_NAME s_scm_textdomain
211 char const *c_result;
213 SCM result = SCM_BOOL_F;
215 scm_dynwind_begin (0);
217 if (SCM_UNBNDP (domainname))
221 c_domain = scm_to_locale_string (domainname);
222 scm_dynwind_free (c_domain);
225 c_result = textdomain (c_domain);
226 if (c_result != NULL)
227 result = scm_from_locale_string (c_result);
228 else if (!SCM_UNBNDP (domainname))
236 SCM_DEFINE (scm_bindtextdomain, "bindtextdomain", 1, 1, 0,
237 (SCM domainname, SCM directory),
238 "If optional parameter @var{directory} is supplied, "
239 "set message catalogs to directory @var{directory}. "
240 "Return the directory bound to @var{domainname}.")
241 #define FUNC_NAME s_scm_bindtextdomain
245 char const *c_result;
248 scm_dynwind_begin (0);
250 if (SCM_UNBNDP (directory))
254 c_directory = scm_to_locale_string (directory);
255 scm_dynwind_free (c_directory);
258 c_domain = scm_to_locale_string (domainname);
259 scm_dynwind_free (c_domain);
261 c_result = bindtextdomain (c_domain, c_directory);
263 if (c_result != NULL)
264 result = scm_from_locale_string (c_result);
265 else if (!SCM_UNBNDP (directory))
275 SCM_DEFINE (scm_bind_textdomain_codeset, "bind-textdomain-codeset", 1, 1, 0,
276 (SCM domainname, SCM encoding),
277 "If optional parameter @var{encoding} is supplied, "
278 "set encoding for message catalogs of @var{domainname}. "
279 "Return the encoding of @var{domainname}.")
280 #define FUNC_NAME s_scm_bind_textdomain_codeset
284 char const *c_result;
287 scm_dynwind_begin (0);
289 if (SCM_UNBNDP (encoding))
293 c_encoding = scm_to_locale_string (encoding);
294 scm_dynwind_free (c_encoding);
297 c_domain = scm_to_locale_string (domainname);
298 scm_dynwind_free (c_domain);
300 c_result = bind_textdomain_codeset (c_domain, c_encoding);
302 if (c_result != NULL)
303 result = scm_from_locale_string (c_result);
304 else if (!SCM_UNBNDP (encoding))
317 scm_add_feature ("i18n");
318 #include "libguile/i18n.x"