@@ -21,6 +21,10 @@ This software comes with no warranty. Use at your own risk.
2121#include <langinfo.h>
2222#endif
2323
24+ #ifdef HAVE_LIBINTL_H
25+ #include <libintl.h>
26+ #endif
27+
2428#if defined(MS_WIN32 )
2529#define WINDOWS_LEAN_AND_MEAN
2630#include <windows.h>
@@ -521,7 +525,86 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
521525 return NULL ;
522526}
523527#endif /* HAVE_LANGINFO_H */
524-
528+
529+ #ifdef HAVE_LIBINTL_H
530+
531+ static char gettext__doc__ []=
532+ "gettext(msg) -> string\n"
533+ "Return translation of msg." ;
534+
535+ static PyObject *
536+ PyIntl_gettext (PyObject * self , PyObject * args )
537+ {
538+ char * in ;
539+ if (!PyArg_ParseTuple (args , "z" , & in ))
540+ return 0 ;
541+ return PyString_FromString (gettext (in ));
542+ }
543+
544+ static char dgettext__doc__ []=
545+ "dgettext(domain, msg) -> string\n"
546+ "Return translation of msg in domain." ;
547+
548+ static PyObject *
549+ PyIntl_dgettext (PyObject * self , PyObject * args )
550+ {
551+ char * domain , * in ;
552+ if (!PyArg_ParseTuple (args , "zz" , & domain , & in ))
553+ return 0 ;
554+ return PyString_FromString (dgettext (domain , in ));
555+ }
556+
557+ static char dcgettext__doc__ []=
558+ "dcgettext(domain, msg, category) -> string\n"
559+ "Return translation of msg in domain and category." ;
560+
561+ static PyObject *
562+ PyIntl_dcgettext (PyObject * self , PyObject * args )
563+ {
564+ char * domain , * msgid ;
565+ int category ;
566+ if (!PyArg_ParseTuple (args , "zzi" , & domain , & msgid , & category ))
567+ return 0 ;
568+ return PyString_FromString (dcgettext (domain ,msgid ,category ));
569+ }
570+
571+ static char textdomain__doc__ []=
572+ "textdomain(domain) -> string\n"
573+ "Set the C library's textdmain to domain, returning the new domain." ;
574+
575+ static PyObject *
576+ PyIntl_textdomain (PyObject * self , PyObject * args )
577+ {
578+ char * domain ;
579+ if (!PyArg_ParseTuple (args , "z" , & domain ))
580+ return 0 ;
581+ domain = textdomain (domain );
582+ if (!domain ) {
583+ PyErr_SetFromErrno (PyExc_OSError );
584+ return NULL ;
585+ }
586+ return PyString_FromString (domain );
587+ }
588+
589+ static char bindtextdomain__doc__ []=
590+ "bindtextdomain(domain, dir) -> string\n"
591+ "Bind the C library's domain to dir." ;
592+
593+ static PyObject *
594+ PyIntl_bindtextdomain (PyObject * self ,PyObject * args )
595+ {
596+ char * domain ,* dirname ;
597+ if (!PyArg_ParseTuple (args , "zz" , & domain , & dirname ))
598+ return 0 ;
599+ dirname = bindtextdomain (domain , dirname );
600+ if (!dirname ) {
601+ PyErr_SetFromErrno (PyExc_OSError );
602+ return NULL ;
603+ }
604+ return PyString_FromString (dirname );
605+ }
606+
607+ #endif
525608
526609static struct PyMethodDef PyLocale_Methods [] = {
527610 {"setlocale" , (PyCFunction ) PyLocale_setlocale ,
@@ -539,7 +622,18 @@ static struct PyMethodDef PyLocale_Methods[] = {
539622 {"nl_langinfo" , (PyCFunction ) PyLocale_nl_langinfo ,
540623 METH_VARARGS , nl_langinfo__doc__ },
541624#endif
542-
625+ #ifdef HAVE_LANGINFO_H
626+ {"gettext" ,(PyCFunction )PyIntl_gettext ,METH_VARARGS ,
627+ gettext__doc__ },
628+ {"dgettext" ,(PyCFunction )PyIntl_dgettext ,METH_VARARGS ,
629+ dgettext__doc__ },
630+ {"dcgettext" ,(PyCFunction )PyIntl_dcgettext ,METH_VARARGS ,
631+ dcgettext__doc__ },
632+ {"textdomain" ,(PyCFunction )PyIntl_textdomain ,METH_VARARGS ,
633+ textdomain__doc__ },
634+ {"bindtextdomain" ,(PyCFunction )PyIntl_bindtextdomain ,METH_VARARGS ,
635+ bindtextdomain__doc__ },
636+ #endif
543637 {NULL , NULL }
544638};
545639
0 commit comments