diff options
author | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-05-30 15:03:16 +0400 |
---|---|---|
committer | Xiao Xiangquan <xiaoxiangquan@gmail.com> | 2011-05-30 15:03:16 +0400 |
commit | 0fc21dde4e0b1bc1188f2bf9024125fcbaec03ee (patch) | |
tree | 64ffe3c259ebbe934af8ed1e4e3a72d7fe192c0b /source | |
parent | 682a5acd03959e5ed8ac4ff7b4b02435df19f50d (diff) |
Add BLF_gettext(msgid) for C, and blf.gettext(msgid) for Python.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 2 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 6 | ||||
-rw-r--r-- | source/blender/python/generic/blf_py_api.c | 25 |
3 files changed, 33 insertions, 0 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 57f8c83eda6..79c8c3b9a1a 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -41,6 +41,8 @@ void BLF_exit(void); void BLF_cache_clear(void); +char* BLF_gettext(const char *msgid); + int BLF_load(const char *name); int BLF_load_mem(const char *name, unsigned char *mem, int mem_size); diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index c0e62b1c0c7..1d2ac298af4 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -37,6 +37,7 @@ #include <math.h> #include <ft2build.h> +#include <libintl.h> #include FT_FREETYPE_H #include FT_GLYPH_H @@ -120,6 +121,11 @@ void BLF_cache_clear(void) } } +char* BLF_gettext(const char *msgid) +{ + return gettext( msgid ); +} + static int blf_search(const char *name) { FontBLF *font; diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 3cf0b0f1f27..f7b49ad28dc 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -367,6 +367,30 @@ static PyObject *py_blf_load(PyObject *UNUSED(self), PyObject *args) return PyLong_FromLong(BLF_load(filename)); } +PyDoc_STRVAR(py_blf_gettext_doc, +".. function:: gettext(msgid)\n" +"\n" +" Get a msg in local language.\n" +"\n" +" :arg msgid: the source string.\n" +" :type msgid: string\n" +" :return: the localized string.\n" +" :rtype: string\n" +); +static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *args) +{ + char* msgid; + char* msgstr; + char* error_handle; + + if (!PyArg_ParseTuple(args, "s:blf.gettext", &msgid)) + return NULL; + + msgstr = BLF_gettext( msgid ); + + return PyUnicode_DecodeUTF8( msgstr, strlen(msgstr), error_handle ); +} + /*----------------------------MODULE INIT-------------------------*/ static PyMethodDef BLF_methods[] = { {"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc}, @@ -382,6 +406,7 @@ static PyMethodDef BLF_methods[] = { {"shadow_offset", (PyCFunction) py_blf_shadow_offset, METH_VARARGS, py_blf_shadow_offset_doc}, {"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc}, {"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc}, + {"gettext", (PyCFunction) py_blf_gettext, METH_VARARGS, py_blf_gettext_doc}, {NULL, NULL, 0, NULL} }; |