aboutsummaryrefslogtreecommitdiff
path: root/src/gettext.c
blob: 9dcaf1c754ee717fe851a1d6d1a927335b0cbb28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* This file is part of gettext interface for guile.
   Copyright (C) 2004 Sergey Poznyakoff

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gettext.h>
#include <libguile.h>
#include <locale.h>

SCM_DEFINE (scm_bindtextdomain, "bindtextdomain", 2, 0, 0,
	    (SCM PACKAGENAME, SCM LOCALEDIR),
	    "")
#define FUNC_NAME s_scm_bindtextdomain
{
	SCM_ASSERT(SCM_STRINGP(PACKAGENAME), PACKAGENAME, SCM_ARG1, FUNC_NAME);
	SCM_ASSERT(SCM_STRINGP(LOCALEDIR), LOCALEDIR, SCM_ARG2, FUNC_NAME);
	bindtextdomain(SCM_CHARS(PACKAGENAME), SCM_CHARS(LOCALEDIR));
	return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

SCM_DEFINE (scm_bind_textdomain_codeset, "bind_textdomain_codeset", 1, 1, 0,
	    (SCM DOMAINNAME, SCM CODESET),
	    "")
#define FUNC_NAME s_scm_bind_textdomain_codeset
{
	char *codeset;
	
	SCM_ASSERT(SCM_STRINGP(DOMAINNAME), DOMAINNAME, SCM_ARG1, FUNC_NAME);
	if (SCM_UNBNDP(CODESET))
		codeset = NULL;
	else {
		SCM_ASSERT(SCM_STRINGP(CODESET), CODESET, SCM_ARG2, FUNC_NAME);
		codeset = SCM_CHARS(CODESET);
	}
	return scm_makfrom0str(bind_textdomain_codeset(SCM_CHARS(DOMAINNAME),
						       codeset));
}
#undef FUNC_NAME


SCM_DEFINE (scm_textdomain, "textdomain", 1, 0, 0,
	    (SCM PACKAGENAME),
	    "")
#define FUNC_NAME s_scm_bindtextdomain
{
	SCM_ASSERT(SCM_STRINGP(PACKAGENAME), PACKAGENAME, SCM_ARG1, FUNC_NAME);
	textdomain(SCM_CHARS(PACKAGENAME));
	return SCM_UNSPECIFIED;
}
#undef FUNC_NAME

SCM_DEFINE (scm_gettext, "gettext", 1, 0, 0,
	    (SCM STRING),
	    "Return a translation of the given string.")
#define FUNC_NAME s_scm_gettext
{
	SCM_ASSERT(SCM_STRINGP(STRING), STRING, SCM_ARG1, FUNC_NAME);
	return scm_makfrom0str(gettext(SCM_CHARS(STRING)));
}
#undef FUNC_NAME

SCM_DEFINE (scm_dgettext, "dgettext", 2, 0, 0,
	    (SCM DOMAIN, SCM STRING),
	    "Return a translation of the given string within the given domain.")
#define FUNC_NAME s_scm_dgettext
{
	SCM_ASSERT(SCM_STRINGP(DOMAIN), DOMAIN, SCM_ARG1, FUNC_NAME);
	SCM_ASSERT(SCM_STRINGP(STRING), STRING, SCM_ARG2, FUNC_NAME);
	return scm_makfrom0str(dgettext(SCM_CHARS(DOMAIN), SCM_CHARS(STRING)));
}
#undef FUNC_NAME

SCM_DEFINE (scm_ngettext, "ngettext", 3, 0, 0,
	    (SCM MSGID1, SCM MSGID2, SCM N),
	    "The `ngettext' function is used to translate messages that "
	    "have singular and plural forms. The MSGID1 parameter must "
	    "contain the singular form of the string to be converted. It is "
	    "also used as the key for the search in the catalog. The "
	    "MSGID2 parameter is the plural form.  The parameter N "
	    "is used to determine the plural form. If no message catalog is "
	    "found MSGID1 is returned if `N == 1', otherwise MSGID2.")
#define FUNC_NAME s_scm_ngettext
{
	SCM_ASSERT(SCM_STRINGP(MSGID1), MSGID1, SCM_ARG1, FUNC_NAME);
	SCM_ASSERT(SCM_STRINGP(MSGID2), MSGID2, SCM_ARG2, FUNC_NAME);
	SCM_ASSERT(SCM_IMP(N) && SCM_INUMP(N), N, SCM_ARG3, FUNC_NAME);
	return scm_makfrom0str(ngettext(SCM_CHARS(MSGID1), SCM_CHARS(MSGID2),
					SCM_INUM(N)));
}
#undef FUNC_NAME

SCM_DEFINE (scm_dngettext, "dngettext", 4, 0, 0,
	    (SCM DOMAIN, SCM MSGID1, SCM MSGID2, SCM N),
	    "The `dngettext' function is used to translate messages that "
	    "have singular and plural forms. The MSGID1 parameter must "
	    "contain the singular form of the string to be converted. It is "
	    "also used as the key for the search in the catalog. The "
	    "MSGID2 parameter is the plural form.  The parameter N "
	    "is used to determine the plural form. If no message catalog is "
	    "found MSGID1 is returned if `N == 1', otherwise MSGID2.")
#define FUNC_NAME s_scm_dngettext
{
	SCM_ASSERT(SCM_STRINGP(DOMAIN), DOMAIN, SCM_ARG1, FUNC_NAME);
	SCM_ASSERT(SCM_STRINGP(MSGID1), MSGID1, SCM_ARG2, FUNC_NAME);
	SCM_ASSERT(SCM_STRINGP(MSGID2), MSGID2, SCM_ARG3, FUNC_NAME);
	SCM_ASSERT(SCM_IMP(N) && SCM_INUMP(N), N, SCM_ARG4, FUNC_NAME);
	return scm_makfrom0str(dngettext(SCM_CHARS(DOMAIN),
					 SCM_CHARS(MSGID1),
					 SCM_CHARS(MSGID2),
					 SCM_INUM(N)));
}
#undef FUNC_NAME

extern void
gettext_init()
{
#ifndef SCM_MAGIC_SNARFER
# include <gettext.x>
#endif
}

Return to:

Send suggestions and report system problems to the System administrator.