[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [40377] branches/soc-2011-garlic/source/ blender: modify the python gettext function to pass through the original string when no translation is done , this means the cached info such as byte representation and hash will be kept .

Campbell Barton ideasman42 at gmail.com
Tue Sep 20 04:25:58 CEST 2011


Revision: 40377
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=40377
Author:   campbellbarton
Date:     2011-09-20 02:25:57 +0000 (Tue, 20 Sep 2011)
Log Message:
-----------
modify the python gettext function to pass through the original string when no translation is done, this means the cached info such as byte representation and hash will be kept.

Modified Paths:
--------------
    branches/soc-2011-garlic/source/blender/blenkernel/intern/font.c
    branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c

Modified: branches/soc-2011-garlic/source/blender/blenkernel/intern/font.c
===================================================================
--- branches/soc-2011-garlic/source/blender/blenkernel/intern/font.c	2011-09-20 01:35:39 UTC (rev 40376)
+++ branches/soc-2011-garlic/source/blender/blenkernel/intern/font.c	2011-09-20 02:25:57 UTC (rev 40377)
@@ -289,8 +289,10 @@
 	}
 	BLI_freelistN(&ttfdata);
 
+#ifdef INTERNATIONAL
 	if(unifont_ttf)
 		MEM_freeN(unifont_ttf);
+#endif
 }
 
 struct TmpFont *vfont_find_tmpfont(VFont *vfont)

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-09-20 01:35:39 UTC (rev 40376)
+++ branches/soc-2011-garlic/source/blender/python/generic/blf_py_api.c	2011-09-20 02:25:57 UTC (rev 40377)
@@ -381,20 +381,20 @@
 "   :return: the localized string.\n"
 "   :rtype: string\n"
 );
-static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *args)
+static PyObject *py_blf_gettext(PyObject *UNUSED(self), PyObject *value)
 {
-	char* msgid;
-	const char *text;
+	if ((U.transopts & USER_DOTRANSLATE) && (U.transopts & USER_TR_IFACE)) {
+		const char *msgid= _PyUnicode_AsString(value);
+		if(msgid == NULL) {
+			PyErr_SetString(PyExc_TypeError, "blf.gettext expects a single string argument");
+			return NULL;
+		}
 
-	if (!PyArg_ParseTuple(args, "s:blf.gettext", &msgid))
-		return NULL;
-
-	if((U.transopts&USER_DOTRANSLATE) && (U.transopts&USER_TR_IFACE))
-		text = BLF_gettext( msgid );
-	else
-		text = msgid;
-
-	return PyUnicode_FromString( text );
+		return PyUnicode_FromString(BLF_gettext(msgid));
+	}
+	else {
+		return Py_INCREF(value), value;
+	}
 }
 
 PyDoc_STRVAR(py_blf_fake_gettext_doc,
@@ -407,15 +407,16 @@
 "   :return: the source string.\n"
 "   :rtype: string\n"
 );
-static PyObject *py_blf_fake_gettext(PyObject *UNUSED(self), PyObject *args)
+static PyObject *py_blf_fake_gettext(PyObject *UNUSED(self), PyObject *value)
 {
-	const char* msgid;
-	if (!PyArg_ParseTuple(args, "s:blf.fake_gettext", &msgid))
+	if (!PyUnicode_Check(value)) {
+		PyErr_SetString(PyExc_TypeError, "blf.fake_gettext expects a single string argument");
 		return NULL;
+	}
 
-	return PyUnicode_FromString( msgid );
+	return Py_INCREF(value), value;
 }
-#endif
+#endif /* INTERNATIONAL */
 
 /*----------------------------MODULE INIT-------------------------*/
 static PyMethodDef BLF_methods[] = {
@@ -433,8 +434,8 @@
 	{"size", (PyCFunction) py_blf_size, METH_VARARGS, py_blf_size_doc},
 	{"load", (PyCFunction) py_blf_load, METH_VARARGS, py_blf_load_doc},
 #ifdef INTERNATIONAL
-	{"gettext", (PyCFunction) py_blf_gettext, METH_VARARGS, py_blf_gettext_doc},
-	{"fake_gettext", (PyCFunction) py_blf_fake_gettext, METH_VARARGS, py_blf_fake_gettext_doc},
+	{"gettext", (PyCFunction) py_blf_gettext, METH_O, py_blf_gettext_doc},
+	{"fake_gettext", (PyCFunction) py_blf_fake_gettext, METH_O, py_blf_fake_gettext_doc},
 #endif
 	{NULL, NULL, 0, NULL}
 };




More information about the Bf-blender-cvs mailing list