[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55305] trunk/blender/source/blender: Add the possibility to define the translation context for py rna classes ( operators, panels and menus).
Bastien Montagne
montagne29 at wanadoo.fr
Fri Mar 15 15:32:29 CET 2013
Revision: 55305
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55305
Author: mont29
Date: 2013-03-15 14:32:29 +0000 (Fri, 15 Mar 2013)
Log Message:
-----------
Add the possibility to define the translation context for py rna classes (operators, panels and menus).
Thanks to Campell and Brecht for the reviews!
Modified Paths:
--------------
trunk/blender/source/blender/blenfont/BLF_translation.h
trunk/blender/source/blender/blenfont/intern/blf_translation.c
trunk/blender/source/blender/blenkernel/BKE_screen.h
trunk/blender/source/blender/editors/interface/interface_layout.c
trunk/blender/source/blender/editors/interface/interface_panel.c
trunk/blender/source/blender/makesrna/intern/rna_ui.c
trunk/blender/source/blender/makesrna/intern/rna_wm.c
trunk/blender/source/blender/python/intern/bpy_operator_wrap.c
trunk/blender/source/blender/python/intern/bpy_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 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/blenfont/BLF_translation.h 2013-03-15 14:32:29 UTC (rev 55305)
@@ -110,12 +110,14 @@
* All i18n contexts must be defined here.
* This is a nice way to be sure not to use a context twice for different
* things, and limit the number of existing contexts!
+ * WARNING! Contexts should not be longer than BKE_ST_MAXNAME - 1!
*/
/* 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... :/
+ * The void string "" is also interpreted as BLF_I18NCONTEXT_DEFAULT.
* For perf reason, we only use the first char to detect this context, so other contexts should never start
* with the same char!
*/
Modified: trunk/blender/source/blender/blenfont/intern/blf_translation.c
===================================================================
--- trunk/blender/source/blender/blenfont/intern/blf_translation.c 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/blenfont/intern/blf_translation.c 2013-03-15 14:32:29 UTC (rev 55305)
@@ -132,7 +132,7 @@
if (msgid && msgid[0]) {
/*if (msgctxt && !strcmp(msgctxt, BLF_I18NCONTEXT_DEFAULT_BPY_INTERN)) { */
- if (msgctxt && msgctxt[0] == BLF_I18NCONTEXT_DEFAULT_BPY[0]) {
+ 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. */
msgctxt = BLF_I18NCONTEXT_DEFAULT;
}
Modified: trunk/blender/source/blender/blenkernel/BKE_screen.h
===================================================================
--- trunk/blender/source/blender/blenkernel/BKE_screen.h 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/blenkernel/BKE_screen.h 2013-03-15 14:32:29 UTC (rev 55305)
@@ -163,9 +163,10 @@
typedef struct PanelType {
struct PanelType *next, *prev;
- char idname[BKE_ST_MAXNAME]; /* unique name */
- char label[BKE_ST_MAXNAME]; /* for panel header */
- char context[BKE_ST_MAXNAME]; /* for buttons window */
+ char idname[BKE_ST_MAXNAME]; /* unique name */
+ char label[BKE_ST_MAXNAME]; /* for panel header */
+ char translation_context[BKE_ST_MAXNAME];
+ char context[BKE_ST_MAXNAME]; /* for buttons window */
int space_type;
int region_type;
@@ -227,7 +228,8 @@
char idname[BKE_ST_MAXNAME]; /* unique name */
char label[BKE_ST_MAXNAME]; /* for button text */
- char *description;
+ char translation_context[BKE_ST_MAXNAME];
+ char *description;
/* verify if the menu should draw or not */
int (*poll)(const struct bContext *, struct MenuType *);
Modified: trunk/blender/source/blender/editors/interface/interface_layout.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_layout.c 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/editors/interface/interface_layout.c 2013-03-15 14:32:29 UTC (rev 55305)
@@ -1567,7 +1567,7 @@
}
if (!name) {
- name = IFACE_(mt->label);
+ name = CTX_IFACE_(mt->translation_context, mt->label);
}
if (layout->root->type == UI_LAYOUT_MENU && !icon)
Modified: trunk/blender/source/blender/editors/interface/interface_panel.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_panel.c 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/editors/interface/interface_panel.c 2013-03-15 14:32:29 UTC (rev 55305)
@@ -191,7 +191,7 @@
Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, int *open)
{
Panel *pa, *patab, *palast, *panext;
- char *drawname = pt->label;
+ const char *drawname = CTX_IFACE_(pt->translation_context, pt->label);
char *idname = pt->idname;
char *tabname = pt->idname;
char *hookname = NULL;
@@ -469,7 +469,7 @@
Panel *panel = block->panel;
rcti hrect;
int pnl_icons;
- const char *activename = IFACE_(panel->drawname[0] ? panel->drawname : panel->panelname);
+ const char *activename = panel->drawname[0] ? panel->drawname : panel->panelname;
/* + 0.001f to avoid flirting with float inaccuracy */
if (panel->control & UI_PNL_CLOSE) pnl_icons = (panel->labelofs + 2 * PNL_ICON + 5) / block->aspect + 0.001f;
Modified: trunk/blender/source/blender/makesrna/intern/rna_ui.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ui.c 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/makesrna/intern/rna_ui.c 2013-03-15 14:32:29 UTC (rev 55305)
@@ -29,6 +29,8 @@
#include "DNA_screen_types.h"
+#include "BLF_translation.h"
+
#include "RNA_define.h"
#include "rna_internal.h"
@@ -226,6 +228,7 @@
memcpy(pt, &dummypt, sizeof(dummypt));
pt->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, pt->idname, &RNA_Panel);
+ RNA_def_struct_translation_context(pt->ext.srna, pt->translation_context);
pt->ext.data = data;
pt->ext.call = call;
pt->ext.free = free;
@@ -573,6 +576,7 @@
}
mt->ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, mt->idname, &RNA_Menu);
+ RNA_def_struct_translation_context(mt->ext.srna, mt->translation_context);
mt->ext.data = data;
mt->ext.call = call;
mt->ext.free = free;
@@ -773,6 +777,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);
/* poll */
func = RNA_def_function(srna, "poll", NULL);
@@ -819,7 +824,13 @@
RNA_def_property_ui_text(prop, "Label",
"The panel label, shows up in the panel header at the right of the "
"triangle used to collapse the panel");
-
+
+ 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_flag(prop, PROP_REGISTER_OPTIONAL);
+ RNA_define_verify_sdna(TRUE);
+
prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
RNA_def_property_enum_items(prop, space_type_items);
@@ -956,6 +967,7 @@
RNA_def_struct_sdna(srna, "Menu");
RNA_def_struct_refine_func(srna, "rna_Menu_refine");
RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister", NULL);
+ RNA_def_struct_translation_context(srna, BLF_I18NCONTEXT_DEFAULT);
/* poll */
func = RNA_def_function(srna, "poll", NULL);
@@ -972,7 +984,7 @@
parm = RNA_def_pointer(func, "context", "Context", "", "");
RNA_def_property_flag(parm, PROP_REQUIRED);
- RNA_define_verify_sdna(0); /* not in sdna */
+ RNA_define_verify_sdna(FALSE); /* not in sdna */
prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "layout");
@@ -994,6 +1006,11 @@
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "Label", "The menu label");
+ 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_flag(prop, PROP_REGISTER_OPTIONAL);
+
prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "type->description");
RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c 2013-03-15 13:18:35 UTC (rev 55304)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c 2013-03-15 14:32:29 UTC (rev 55305)
@@ -33,6 +33,8 @@
#include "BLI_utildefines.h"
+#include "BLF_translation.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -1050,6 +1052,7 @@
static char _operator_idname[OP_MAX_TYPENAME];
static char _operator_name[OP_MAX_TYPENAME];
static char _operator_descr[RNA_DYN_DESCR_MAX];
+static char _operator_ctxt[RNA_DYN_DESCR_MAX];
static StructRNA *rna_Operator_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
{
@@ -1063,10 +1066,11 @@
dummyot.idname = _operator_idname; /* only assigne the pointer, string is NULL'd */
dummyot.name = _operator_name; /* only assigne the pointer, string is NULL'd */
dummyot.description = _operator_descr; /* only assigne the pointer, string is NULL'd */
+ dummyot.translation_context = _operator_ctxt; /* only assigne the pointer, string is NULL'd */
RNA_pointer_create(NULL, &RNA_Operator, &dummyop, &dummyotr);
/* clear in case they are left unset */
- _operator_idname[0] = _operator_name[0] = _operator_descr[0] = '\0';
+ _operator_idname[0] = _operator_name[0] = _operator_descr[0] = _operator_ctxt[0] = '\0';
/* validate the python class */
if (validate(&dummyotr, data, have_function) != 0)
@@ -1117,9 +1121,10 @@
int idlen = strlen(_operator_idname) + 4;
int namelen = strlen(_operator_name) + 1;
int desclen = strlen(_operator_descr) + 1;
+ int ctxtlen = strlen(_operator_ctxt) + 1;
char *ch;
/* 2 terminators and 3 to convert a.b -> A_OT_b */
- ch = MEM_callocN(sizeof(char) * (idlen + namelen + desclen), "_operator_idname");
+ ch = MEM_callocN(sizeof(char) * (idlen + namelen + desclen + ctxtlen), "_operator_idname");
WM_operator_bl_idname(ch, _operator_idname); /* convert the idname from python */
dummyot.idname = ch;
ch += idlen;
@@ -1128,6 +1133,9 @@
ch += namelen;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list