[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53142] trunk/blender: Various minor fixes to i18n code (mostly, translation of enum items' tooltips was wrongly bound to iface option, not tooltips one, and recent changes in r53119 were incorectly using BLF_pgettext, made them simpler by using CTX_IFACE_ macro).

Bastien Montagne montagne29 at wanadoo.fr
Tue Dec 18 19:25:49 CET 2012


Revision: 53142
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53142
Author:   mont29
Date:     2012-12-18 18:25:48 +0000 (Tue, 18 Dec 2012)
Log Message:
-----------
Various minor fixes to i18n code (mostly, translation of enum items' tooltips was wrongly bound to iface option, not tooltips one, and recent changes in r53119 were incorectly using BLF_pgettext, made them simpler by using CTX_IFACE_ macro).

Also fixed CTX_FOO_ macros when building without i18n, those were kinda wrong.

And hid i18n ui section in userpreferences when built without its support too.

Revision Links:
--------------
    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53119

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
    trunk/blender/source/blender/blenfont/BLF_translation.h
    trunk/blender/source/blender/blenfont/intern/blf_lang.c
    trunk/blender/source/blender/editors/interface/interface.c
    trunk/blender/source/blender/editors/interface/interface_layout.c
    trunk/blender/source/blender/editors/interface/interface_templates.c
    trunk/blender/source/blender/makesrna/intern/rna_access.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_userpref.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/release/scripts/startup/bl_ui/space_userpref.py	2012-12-18 18:25:48 UTC (rev 53142)
@@ -492,17 +492,17 @@
         sub.active = system.use_weight_color_range
         sub.template_color_ramp(system, "weight_color_range", expand=True)
 
-        column.separator()
+        if 'INTERNATIONAL' in bpy.app.build_options:
+            column.separator()
+            column.prop(system, "use_international_fonts")
+            if system.use_international_fonts:
+                column.prop(system, "language")
+                row = column.row()
+                row.label(text="Translate:")
+                row.prop(system, "use_translate_interface", text="Interface")
+                row.prop(system, "use_translate_tooltips", text="Tooltips")
 
-        column.prop(system, "use_international_fonts")
-        if system.use_international_fonts:
-            column.prop(system, "language")
-            row = column.row()
-            row.label(text="Translate:")
-            row.prop(system, "use_translate_interface", text="Interface")
-            row.prop(system, "use_translate_tooltips", text="Tooltips")
 
-
 class USERPREF_MT_interface_theme_presets(Menu):
     bl_label = "Presets"
     preset_subdir = "interface_theme"

Modified: trunk/blender/source/blender/blenfont/BLF_translation.h
===================================================================
--- trunk/blender/source/blender/blenfont/BLF_translation.h	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h	2012-12-18 18:25:48 UTC (rev 53142)
@@ -85,8 +85,8 @@
 /*	#define _(msgid) msgid */
 	#define IFACE_(msgid) msgid
 	#define TIP_(msgid) msgid
-	#define CTX_IFACE_(context, msgid) ((void)context, msgid)
-	#define CTX_TIP_(context, msgid)   ((void)context, msgid)
+	#define CTX_IFACE_(context, msgid) msgid
+	#define CTX_TIP_(context, msgid)   msgid
 #endif
 
 /* Helper macro, when we want to define a same msgid for multiple msgctxt...

Modified: trunk/blender/source/blender/blenfont/intern/blf_lang.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_lang.c	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/blenfont/intern/blf_lang.c	2012-12-18 18:25:48 UTC (rev 53142)
@@ -30,6 +30,8 @@
 
 #include "BLF_translation.h" /* own include */
 
+#include "BLI_utildefines.h"
+
 #ifdef WITH_INTERNATIONAL
 
 #include <stdio.h>
@@ -50,7 +52,6 @@
 #include "BLI_linklist.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
-#include "BLI_utildefines.h"
 
 /* Locale options. */
 static const char **locales = NULL;
@@ -254,9 +255,8 @@
 	return;
 }
 
-void BLF_lang_set(const char *str)
+void BLF_lang_set(const char *UNUSED(str))
 {
-	(void)str;
 	return;
 }
 

Modified: trunk/blender/source/blender/editors/interface/interface.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface.c	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/editors/interface/interface.c	2012-12-18 18:25:48 UTC (rev 53142)
@@ -2831,15 +2831,11 @@
 			EnumPropertyItem *item;
 			int i, totitem, free;
 
-			/* get untranslated, then translate the single string we get */
+			/* get untranslated, then translate the single string we need */
 			RNA_property_enum_items(block->evil_C, ptr, prop, &item, &totitem, &free);
 			for (i = 0; i < totitem; i++) {
 				if (item[i].identifier[0] && item[i].value == (int)max) {
-#ifdef WITH_INTERNATIONAL
-					str = BLF_pgettext(RNA_property_translation_context(prop), item[i].name);
-#else
-					str = item[i].name;
-#endif
+					str = CTX_IFACE_(RNA_property_translation_context(prop), item[i].name);
 					icon = item[i].icon;
 					break;
 				}

Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c	2012-12-18 18:25:48 UTC (rev 53142)
@@ -720,9 +720,7 @@
 
 	RNA_property_enum_items(layout->root->block->evil_C, ptr, prop, &item, &totitem, &free);
 	if (RNA_enum_name(item, retval, &name)) {
-#ifdef WITH_INTERNATIONAL
-		name = BLF_pgettext(RNA_property_translation_context(prop), name);
-#endif
+		name = CTX_IFACE_(RNA_property_translation_context(prop), name);
 	}
 	else {
 		name = "";
@@ -909,7 +907,7 @@
 	UI_OPERATOR_ERROR_RET(ot, opname, return );
 
 	WM_operator_properties_create_ptr(&ptr, ot);
-	
+
 	/* enum lookup */
 	if ((prop = RNA_struct_find_property(&ptr, propname))) {
 		/* no need for translations here */
@@ -930,9 +928,9 @@
 		RNA_warning("%s.%s not found", RNA_struct_identifier(ptr.type), propname);
 		return;
 	}
-	
+
 	RNA_property_enum_set(&ptr, prop, value);
-	
+
 	/* same as uiItemEnumO */
 	if (!name)
 		name = ui_menu_enumpropname(layout, &ptr, prop, value);
@@ -1191,11 +1189,8 @@
 
 	for (a = 0; item[a].identifier; a++) {
 		if (item[a].value == ivalue) {
-			const char *item_name = item[a].name;
+			const char *item_name = CTX_IFACE_(RNA_property_translation_context(prop), item[a].name);
 
-#ifdef WITH_INTERNATIONAL
-			item_name = BLF_pgettext(RNA_property_translation_context(prop), item_name);
-#endif
 			uiItemFullR(layout, ptr, prop, RNA_ENUM_VALUE, ivalue, 0, item_name ? item_name : name, icon ? icon : item[a].icon);
 			break;
 		}

Modified: trunk/blender/source/blender/editors/interface/interface_templates.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_templates.c	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/editors/interface/interface_templates.c	2012-12-18 18:25:48 UTC (rev 53142)
@@ -347,6 +347,7 @@
 /* Return a type-based i18n context, needed e.g. by "New" button.
  * In most languages, this adjective takes different form based on gender of type name...
  */
+#ifdef WITH_INTERNATIONAL
 static const char *template_id_context(StructRNA *type)
 {
 	if (type) {
@@ -377,6 +378,7 @@
 	}
 	return BLF_I18NCONTEXT_DEFAULT;
 }
+#endif
 
 static void template_ID(bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, short idcode, int flag,
                         const char *newop, const char *openop, const char *unlinkop)
@@ -387,7 +389,6 @@
 	// ListBase *lb; // UNUSED
 	ID *id, *idfrom;
 	int editable = RNA_property_editable(&template->ptr, template->prop);
-	const char *i18n_ctxt = template_id_context(type);
 
 	idptr = RNA_property_pointer_get(&template->ptr, template->prop);
 	id = idptr.data;
@@ -518,11 +519,11 @@
 		
 		if (newop) {
 			but = uiDefIconTextButO(block, BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
-			                        (id) ? "" : CTX_IFACE_(i18n_ctxt, "New"), 0, 0, w, UI_UNIT_Y, NULL);
+			                        (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), 0, 0, w, UI_UNIT_Y, NULL);
 			uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
 		}
 		else {
-			but = uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(i18n_ctxt, "New"),
+			but = uiDefIconTextBut(block, BUT, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
 			                       0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
 			uiButSetNFunc(but, template_id_cb, MEM_dupallocN(template), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
 		}

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-12-18 18:10:05 UTC (rev 53141)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c	2012-12-18 18:25:48 UTC (rev 53142)
@@ -1197,11 +1197,16 @@
 	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;
+		/* Note: Only do those tests once, and then use BLF_pgettext. */
+		int do_iface = BLF_translate_iface();
+		int do_tooltip = BLF_translate_tooltips();
 		EnumPropertyItem *nitem;
 
+		if (!(do_iface || do_tooltip))
+			return;
+
 		if (*free) {
 			nitem = *item;
 		}
@@ -1217,16 +1222,17 @@
 			for (i = 0; (*item)[i].identifier; i++)
 				nitem[i] = (*item)[i];
 
-			*free = 1;
+			*free = TRUE;
 		}
 
 		for (i = 0; nitem[i].identifier; i++) {
-			if (nitem[i].name) {
-				/* note: prop->translation_context may be NULL, this just means we dont use a context */
+			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)
+			if (nitem[i].description && do_tooltip) {
 				nitem[i].description = BLF_pgettext(NULL, nitem[i].description);
+			}
 		}
 
 		*item = nitem;




More information about the Bf-blender-cvs mailing list