[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54527] trunk/blender: Fix physics' name not translated in main physics panel (reported on bf-translations ML) .

Bastien Montagne montagne29 at wanadoo.fr
Wed Feb 13 12:52:01 CET 2013


Revision: 54527
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54527
Author:   mont29
Date:     2013-02-13 11:52:01 +0000 (Wed, 13 Feb 2013)
Log Message:
-----------
Fix physics' name not translated in main physics panel (reported on bf-translations ML).

This also revealed another bug, as you could not explicitely set default context to text_ctxt UI func parameter (None is not accpeted by RNA string props), so I had to change default context from py POV to "*" instead of None.

Anyway, that physics UI translation remains weak, as the trick used here (helper func) prevents message extractor script to directly find them. Currently it works because specified labels are also defined elsewhere, but it would be nice to have some kind of "translation markers" in py code too (similar to our N_/CTX_N_ C macros, unfortunately python does not have preprocessing ;) )...

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py
    trunk/blender/source/blender/blenfont/BLF_translation.h
    trunk/blender/source/blender/blenfont/intern/blf_translation.c
    trunk/blender/source/blender/python/intern/bpy_app_translations.c

Modified: trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py	2013-02-13 11:02:51 UTC (rev 54526)
+++ trunk/blender/release/scripts/startup/bl_ui/properties_physics_common.py	2013-02-13 11:52:01 UTC (rev 54527)
@@ -21,7 +21,9 @@
 import bpy
 from bpy.types import Panel
 
+i18n_default_ctxt = bpy.app.translations.contexts.default
 
+
 class PhysicButtonsPanel():
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
@@ -37,20 +39,20 @@
     sub = layout.row(align=True)
     if md:
         sub.context_pointer_set("modifier", md)
-        sub.operator("object.modifier_remove", text=name, icon='X')
+        sub.operator("object.modifier_remove", text=name, text_ctxt=i18n_default_ctxt, icon='X')
         if(toggles):
             sub.prop(md, "show_render", text="")
             sub.prop(md, "show_viewport", text="")
     else:
-        sub.operator("object.modifier_add", text=name, icon=typeicon).type = type
+        sub.operator("object.modifier_add", text=name, text_ctxt=i18n_default_ctxt, icon=typeicon).type = type
 
 
 def physics_add_special(self, layout, data, name, addop, removeop, typeicon):
     sub = layout.row(align=True)
     if data:
-        sub.operator(removeop, text=name, icon='X')
+        sub.operator(removeop, text=name, text_ctxt=i18n_default_ctxt, icon='X')
     else:
-        sub.operator(addop, text=name, icon=typeicon)
+        sub.operator(addop, text=name, text_ctxt=i18n_default_ctxt, icon=typeicon)
 
 
 class PHYSICS_PT_add(PhysicButtonsPanel, Panel):

Modified: trunk/blender/source/blender/blenfont/BLF_translation.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_translation.h	2013-02-13 11:02:51 UTC (rev 54526)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h	2013-02-13 11:52:01 UTC (rev 54527)
@@ -112,9 +112,13 @@
 
 /* Default, void context.
  * WARNING! The "" context is not the same as no (NULL) context at mo/boost::locale level!
+ * NOTE: We translate BLF_I18NCONTEXT_DEFAULT as BLF_I18NCONTEXT_DEFAULT_BPY in Python, as we can’t use "natural"
+ *       None value in rna string properties... :/
+ *       For perf reason, we only use the first char to detect this context, so other contexts should never start
+ *       with the same char!
  */
-#define BLF_I18NCONTEXT_DEFAULT NULL  /* Translated as None in Python. */
-#define BLF_I18NCONTEXT_DEFAULT_BPY_INTERN ""  /* Only used in code, never exposed to user! */
+#define BLF_I18NCONTEXT_DEFAULT NULL
+#define BLF_I18NCONTEXT_DEFAULT_BPY "*"
 
 /* Default context for operator names/labels. */
 #define BLF_I18NCONTEXT_OPERATOR_DEFAULT "Operator"
@@ -165,7 +169,8 @@
 #define BLF_I18NCONTEXTS_ITEM(ctxt_id, py_id) {#ctxt_id, py_id, ctxt_id}
 
 #define BLF_I18NCONTEXTS_DESC {                                                                                        \
-	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default"),                                                         \
+	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default_real"),                                                    \
+	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT_BPY, "default"),                                                     \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"),                                       \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ACTION, "id_action"),                                                     \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_ID_ARMATURE, "id_armature"),                                                 \

