Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2012-03-16 19:39:25 +0400
committerBastien Montagne <montagne29@wanadoo.fr>2012-03-16 19:39:25 +0400
commit2caa507b7eaa7d55a0be7bda513f08ecfe4791f1 (patch)
tree86e65a98805030b6191643571c2eea1962da9ea7 /source
parent4e6669cee38ed81dc2e9be52f2900885295506f3 (diff)
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!
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenfont/BLF_translation.h20
-rw-r--r--source/blender/blenfont/intern/blf_translation.c20
-rw-r--r--source/blender/editors/interface/interface.c11
-rw-r--r--source/blender/editors/interface/interface_layout.c5
-rw-r--r--source/blender/makesrna/RNA_define.h2
-rw-r--r--source/blender/makesrna/intern/makesrna.c2
-rw-r--r--source/blender/makesrna/intern/rna_access.c23
-rw-r--r--source/blender/makesrna/intern/rna_define.c5
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h2
-rw-r--r--source/blender/makesrna/intern/rna_rna.c17
-rw-r--r--source/blender/windowmanager/WM_types.h2
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c22
12 files changed, 87 insertions, 44 deletions
diff --git a/source/blender/blenfont/BLF_translation.h b/source/blender/blenfont/BLF_translation.h
index 4e09eb60928..5e2fee36af0 100644
--- a/source/blender/blenfont/BLF_translation.h
+++ b/source/blender/blenfont/BLF_translation.h
@@ -61,15 +61,25 @@ void BLF_lang_encoding(const char *str);
/* 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__ */
diff --git a/source/blender/blenfont/intern/blf_translation.c b/source/blender/blenfont/intern/blf_translation.c
index 457545eeb17..dd9fe57fa82 100644
--- a/source/blender/blenfont/intern/blf_translation.c
+++ b/source/blender/blenfont/intern/blf_translation.c
@@ -154,11 +154,15 @@ int BLF_translate_tooltips(void)
#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 @@ const char *BLF_translate_do_iface(const char *msgid)
#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
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index edddd9bf407..9136274e39a 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2814,13 +2814,14 @@ static uiBut *ui_def_but_operator_ptr(uiBlock *block, int type, wmOperatorType *
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);
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index a0dbecbd4a6..3b6648a6441 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -639,7 +639,10 @@ PointerRNA uiItemFullO_ptr(uiLayout *layout, wmOperatorType *ot, const char *nam
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)
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index d6c3422c8d4..9939d0839e6 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -66,6 +66,8 @@ void RNA_def_struct_ui_icon(StructRNA *srna, int icon);
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;
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index be7ced4b656..bb69e23b1f3 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -2474,6 +2474,8 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
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;
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 543824eb5d5..76d33ea9b9a 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -474,12 +474,7 @@ static const char *rna_ensure_property_description(PropertyRNA *prop)
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 @@ static const char *rna_ensure_property_name(PropertyRNA *prop)
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_identifier(StructRNA *type)
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 @@ int RNA_struct_ui_icon(StructRNA *type)
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 @@ void RNA_property_enum_items_gettexted(bContext *C, PointerRNA *ptr, PropertyRNA
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;
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index 202418205f3..78780678af4 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -871,6 +871,11 @@ void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
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)
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index 997f9d084c5..e71352748ea 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -312,6 +312,8 @@ struct StructRNA {
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;
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index 153e9288375..03a1fbc4a80 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -129,6 +129,16 @@ static int rna_Struct_name_length(PointerRNA *ptr)
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 @@ static void rna_def_struct(BlenderRNA *brna)
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 @@ static void rna_def_property(BlenderRNA *brna)
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);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 3beb81eef0a..c2cb3181e3e 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -428,6 +428,8 @@ typedef struct wmTimer {
int sleep; /* internal, put timers to sleep when needed */
} wmTimer;
+/* Default context for operator names/labels. */
+#define WM_OPERATOR_DEFAULT_I18NCONTEXT "Operator"
typedef struct wmOperatorType {
const char *name; /* text for ui, undo */
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index f42bd1d9f80..f72939c03b2 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -146,16 +146,17 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType*))
ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
+ /* Set the default i18n context now, so that opfunc can redefine it if needed! */
+ RNA_def_struct_translation_context(ot->srna, WM_OPERATOR_DEFAULT_I18NCONTEXT);
opfunc(ot);
if(ot->name==NULL) {
fprintf(stderr, "ERROR: Operator %s has no name property!\n", ot->idname);
- ot->name= IFACE_("Dummy Name");
+ ot->name= N_("Dummy Name");
}
// XXX All ops should have a description but for now allow them not to.
- RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:IFACE_("(undocumented operator)"));
-
+ RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:N_("(undocumented operator)"));
RNA_def_struct_identifier(ot->srna, ot->idname);
BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
@@ -167,8 +168,10 @@ void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType*, void*), void *us
ot= MEM_callocN(sizeof(wmOperatorType), "operatortype");
ot->srna= RNA_def_struct(&BLENDER_RNA, "", "OperatorProperties");
+ /* Set the default i18n context now, so that opfunc can redefine it if needed! */
+ RNA_def_struct_translation_context(ot->srna, WM_OPERATOR_DEFAULT_I18NCONTEXT);
opfunc(ot, userdata);
- RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:IFACE_("(undocumented operator)"));
+ RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description:N_("(undocumented operator)"));
RNA_def_struct_identifier(ot->srna, ot->idname);
BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
@@ -361,11 +364,12 @@ wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *nam
ot->cancel= wm_macro_cancel;
ot->poll= NULL;
- if(!ot->description)
- ot->description= IFACE_("(undocumented operator)");
+ if(!ot->description) /* XXX All ops should have a description but for now allow them not to. */
+ ot->description= N_("(undocumented operator)");
- RNA_def_struct_ui_text(ot->srna, ot->name, ot->description); // XXX All ops should have a description but for now allow them not to.
+ RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);
RNA_def_struct_identifier(ot->srna, ot->idname);
+ RNA_def_struct_translation_context(ot->srna, WM_OPERATOR_DEFAULT_I18NCONTEXT);
BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
@@ -387,8 +391,10 @@ void WM_operatortype_append_macro_ptr(void (*opfunc)(wmOperatorType*, void*), vo
ot->poll= NULL;
if(!ot->description)
- ot->description= IFACE_("(undocumented operator)");
+ ot->description= N_("(undocumented operator)");
+ /* Set the default i18n context now, so that opfunc can redefine it if needed! */
+ RNA_def_struct_translation_context(ot->srna, WM_OPERATOR_DEFAULT_I18NCONTEXT);
opfunc(ot, userdata);
RNA_def_struct_ui_text(ot->srna, ot->name, ot->description);