From 4a838cfd0554fc4b288d4f9e0e942377633da989 Mon Sep 17 00:00:00 2001 From: Damien Picard Date: Sun, 22 Oct 2023 13:54:25 +0200 Subject: [PATCH] I18n: extract and disambiguate a few messages Extract: - "Attribute", when creating a new attribute with `GEOMETRY_OT_attribute_add()`: make the default name in the operator a null string, and set it to "Attribute" translated inside an invoke method instead. - Also for new attributes, from `BKE_id_attribute_calc_unique_name()`, for instance to create a default vertex color layer when going into Vertex Paint mode: use `DATA_()` instead of `IFACE_()`, since it represents user data. Disambiguate: - "Weight" can be the thickness of font glyphs. - "Mark as Asset" and "Clear Asset" are operator names already extracted using the Operator context. They were recently added to a manual translation in the UI, but the existing one can be reused. - "Second" as a time unit in the context of frame snapping. Some messages reported by Satoshi Yamasaki in #43295. --- scripts/startup/bl_ui/space_userpref.py | 2 +- source/blender/blenkernel/intern/attribute.cc | 4 +- .../editors/geometry/geometry_attributes.cc | 38 +++++++++++++++++-- .../interface/interface_context_menu.cc | 10 ++++- source/blender/makesrna/intern/rna_scene.cc | 1 + 5 files changed, 46 insertions(+), 9 deletions(-) diff --git a/scripts/startup/bl_ui/space_userpref.py b/scripts/startup/bl_ui/space_userpref.py index bb58c689f06..2292c6dd9c9 100644 --- a/scripts/startup/bl_ui/space_userpref.py +++ b/scripts/startup/bl_ui/space_userpref.py @@ -1076,7 +1076,7 @@ class USERPREF_PT_theme_text_style(ThemePanel, CenterAlignMixIn, Panel): col = flow.column() col.prop(font_style, "points") - col.prop(font_style, "character_weight", text="Weight") + col.prop(font_style, "character_weight", text="Weight", text_ctxt=i18n_contexts.id_text) col = flow.column(align=True) col.prop(font_style, "shadow_offset_x", text="Shadow Offset X") diff --git a/source/blender/blenkernel/intern/attribute.cc b/source/blender/blenkernel/intern/attribute.cc index 68c20c91d4e..16d3ed4b967 100644 --- a/source/blender/blenkernel/intern/attribute.cc +++ b/source/blender/blenkernel/intern/attribute.cc @@ -270,8 +270,8 @@ void BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname) const int name_maxncpy = CustomData_name_maxncpy_calc(name); /* Set default name if none specified. - * NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */ - BLI_strncpy_utf8(outname, (name && name[0]) ? name : IFACE_("Attribute"), name_maxncpy); + * NOTE: We only call DATA_() if needed to avoid locale lookup overhead. */ + BLI_strncpy_utf8(outname, (name && name[0]) ? name : DATA_("Attribute"), name_maxncpy); const char *defname = ""; /* Dummy argument, never used as `name` is never zero length. */ BLI_uniquename_cb(unique_name_cb, &data, defname, '.', outname, name_maxncpy); diff --git a/source/blender/editors/geometry/geometry_attributes.cc b/source/blender/editors/geometry/geometry_attributes.cc index 708403ab679..12603f2fd0a 100644 --- a/source/blender/editors/geometry/geometry_attributes.cc +++ b/source/blender/editors/geometry/geometry_attributes.cc @@ -24,6 +24,10 @@ #include "BKE_paint.hh" #include "BKE_report.h" +#include "BLI_string.h" + +#include "BLT_translation.h" + #include "RNA_access.hh" #include "RNA_define.hh" #include "RNA_enum_types.hh" @@ -241,6 +245,16 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int geometry_attribute_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + PropertyRNA *prop; + prop = RNA_struct_find_property(op->ptr, "name"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_string_set(op->ptr, prop, DATA_("Attribute")); + } + return WM_operator_props_popup_confirm(C, op, event); +} + void GEOMETRY_OT_attribute_add(wmOperatorType *ot) { /* identifiers */ @@ -251,7 +265,7 @@ void GEOMETRY_OT_attribute_add(wmOperatorType *ot) /* api callbacks */ ot->poll = geometry_attributes_poll; ot->exec = geometry_attribute_add_exec; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = geometry_attribute_add_invoke; /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -259,7 +273,10 @@ void GEOMETRY_OT_attribute_add(wmOperatorType *ot) /* properties */ PropertyRNA *prop; - prop = RNA_def_string(ot->srna, "name", "Attribute", MAX_NAME, "Name", "Name of new attribute"); + /* The default name of the new attribute can be translated if new data translation is enabled, + * but since the user can choose it at invoke time, the translation happens in the invoke + * callback instead of here. */ + prop = RNA_def_string(ot->srna, "name", nullptr, MAX_NAME, "Name", "Name of new attribute"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_enum(ot->srna, @@ -348,6 +365,16 @@ static int geometry_color_attribute_add_exec(bContext *C, wmOperator *op) return OPERATOR_FINISHED; } +static int geometry_color_attribute_add_invoke(bContext *C, wmOperator *op, const wmEvent *event) +{ + PropertyRNA *prop; + prop = RNA_struct_find_property(op->ptr, "name"); + if (!RNA_property_is_set(op->ptr, prop)) { + RNA_property_string_set(op->ptr, prop, DATA_("Color")); + } + return WM_operator_props_popup_confirm(C, op, event); +} + enum class ConvertAttributeMode { Generic, VertexGroup, @@ -454,7 +481,7 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot) /* api callbacks */ ot->poll = geometry_attributes_poll; ot->exec = geometry_color_attribute_add_exec; - ot->invoke = WM_operator_props_popup_confirm; + ot->invoke = geometry_color_attribute_add_invoke; ot->ui = geometry_color_attribute_add_ui; /* flags */ @@ -463,8 +490,11 @@ void GEOMETRY_OT_color_attribute_add(wmOperatorType *ot) /* properties */ PropertyRNA *prop; + /* The default name of the new attribute can be translated if new data translation is enabled, + * but since the user can choose it at invoke time, the translation happens in the invoke + * callback instead of here. */ prop = RNA_def_string( - ot->srna, "name", "Color", MAX_NAME, "Name", "Name of new color attribute"); + ot->srna, "name", nullptr, MAX_NAME, "Name", "Name of new color attribute"); RNA_def_property_flag(prop, PROP_SKIP_SAVE); prop = RNA_def_enum(ot->srna, diff --git a/source/blender/editors/interface/interface_context_menu.cc b/source/blender/editors/interface/interface_context_menu.cc index 015b3fc89e5..bd5b9314056 100644 --- a/source/blender/editors/interface/interface_context_menu.cc +++ b/source/blender/editors/interface/interface_context_menu.cc @@ -979,10 +979,16 @@ bool ui_popup_context_menu_for_button(bContext *C, uiBut *but, const wmEvent *ev * which isn't cheap to check. */ uiLayout *sub = uiLayoutColumn(layout, true); uiLayoutSetEnabled(sub, !id->asset_data); - uiItemO(sub, IFACE_("Mark as Asset"), ICON_ASSET_MANAGER, "ASSET_OT_mark_single"); + uiItemO(sub, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Mark as Asset"), + ICON_ASSET_MANAGER, + "ASSET_OT_mark_single"); sub = uiLayoutColumn(layout, true); uiLayoutSetEnabled(sub, id->asset_data); - uiItemO(sub, IFACE_("Clear Asset"), ICON_NONE, "ASSET_OT_clear_single"); + uiItemO(sub, + CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Clear Asset"), + ICON_NONE, + "ASSET_OT_clear_single"); uiItemS(layout); } diff --git a/source/blender/makesrna/intern/rna_scene.cc b/source/blender/makesrna/intern/rna_scene.cc index 1f0e9474386..87ad725f047 100644 --- a/source/blender/makesrna/intern/rna_scene.cc +++ b/source/blender/makesrna/intern/rna_scene.cc @@ -3471,6 +3471,7 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_enum_bitflag_sdna(prop, nullptr, "snap_anim_mode"); RNA_def_property_enum_items(prop, rna_enum_snap_animation_element_items); RNA_def_property_ui_text(prop, "Snap Anim Element", "Type of element to snap to"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UNIT); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, nullptr); /* header redraw */ /* image editor uses own set of snap modes */ -- 2.30.2