From 203e6e2b416aa912583acfa1a137ffdec593c3d2 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Fri, 11 Aug 2023 11:29:42 +0200 Subject: [PATCH] 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. --- .../editors/sculpt_paint/sculpt_filter_color.cc | 17 +++++------------ source/blender/editors/util/select_utils.cc | 14 +++++++------- source/blender/makesrna/intern/rna_access.cc | 8 ++------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc index 7a85d4020f4..5a4e430bf69 100644 --- a/source/blender/editors/sculpt_paint/sculpt_filter_color.cc +++ b/source/blender/editors/sculpt_paint/sculpt_filter_color.cc @@ -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) diff --git a/source/blender/editors/util/select_utils.cc b/source/blender/editors/util/select_utils.cc index 2f44b7c09b2..75f32cc4053 100644 --- a/source/blender/editors/util/select_utils.cc +++ b/source/blender/editors/util/select_utils.cc @@ -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"); } /** \} */ diff --git a/source/blender/makesrna/intern/rna_access.cc b/source/blender/makesrna/intern/rna_access.cc index 4c67763f216..c459b0d316f 100644 --- a/source/blender/makesrna/intern/rna_access.cc +++ b/source/blender/makesrna/intern/rna_access.cc @@ -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;