[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55424] trunk/blender/source/blender: Various cleanup around default i18n context.

Bastien Montagne montagne29 at wanadoo.fr
Tue Mar 19 20:37:23 CET 2013


Revision: 55424
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55424
Author:   mont29
Date:     2013-03-19 19:37:22 +0000 (Tue, 19 Mar 2013)
Log Message:
-----------
Various cleanup around default i18n context.

Issue is that the real default context is NULL, however, in python and RNA, this value can't be used easily. So we use a specific string instead ("*"), defined as BLF_I18NCONTEXT_DEFAULT_BPYRNA.

>From now on, all bpy/rna code should only use the BLF_I18NCONTEXT_DEFAULT_BPYRNA value, while all "usual" C code should use the BLF_I18NCONTEXT_DEFAULT value (BLF_pgettext is still able to "understand" both, anyway).

Also added BLF_is_default_context helper func, so that we can keep that check in a single place!

Finally, we should no need anymore to understand the void string "" as default context too - two values for a same thing are more than enough!

Modified Paths:
--------------
    trunk/blender/source/blender/blenfont/BLF_translation.h
    trunk/blender/source/blender/blenfont/intern/blf_translation.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/makesrna/intern/rna_define.c
    trunk/blender/source/blender/makesrna/intern/rna_rna.c
    trunk/blender/source/blender/makesrna/intern/rna_ui.c
    trunk/blender/source/blender/python/intern/bpy_app_translations.c

Modified: trunk/blender/source/blender/blenfont/BLF_translation.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_translation.h	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h	2013-03-19 19:37:22 UTC (rev 55424)
@@ -71,6 +71,7 @@
 unsigned char *BLF_get_unifont_mono(int *unifont_size);
 void BLF_free_unifont_mono(void);
 
+bool BLF_is_default_context(const char *msgctxt);
 const char *BLF_pgettext(const char *msgctxt, const char *msgid);
 
 /* translation */
@@ -101,7 +102,7 @@
 
 /* Helper macro, when we want to define a same msgid for multiple msgctxt...
  * Does nothing in C, but is "parsed" by our i18n py tools.
- * XXX Currently limited to at most 16 contexts at most
+ * XXX Currently limited to at most 16 contexts at once
  *     (but you can call it several times with the same msgid, should you need more contexts!).
  */
 #define BLF_I18N_MSGID_MULTI_CTXT(msgid, ...)
@@ -122,7 +123,7 @@
  *       with the same char!
  */
 #define BLF_I18NCONTEXT_DEFAULT NULL
-#define BLF_I18NCONTEXT_DEFAULT_BPY "*"
+#define BLF_I18NCONTEXT_DEFAULT_BPYRNA "*"
 
 /* Default context for operator names/labels. */
 #define BLF_I18NCONTEXT_OPERATOR_DEFAULT "Operator"
@@ -174,7 +175,7 @@
 
 #define BLF_I18NCONTEXTS_DESC {                                                                                        \
 	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT, "default_real"),                                                    \
-	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT_BPY, "default"),                                                     \
+	BLF_I18NCONTEXTS_ITEM(BLF_I18NCONTEXT_DEFAULT_BPYRNA, "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-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/blenfont/intern/blf_translation.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -125,15 +125,22 @@
 #endif
 }
 
