summaryrefslogtreecommitdiffstats
path: root/Modules/_localemodule.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-03-27 18:49:02 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-03-27 18:49:02 (GMT)
commit2e64c3485021ec8c8e2dfc51f1c93d349ab7d3ba (patch)
tree7c419b12c47308f04699f7988714a84a3b81e011 /Modules/_localemodule.c
parent4208d4f7574bef6cfd78e242a83aedd12442c812 (diff)
downloadcpython-2e64c3485021ec8c8e2dfc51f1c93d349ab7d3ba.zip
cpython-2e64c3485021ec8c8e2dfc51f1c93d349ab7d3ba.tar.gz
cpython-2e64c3485021ec8c8e2dfc51f1c93d349ab7d3ba.tar.bz2
Expose C library's gettext. Fixes #516412.
Diffstat (limited to 'Modules/_localemodule.c')
-rw-r--r--Modules/_localemodule.c98
1 files changed, 96 insertions, 2 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c
index e72999c..58d349b 100644
--- a/Modules/_localemodule.c
+++ b/Modules/_localemodule.c
@@ -21,6 +21,10 @@ This software comes with no warranty. Use at your own risk.
#include <langinfo.h>
#endif
+#ifdef HAVE_LIBINTL_H
+#include <libintl.h>
+#endif
+
#if defined(MS_WIN32)
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
@@ -521,7 +525,86 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
return NULL;
}
#endif /* HAVE_LANGINFO_H */
-
+
+#ifdef HAVE_LIBINTL_H
+
+static char gettext__doc__[]=
+"gettext(msg) -> string\n"
+"Return translation of msg.";
+
+static PyObject*
+PyIntl_gettext(PyObject* self, PyObject *args)
+{
+ char *in;
+ if (!PyArg_ParseTuple(args, "z", &in))
+ return 0;
+ return PyString_FromString(gettext(in));
+}
+
+static char dgettext__doc__[]=
+"dgettext(domain, msg) -> string\n"
+"Return translation of msg in domain.";
+
+static PyObject*
+PyIntl_dgettext(PyObject* self, PyObject *args)
+{
+ char *domain, *in;
+ if (!PyArg_ParseTuple(args, "zz", &domain, &in))
+ return 0;
+ return PyString_FromString(dgettext(domain, in));
+}
+
+static char dcgettext__doc__[]=
+"dcgettext(domain, msg, category) -> string\n"
+"Return translation of msg in domain and category.";
+
+static PyObject*
+PyIntl_dcgettext(PyObject *self, PyObject *args)
+{
+ char *domain, *msgid;
+ int category;
+ if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
+ return 0;
+ return PyString_FromString(dcgettext(domain,msgid,category));
+}
+
+static char textdomain__doc__[]=
+"textdomain(domain) -> string\n"
+"Set the C library's textdmain to domain, returning the new domain.";
+
+static PyObject*
+PyIntl_textdomain(PyObject* self, PyObject* args)
+{
+ char *domain;
+ if (!PyArg_ParseTuple(args, "z", &domain))
+ return 0;
+ domain = textdomain(domain);
+ if (!domain) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+ return PyString_FromString(domain);
+}
+
+static char bindtextdomain__doc__[]=
+"bindtextdomain(domain, dir) -> string\n"
+"Bind the C library's domain to dir.";
+
+static PyObject*
+PyIntl_bindtextdomain(PyObject* self,PyObject*args)
+{
+ char *domain,*dirname;
+ if (!PyArg_ParseTuple(args, "zz", &domain, &dirname))
+ return 0;
+ dirname = bindtextdomain(domain, dirname);
+ if (!dirname) {
+ PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
+ }
+ return PyString_FromString(dirname);
+}
+
+#endif
static struct PyMethodDef PyLocale_Methods[] = {
{"setlocale", (PyCFunction) PyLocale_setlocale,
@@ -539,7 +622,18 @@ static struct PyMethodDef PyLocale_Methods[] = {
{"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
METH_VARARGS, nl_langinfo__doc__},
#endif
-
+#ifdef HAVE_LANGINFO_H
+ {"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
+ gettext__doc__},
+ {"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
+ dgettext__doc__},
+ {"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
+ dcgettext__doc__},
+ {"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
+ textdomain__doc__},
+ {"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
+ bindtextdomain__doc__},
+#endif
{NULL, NULL}
};