diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-07-17 19:04:51 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-07-17 19:04:51 +0200 |
| commit | 769c1d5fa940e70ddb8ac55e8dd5ed8f05ab7e6e (patch) | |
| tree | 44da0df24475f5d94c33a78a3aca0933c8192406 | |
| parent | db6032394c794c6bbe59675bb38802d208d993cb (diff) | |
| download | python-apt-769c1d5fa940e70ddb8ac55e8dd5ed8f05ab7e6e.tar.gz | |
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.
| -rw-r--r-- | python/apt_pkgmodule.cc | 25 |
1 files changed, 25 insertions, 0 deletions
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 <apt-pkg/pkgsystem.h> #include <sys/stat.h> +#include <libintl.h> #include <unistd.h> #include <Python.h> /*}}}*/ + +/** + * 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}, |
