From 769c1d5fa940e70ddb8ac55e8dd5ed8f05ab7e6e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 17 Jul 2009 19:04:51 +0200 Subject: python/apt_pkgmodule.cc: Introduce apt_pkg.gettext(). Python's gettext() ignores setlocale() which causes a strange behavior because the values received from apt-pkg respect setlocale(). We circumvent this problem by calling the C version of gettext(). This is also much faster. --- python/apt_pkgmodule.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'python') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index a7392f58..d6b8e3d1 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -24,10 +24,29 @@ #include #include +#include #include #include /*}}}*/ + +/** + * A Python->C->Python gettext() function. + * + * Python's gettext() ignores setlocale() which causes a strange behavior + * because the values received from apt-pkg respect setlocale(). We circumvent + * this problem by calling the C version of gettext(). This is also much + * faster. + */ +static PyObject *py_gettext(PyObject *self, PyObject *Args) { + const char *msg; + char *domain = "python-apt"; + if (PyArg_ParseTuple(Args,"s|s:gettext",&msg) == 0) + return 0; + + return PyString_FromString(dgettext(domain, msg)); +} + // newConfiguration - Build a new configuration class /*{{{*/ // --------------------------------------------------------------------- #ifdef COMPAT_0_7 @@ -405,6 +424,12 @@ static PyMethodDef methods[] = {"init_config",InitConfig,METH_VARARGS,doc_InitConfig}, {"init_system",InitSystem,METH_VARARGS,doc_InitSystem}, + // Internationalization. + {"gettext",py_gettext,METH_VARARGS, + "gettext(msg: str[, domain: str = 'python-apt']) -> str\n\n" + "Translate the given string. Much Faster than Python's version and only\n" + "does translations after setlocale() has been called."}, + // Tag File {"rewrite_section",RewriteSection,METH_VARARGS,doc_RewriteSection}, -- cgit v1.2.3