Modified: trunk/blender/source/blender/blenfont/intern/blf_translation.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_translation.c	2013-02-13 11:02:51 UTC (rev 54526)
+++ trunk/blender/source/blender/blenfont/intern/blf_translation.c	2013-02-13 11:52:01 UTC (rev 54527)
@@ -94,9 +94,9 @@
 		const char *ret;
 
 		/*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */
-		if (msgctxt && !msgctxt[0]) {
-			/* BLF_I18NCONTEXT_DEFAULT_BPY_INTERN context is reserved and considered the same as default NULL one. */
-			msgctxt = NULL;
+		if (msgctxt && msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0]) {
+			/* BLF_I18NCONTEXT_DEFAULT_BPY context is reserved and considered the same as default NULL one. */
+			msgctxt = BLF_I18NCONTEXT_DEFAULT;
 		}
 		ret = bl_locale_pgettext(msgctxt, msgid);
 		/* We assume if the returned string is the same (memory level) as the msgid, no translation was found,

Modified: trunk/blender/source/blender/python/intern/bpy_app_translations.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_app_translations.c	2013-02-13 11:02:51 UTC (rev 54526)
+++ trunk/blender/source/blender/python/intern/bpy_app_translations.c	2013-02-13 11:52:01 UTC (rev 54527)
@@ -74,7 +74,7 @@
 static GHashKey *_ghashutil_keyalloc(const void *msgctxt, const void *msgid)
 {
 	GHashKey *key = MEM_mallocN(sizeof(GHashKey), "Py i18n GHashKey");
-	key->msgctxt = BLI_strdup(msgctxt ? msgctxt : BLF_I18NCONTEXT_DEFAULT_BPY_INTERN);
+	key->msgctxt = BLI_strdup(msgctxt ? msgctxt : BLF_I18NCONTEXT_DEFAULT_BPY);
 	key->msgid = BLI_strdup(msgid);
 	return key;
 }
@@ -195,7 +195,7 @@
 				else {
 					PyObject *tmp = PyTuple_GET_ITEM(pykey, 0);
 					if (tmp == Py_None) {
-						msgctxt = BLF_I18NCONTEXT_DEFAULT;
+						msgctxt = BLF_I18NCONTEXT_DEFAULT_BPY;
 					}
 					else if (PyUnicode_Check(tmp)) {
 						msgctxt = _PyUnicode_AsString(tmp);
@@ -288,9 +288,7 @@
 
 	_ghashutil_keyfree((void *)key);
 
-	if (tmp)
-		return tmp;
-	return msgid;
+	return tmp ? tmp : msgid;
 
 #undef STATIC_LOCALE_SIZE
 }
@@ -435,8 +433,8 @@
 
 PyDoc_STRVAR(app_translations_contexts_doc,
 	"A named tuple containing all pre-defined translation contexts.\n"
-	"WARNING: do not use the \"" BLF_I18NCONTEXT_DEFAULT_BPY_INTERN "\" context, it is internally assimilated as the "
-	"default one!\n"
+	"WARNING: Never use a (new) context starting with \"" BLF_I18NCONTEXT_DEFAULT_BPY "\", it would be internally "
+	"assimilated as the default one!\n"
 );
 
 PyDoc_STRVAR(app_translations_contexts_C_to_py_doc,
@@ -503,8 +501,7 @@
 #ifdef WITH_INTERNATIONAL
 	char *msgid, *msgctxt = NULL;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kw, "s|z:bpy.app.translations.pgettext", (char **)kwlist,
-	                                 &msgid, &msgctxt))
+	if (!PyArg_ParseTupleAndKeywords(args, kw, "s|z:bpy.app.translations.pgettext", (char **)kwlist, &msgid, &msgctxt))
 	{
 		return NULL;
 	}
@@ -514,8 +511,7 @@
 	PyObject *msgid, *msgctxt;
 	(void)_pgettext;
 
-	if (!PyArg_ParseTupleAndKeywords(args, kw, "O|O:bpy.app.translations.pgettext", (char **)kwlist,
-	                                 &msgid, &msgctxt))
+	if (!PyArg_ParseTupleAndKeywords(args, kw, "O|O:bpy.app.translations.pgettext", (char **)kwlist, &msgid, &msgctxt))
 	{
 		return NULL;
 	}




More information about the Bf-blender-cvs mailing list