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!
This commit is contained in:
parent
4e6669cee3
commit
2caa507b7e
|
@ -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__ */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue