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.

Pull Request: https://projects.blender.org/blender/blender/pulls/114159
This commit is contained in:
Damien Picard 2023-10-22 13:54:25 +02:00 committed by Gitea
parent f48f901b3b
commit 7231ac0a52
5 changed files with 46 additions and 9 deletions

View File

@ -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")

View File

@ -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);

View File

@ -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,

View File

@ -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);
}

View File

@ -3485,6 +3485,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 */