+bool BLF_is_default_context(const char *msgctxt)
+{
+	/* We use the "short" test, a more complete one could be:
+	 * return (!msgctxt || !msgctxt[0] || !strcmp(msgctxt == BLF_I18NCONTEXT_DEFAULT_BPYRNA))
+	 */
+	/* Note: trying without the void string check for now, it *should* not be necessary... */
+	return (!msgctxt || msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPYRNA[0]);
+}
+
 const char *BLF_pgettext(const char *msgctxt, const char *msgid)
 {
 #ifdef WITH_INTERNATIONAL
 	const char *ret = msgid;
 
 	if (msgid && msgid[0]) {
-		/*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */
-		if (msgctxt && (!msgctxt[0] || msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0])) {
-			/* BLF_I18NCONTEXT_DEFAULT_BPY context is reserved and considered the same as default NULL one. */
+		if (BLF_is_default_context(msgctxt)) {
 			msgctxt = BLF_I18NCONTEXT_DEFAULT;
 		}
 		ret = bl_locale_pgettext(msgctxt, msgid);

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/editors/interface/interface.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -3963,7 +3963,7 @@
 			}
 		}
 		else if (type == BUT_GET_RNA_LABEL_CONTEXT) {
-			const char *_tmp = NULL;
+			const char *_tmp = BLF_I18NCONTEXT_DEFAULT;
 			if (but->rnaprop)
 				_tmp = RNA_property_translation_context(but->rnaprop);
 			else if (but->optype)
@@ -3973,8 +3973,8 @@
 				if (mt)
 					_tmp = RNA_struct_translation_context(mt->ext.srna);
 			}
-			if (!_tmp) {  /* _tmp == BLF_I18NCONTEXT_DEFAULT */
-				_tmp = BLF_I18NCONTEXT_DEFAULT_BPY;
+			if (BLF_is_default_context(_tmp)) {
+				_tmp = BLF_I18NCONTEXT_DEFAULT_BPYRNA;
 			}
 			tmp = BLI_strdup(_tmp);
 		}

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -554,7 +554,7 @@
 
 const char *RNA_struct_translation_context(StructRNA *type)
 {
-	return type->translation_context ? type->translation_context : BLF_I18NCONTEXT_DEFAULT;
+	return type->translation_context;
 }
 
 PropertyRNA *RNA_struct_name_property(StructRNA *type)
