Fix (unreported) Several OperatorType.get_name not doing translation.
`OperatorType.get_name` callback is supposed to return strings directly usable in the UI, i.e. translated if needed. Several callbacks did not, noticiably the generic `ED_select_pick_get_name` and `ED_select_circle_get_name` ones. And the `sculpt_color_filter_get_name` was not using available RNA helpers for enum items has it should have. Finally, `RNA_property_enum_name_gettexted` and `RNA_property_enum_item_from_value_gettexted` were also not using the optimal higher-level translation API. Noticed while reviewing !110776.
This commit is contained in:
@@ -420,19 +420,12 @@ static int sculpt_color_filter_invoke(bContext *C, wmOperator *op, const wmEvent
|
||||
|
||||
static const char *sculpt_color_filter_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr)
|
||||
{
|
||||
int mode = RNA_enum_get(ptr, "type");
|
||||
EnumPropertyItem *item = prop_color_filter_types;
|
||||
PropertyRNA *prop = RNA_struct_find_property(ptr, "type");
|
||||
const int value = RNA_property_enum_get(ptr, prop);
|
||||
const char *ui_name = nullptr;
|
||||
|
||||
while (item->identifier) {
|
||||
if (item->value == mode) {
|
||||
return item->name;
|
||||
}
|
||||
|
||||
item++;
|
||||
}
|
||||
|
||||
BLI_assert_unreachable();
|
||||
return "error";
|
||||
RNA_property_enum_name_gettexted(nullptr, ptr, prop, value, &ui_name);
|
||||
return ui_name;
|
||||
}
|
||||
|
||||
static void sculpt_color_filter_ui(bContext * /*C*/, wmOperator *op)
|
||||
|
||||
@@ -166,18 +166,18 @@ const char *ED_select_pick_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr)
|
||||
ED_select_pick_params_from_operator(ptr, ¶ms);
|
||||
switch (params.sel_op) {
|
||||
case SEL_OP_ADD:
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Extend)");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Extend)");
|
||||
case SEL_OP_SUB:
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Deselect)");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Deselect)");
|
||||
case SEL_OP_XOR:
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Toggle)");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select (Toggle)");
|
||||
case SEL_OP_AND:
|
||||
BLI_assert_unreachable();
|
||||
ATTR_FALLTHROUGH;
|
||||
case SEL_OP_SET:
|
||||
break;
|
||||
}
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Select");
|
||||
}
|
||||
|
||||
const char *ED_select_circle_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr)
|
||||
@@ -186,9 +186,9 @@ const char *ED_select_circle_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr)
|
||||
const eSelectOp sel_op = eSelectOp(RNA_enum_get(ptr, "mode"));
|
||||
switch (sel_op) {
|
||||
case SEL_OP_ADD:
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select (Extend)");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select (Extend)");
|
||||
case SEL_OP_SUB:
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select (Deselect)");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select (Deselect)");
|
||||
case SEL_OP_XOR:
|
||||
ATTR_FALLTHROUGH;
|
||||
case SEL_OP_AND:
|
||||
@@ -197,7 +197,7 @@ const char *ED_select_circle_get_name(wmOperatorType * /*ot*/, PointerRNA *ptr)
|
||||
case SEL_OP_SET:
|
||||
break;
|
||||
}
|
||||
return CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select");
|
||||
return CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Circle Select");
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -1851,9 +1851,7 @@ bool RNA_property_enum_name_gettexted(
|
||||
|
||||
if (result) {
|
||||
if (!(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
|
||||
if (BLT_translate_iface()) {
|
||||
*name = BLT_pgettext(prop->translation_context, *name);
|
||||
}
|
||||
*name = BLT_translate_do_iface(prop->translation_context, *name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1894,9 +1892,7 @@ bool RNA_property_enum_item_from_value_gettexted(
|
||||
const bool result = RNA_property_enum_item_from_value(C, ptr, prop, value, r_item);
|
||||
|
||||
if (result && !(prop->flag & PROP_ENUM_NO_TRANSLATE)) {
|
||||
if (BLT_translate_iface()) {
|
||||
r_item->name = BLT_pgettext(prop->translation_context, r_item->name);
|
||||
}
|
||||
r_item->name = BLT_translate_do_iface(prop->translation_context, r_item->name);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user