[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [37021] branches/soc-2011-garlic/source/ blender: Add BLF_gettext(msgid) for C, and blf.gettext(msgid) for Python.

xiao xiangquan xiaoxiangquan at gmail.com
Mon May 30 13:03:17 CEST 2011


Revision: 37021
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37021
Author:   xiaoxiangquan
Date:     2011-05-30 11:03:16 +0000 (Mon, 30 May 2011)
Log Message:
-----------
Add BLF_gettext(msgid) for C, and blf.gettext(msgid) for Python.

Modified Paths:
--------------
    branches/soc-2011-garlic/source/blender/blenfont/BLF_api.h
    branches/soc-2011-garlic/source/blender/blenfont/intern/blf.c
    branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c

Modified: branches/soc-2011-garlic/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/soc-2011-garlic/source/blender/blenfont/BLF_api.h	2011-05-30 10:51:37 UTC (rev 37020)
+++ branches/soc-2011-garlic/source/blender/blenfont/BLF_api.h	2011-05-30 11:03:16 UTC (rev 37021)
@@ -41,6 +41,8 @@
 
 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);
 

Modified: branches/soc-2011-garlic/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/soc-2011-garlic/source/blender/blenfont/intern/blf.c	2011-05-30 10:51:37 UTC (rev 37020)
+++ branches/soc-2011-garlic/source/blender/blenfont/intern/blf.c	2011-05-30 11:03:16 UTC (rev 37021)
@@ -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 @@
 	}
 }
 
+char* BLF_gettext(const char *msgid)
+{
+	return gettext( msgid );
+}
+
 static int blf_search(const char *name)
 {
 	FontBLF *font;

Modified: branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c
===================================================================
--- branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c	2011-05-30 10:51:37 UTC (rev 37020)
+++ branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c	2011-05-30 11:03:16 UTC (rev 37021)
@@ -367,6 +367,30 @@
 	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 @@
 	{"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}
 };
 




More information about the Bf-blender-cvs mailing list