@@ -1283,7 +1283,6 @@
 
 		for (i = 0; nitem[i].identifier; i++) {
 			if (nitem[i].name && do_iface) {
-				/* note: prop->translation_context may be NULL, this just means we use the default "" context */
 				nitem[i].name = BLF_pgettext(prop->translation_context, nitem[i].name);
 			}
 			if (nitem[i].description && do_tooltip) {
@@ -1446,7 +1445,7 @@
 const char *RNA_property_translation_context(PropertyRNA *_prop)
 {
 	PropertyRNA *prop = rna_ensure_property(_prop);
-	return prop->translation_context ? prop->translation_context : BLF_I18NCONTEXT_DEFAULT;
+	return prop->translation_context;
 }
 
 int RNA_property_ui_icon(PropertyRNA *prop)

Modified: trunk/blender/source/blender/makesrna/intern/rna_define.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_define.c	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/makesrna/intern/rna_define.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -741,6 +741,8 @@
 	srna->identifier = identifier;
 	srna->name = identifier; /* may be overwritten later RNA_def_struct_ui_text */
 	srna->description = "";
+	/* may be overwritten later RNA_def_struct_translation_context */
+	srna->translation_context = BLF_I18NCONTEXT_DEFAULT_BPYRNA;
 	srna->flag |= STRUCT_UNDO;
 	if (!srnafrom)
 		srna->icon = ICON_DOT;
@@ -984,7 +986,7 @@
 
 void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
 {
-	srna->translation_context = context;
+	srna->translation_context = context ? context : BLF_I18NCONTEXT_DEFAULT_BPYRNA;
 }
 
 /* Property Definition */
@@ -1113,6 +1115,7 @@
 	prop->subtype = subtype;
 	prop->name = identifier;
 	prop->description = "";
+	prop->translation_context = BLF_I18NCONTEXT_DEFAULT_BPYRNA;
 	/* a priori not raw editable */
 	prop->rawtype = -1;
 
@@ -2057,7 +2060,7 @@
 
 void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
 {
-	prop->translation_context = context;
+	prop->translation_context = context ? context : BLF_I18NCONTEXT_DEFAULT_BPYRNA;
 }
 
 /* Functions */

Modified: trunk/blender/source/blender/makesrna/intern/rna_rna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_rna.c	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/makesrna/intern/rna_rna.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -141,12 +141,12 @@
 
 static void rna_Struct_translation_context_get(PointerRNA *ptr, char *value)
 {
-	strcpy(value, ((StructRNA *)ptr->data)->translation_context ? ((StructRNA *)ptr->data)->translation_context : "");
+	strcpy(value, ((StructRNA *)ptr->data)->translation_context);
 }
 
 static int rna_Struct_translation_context_length(PointerRNA *ptr)
 {
-	return ((StructRNA *)ptr->data)->translation_context ? strlen(((StructRNA *)ptr->data)->translation_context) : 0;
+	return strlen(((StructRNA *)ptr->data)->translation_context);
 }
 
 static PointerRNA rna_Struct_base_get(PointerRNA *ptr)
@@ -491,14 +491,14 @@
 {
 	PropertyRNA *prop = (PropertyRNA *)ptr->data;
 	rna_idproperty_check(&prop, ptr);
-	strcpy(value, prop->translation_context ? prop->translation_context : "");
+	strcpy(value, prop->translation_context);
 }
 
 static int rna_Property_translation_context_length(PointerRNA *ptr)
 {
 	PropertyRNA *prop = (PropertyRNA *)ptr->data;
 	rna_idproperty_check(&prop, ptr);
-	return prop->translation_context ? strlen(prop->translation_context) : 0;
+	return strlen(prop->translation_context);
 }
 
 static int rna_Property_type_get(PointerRNA *ptr)

Modified: trunk/blender/source/blender/makesrna/intern/rna_ui.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ui.c	2013-03-19 18:32:56 UTC (rev 55423)
+++ trunk/blender/source/blender/makesrna/intern/rna_ui.c	2013-03-19 19:37:22 UTC (rev 55424)
@@ -199,6 +199,9 @@
 	dummypanel.type = &dummypt;
 	RNA_pointer_create(NULL, &RNA_Panel, &dummypanel, &dummyptr);
 
+	/* We have to set default context! Else we get a void string... */
+	strcpy(dummypt.translation_context, BLF_I18NCONTEXT_DEFAULT_BPYRNA);
+
 	/* validate the python class */
 	if (validate(&dummyptr, data, have_function) != 0)
 		return NULL;
@@ -544,6 +547,8 @@
 
 	/* clear in case they are left unset */
 	_menu_descr[0] = '\0';
+	/* We have to set default context! Else we get a void string... */
+	strcpy(dummymt.translation_context, BLF_I18NCONTEXT_DEFAULT_BPYRNA);
 
 	/* validate the python class */
 	if (validate(&dummymtr, data, have_function) != 0)
@@ -777,7 +782,7 @@
 	RNA_def_struct_sdna(srna, "Panel");
 	RNA_def_struct_refine_func(srna, "rna_Panel_refine");
 	RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister", NULL);
-	RNA_def_struct_translation_context(srna, BLF_I18NCONTEXT_DEFAULT);
+	RNA_def_struct_translation_context(srna, BLF_I18NCONTEXT_DEFAULT_BPYRNA);
 
 	/* poll */
 	func = RNA_def_function(srna, "poll", NULL);
@@ -827,7 +832,7 @@
 
 	prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->translation_context");
-	RNA_def_property_string_default(prop, BLF_I18NCONTEXT_DEFAULT);
+	RNA_def_property_string_default(prop, BLF_I18NCONTEXT_DEFAULT_BPYRNA);
 	RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
 	RNA_define_verify_sdna(TRUE);
 
@@ -967,7 +972,7 @@
 	RNA_def_struct_sdna(srna, "Menu");
 	RNA_def_struct_refine_func(srna, "rna_Menu_refine");

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list