[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [44924] trunk/blender/source/blender: i18n stuff: adds translation_context to RNA structs ( used for there ui name), and a first default "Operator" one for all operators' label.

Bastien Montagne montagne29 at wanadoo.fr
Fri Mar 16 16:39:31 CET 2012


Revision: 44924
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=44924
Author:   mont29
Date:     2012-03-16 15:39:25 +0000 (Fri, 16 Mar 2012)
Log Message:
-----------
i18n stuff: adds translation_context to RNA structs (used for there ui name), and a first default "Operator" one for all operators' label.

The fact is, operators' label are nearly always verbs, while properties labels are nearly always nouns. So this should already solve many translations' problems regarding noun/verb confusion.

This commit also simplifies a bit i18n usage:
*Now IFACE_ and TIP_ macros (or there context versions, CTX_IFACE_/TIP_) are used nearly everywhere (with one exception, where code is a bit complex and needs to manually test whether ui/tip translations is allowed, so no need to redo it later through those macros).
*Also, those macros are now defined to NOP in case WITH_INTERNATIONAL is false, which avoid testing that define everywhere in code!

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/editors/interface/interface_layout.c
    trunk/blender/source/blender/makesrna/RNA_define.h
    trunk/blender/source/blender/makesrna/intern/makesrna.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_internal_types.h
    trunk/blender/source/blender/makesrna/intern/rna_rna.c
    trunk/blender/source/blender/windowmanager/WM_types.h
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/source/blender/blenfont/BLF_translation.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_translation.h	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h	2012-03-16 15:39:25 UTC (rev 44924)
@@ -61,15 +61,25 @@
 /* translation */
 int BLF_translate_iface(void);
 int BLF_translate_tooltips(void);
-const char *BLF_translate_do_iface(const char *msgid);
-const char *BLF_translate_do_tooltip(const char *msgid);
+const char *BLF_translate_do_iface(const char *contex, const char *msgid);
+const char *BLF_translate_do_tooltip(const char *contex, const char *msgid);
 
 
-/* #define _(msgid) BLF_gettext(msgid) */
 /* The "translation-marker" macro. */
 #define N_(msgid) msgid
 /* Those macros should be used everywhere in UI code. */
-#define IFACE_(msgid) BLF_translate_do_iface(msgid)
-#define TIP_(msgid) BLF_translate_do_tooltip(msgid)
+#ifdef WITH_INTERNATIONAL
+/*	#define _(msgid) BLF_gettext(msgid) */
+	#define IFACE_(msgid) BLF_translate_do_iface(NULL, msgid)
+	#define TIP_(msgid) BLF_translate_do_tooltip(NULL, msgid)
+	#define CTX_IFACE_(context, msgid) BLF_translate_do_iface(context, msgid)
+	#define CTX_TIP_(context, msgid) BLF_translate_do_tooltip(context, msgid)
+#else
+/*	#define _(msgid) msgid */
+	#define IFACE_(msgid) msgid
+	#define TIP_(msgid) msgid
+	#define CTX_IFACE_(context, msgid) msgid
+	#define CTX_TIP_(context, msgid) msgid
+#endif
 
 #endif /* __BLF_TRANSLATION_H__ */

Modified: trunk/blender/source/blender/blenfont/intern/blf_translation.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_translation.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/blenfont/intern/blf_translation.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -154,11 +154,15 @@
 #endif
 }
 
-const char *BLF_translate_do_iface(const char *msgid)
+const char *BLF_translate_do_iface(const char *context, const char *msgid)
 {
 #ifdef WITH_INTERNATIONAL
-	if (BLF_translate_iface())
-		return BLF_gettext(msgid);
+	if(BLF_translate_iface()) {
+		if (context)
+			return BLF_pgettext(context, msgid);
+		else
+			return BLF_gettext(msgid);
+	}
 	else
 		return msgid;
 #else
@@ -166,11 +170,15 @@
 #endif
 }
 
-const char *BLF_translate_do_tooltip(const char *msgid)
+const char *BLF_translate_do_tooltip(const char *context, const char *msgid)
 {
 #ifdef WITH_INTERNATIONAL
-	if (BLF_translate_tooltips())
-		return BLF_gettext(msgid);
+	if(BLF_translate_tooltips()) {
+		if (context)
+			return BLF_pgettext(context, msgid);
+		else
+			return BLF_gettext(msgid);
+	}
 	else
 		return msgid;
 #else

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/editors/interface/interface.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -2814,13 +2814,14 @@
 	uiBut *but;
 
 	if(!str) {
-		if(ot) str = ot->name;
+		if (ot && ot->srna)
+			str = RNA_struct_ui_name(ot->srna);
+		else
+			str = "";
 	}
-	
-	if ((!tip || tip[0]=='\0') && ot && ot->description) {
-		tip= ot->description;
 
-		tip = TIP_(tip);
+	if ((!tip || tip[0]=='\0') && ot && ot->srna) {
+		tip = RNA_struct_ui_description(ot->srna);
 	}
 
 	but= ui_def_but(block, type, -1, str, x1, y1, x2, y2, NULL, 0, 0, 0, 0, tip);

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -639,7 +639,10 @@
 	int w;
 
 	if(!name) {
-		name= IFACE_(ot->name);
+		if (ot && ot->srna)
+			name = RNA_struct_ui_name(ot->srna);
+		else
+			name = "";
 	}
 
 	if(layout->root->type == UI_LAYOUT_MENU && !icon)

Modified: trunk/blender/source/blender/makesrna/RNA_define.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_define.h	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/RNA_define.h	2012-03-16 15:39:25 UTC (rev 44924)
@@ -66,6 +66,8 @@
 void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *ext);
 void RNA_struct_free(BlenderRNA *brna, StructRNA *srna);
 
+void RNA_def_struct_translation_context(StructRNA *srna, const char *context);
+
 /* Compact Property Definitions */
 
 typedef void StructOrFunctionRNA;

Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/makesrna.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/intern/makesrna.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -2474,6 +2474,8 @@
 	rna_print_c_string(f, srna->name);
 	fprintf(f, ", ");
 	rna_print_c_string(f, srna->description);
+	fprintf(f, ", ");
+	rna_print_c_string(f, srna->translation_context);
 	fprintf(f, ",\n\t%d,\n", srna->icon);
 
 	prop = srna->nameproperty;

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -474,12 +474,7 @@
 			description = ((IDProperty*)prop)->name; /* XXX - not correct */
 	}
 
