diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-03-08 18:09:19 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2004-03-08 18:09:19 +0000 |
commit | a527ee4fe42cbcd4b54cf1e643d3f8f1d7df39c3 (patch) | |
tree | 2ffee327a7d3e773e94b73f58c4a68bd896a4ec3 /src | |
parent | dcda71fbaac3620758797565a3345ff28e48cfb9 (diff) | |
download | gamma-a527ee4fe42cbcd4b54cf1e643d3f8f1d7df39c3.tar.gz gamma-a527ee4fe42cbcd4b54cf1e643d3f8f1d7df39c3.tar.bz2 |
Initial revision
Diffstat (limited to 'src')
-rw-r--r-- | src/gettext.c | 136 | ||||
-rw-r--r-- | src/gettext.h | 69 |
2 files changed, 205 insertions, 0 deletions
diff --git a/src/gettext.c b/src/gettext.c new file mode 100644 index 0000000..5534165 --- /dev/null +++ b/src/gettext.c @@ -0,0 +1,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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 +} diff --git a/src/gettext.h b/src/gettext.h new file mode 100644 index 0000000..8b262f4 --- /dev/null +++ b/src/gettext.h @@ -0,0 +1,69 @@ +/* Convenience header for conditional use of GNU <libintl.h>. + Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include <libintl.h> + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of <locale.h> a NOP. We don't include <libintl.h> + as well because people using "gettext.h" will not include <libintl.h>, + and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> + is OK. */ +#if defined(__sun) +# include <locale.h> +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# define gettext(Msgid) ((const char *) (Msgid)) +# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) +# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define textdomain(Domainname) ((const char *) (Domainname)) +# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) +# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +#endif /* _LIBGETTEXT_H */ |