-#ifdef WITH_INTERNATIONAL
-	if (description && BLF_translate_tooltips())
-		description = BLF_gettext(description);
-#endif
-
-	return description;
+	return TIP_(description);
 }
 
 static const char *rna_ensure_property_name(PropertyRNA *prop)
@@ -491,16 +486,7 @@
 	else
 		name = ((IDProperty*)prop)->name;
 
-#ifdef WITH_INTERNATIONAL
-	if (BLF_translate_iface()) {
-		if (prop->translation_context)
-			name = BLF_pgettext(prop->translation_context, name);
-		else
-			name = BLF_gettext(name);
-	}
-#endif
-
-	return name;
+	return CTX_IFACE_(prop->translation_context, name);
 }
 
 /* Structs */
@@ -523,7 +509,7 @@
 
 const char *RNA_struct_ui_name(StructRNA *type)
 {
-	return type->name;
+	return CTX_IFACE_(type->translation_context, type->name);
 }
 
 int RNA_struct_ui_icon(StructRNA *type)
@@ -536,7 +522,7 @@
 
 const char *RNA_struct_ui_description(StructRNA *type)
 {
-	return type->description;
+	return TIP_(type->description);
 }
 
 PropertyRNA *RNA_struct_name_property(StructRNA *type)
@@ -1182,6 +1168,7 @@
 	RNA_property_enum_items(C, ptr, prop, item, totitem, free);
 
 #ifdef WITH_INTERNATIONAL
+	/* Note: keep directly using BLF_gettext here, has we have already done tests like BLF_translate_iface... */
 	if (BLF_translate_iface()) {
 		int i;
 		EnumPropertyItem *nitem;

Modified: trunk/blender/source/blender/makesrna/intern/rna_define.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_define.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/intern/rna_define.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -871,6 +871,11 @@
 	srna->icon = icon;
 }
 
+void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
+{
+	srna->translation_context = context;
+}
+
 /* Property Definition */
 
 PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)

Modified: trunk/blender/source/blender/makesrna/intern/rna_internal_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_internal_types.h	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/intern/rna_internal_types.h	2012-03-16 15:39:25 UTC (rev 44924)
@@ -312,6 +312,8 @@
 	const char *name;
 	/* single line description, displayed in the tooltip for example */
 	const char *description;
+	/* context for translation */
+	const char *translation_context;
 	/* icon ID */
 	int icon;
 	

Modified: trunk/blender/source/blender/makesrna/intern/rna_rna.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_rna.c	2012-03-16 14:49:16 UTC (rev 44923)
+++ trunk/blender/source/blender/makesrna/intern/rna_rna.c	2012-03-16 15:39:25 UTC (rev 44924)
@@ -129,6 +129,16 @@
 	return strlen(((StructRNA*)ptr->data)->name);
 }
 
+static void rna_Struct_translation_context_get(PointerRNA *ptr, char *value)
+{
+	strcpy(value, ((StructRNA*)ptr->data)->translation_context ? ((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;
+}
+
 static PointerRNA rna_Struct_base_get(PointerRNA *ptr)
 {
 	return rna_pointer_inherit_refine(ptr, &RNA_Struct, ((StructRNA*)ptr->data)->base);
@@ -982,6 +992,11 @@
 	RNA_def_property_string_funcs(prop, "rna_Struct_description_get", "rna_Struct_description_length", NULL);
 	RNA_def_property_ui_text(prop, "Description", "Description of the Struct's purpose");
 	
+	prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_string_funcs(prop, "rna_Struct_translation_context_get", "rna_Struct_translation_context_length", NULL);
+	RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the struct's name");
+	
 	prop = RNA_def_property(srna, "base", PROP_POINTER, PROP_NONE);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_struct_type(prop, "Struct");
@@ -1064,7 +1079,7 @@
 	prop = RNA_def_property(srna, "translation_context", PROP_STRING, PROP_NONE);
 	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
 	RNA_def_property_string_funcs(prop, "rna_Property_translation_context_get", "rna_Property_translation_context_length", NULL);
-	RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the property");
+	RNA_def_property_ui_text(prop, "Translation Context", "Translation context of the property's name");
 
 	prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list