Fix T46268: All Hotkey "C" are unexpectedly translated in menus.

We need custom context here, those are often very short names so context collision is pretty easy.

Also some minor changes (and avoid shadowing varnames)...
This commit is contained in:
Bastien Montagne 2015-09-27 09:49:41 +02:00
parent 3bc16c3362
commit 14bac995f3
Notes: blender-bot 2023-02-14 09:36:46 +01:00
Referenced by issue #46268, All Hotkey "C" are unexpectedly translated in menus
5 changed files with 28 additions and 9 deletions

View File

@ -106,7 +106,11 @@ const char *BLT_translate_do_new_dataname(const char *msgctxt, const char *msgid
/* Default context for operator names/labels. */
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT "Operator"
/* Mark the msgid applies to several elements (needed in some cases, as english adjectives have no plural mark. :( */
/* Context for events/keymaps (necessary, since those often use one or two letters,
* easy to get collisions with other areas...). */
#define BLT_I18NCONTEXT_UI_EVENTS "UI_Events_KeyMaps"
/* Mark the msgid applies to several elements (needed in some cases, as english adjectives have no plural mark :( ). */
#define BLT_I18NCONTEXT_PLURAL "Plural"
/* ID-types contexts. */
@ -160,6 +164,7 @@ typedef struct {
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT, "default_real"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_DEFAULT_BPYRNA, "default"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "operator_default"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_UI_EVENTS, "ui_events_keymaps"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_PLURAL, "plural"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ACTION, "id_action"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_ARMATURE, "id_armature"), \

View File

@ -3814,6 +3814,7 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
prop = RNA_def_property(srna, "exit_key", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "exitkey");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_default(prop, ESCKEY);
RNA_def_property_enum_funcs(prop, NULL, "rna_GameSettings_exit_key_set", NULL);
RNA_def_property_ui_text(prop, "Exit Key", "The key that exits the Game Engine");

View File

@ -458,6 +458,7 @@ static void rna_def_keyboard_sensor(BlenderRNA *brna)
prop = RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "key");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
RNA_def_property_ui_text(prop, "Key", "");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
@ -466,6 +467,7 @@ static void rna_def_keyboard_sensor(BlenderRNA *brna)
prop = RNA_def_property(srna, "modifier_key_1", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "qual");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
RNA_def_property_update(prop, NC_LOGIC, NULL);
@ -473,6 +475,7 @@ static void rna_def_keyboard_sensor(BlenderRNA *brna)
prop = RNA_def_property(srna, "modifier_key_2", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "qual2");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
RNA_def_property_update(prop, NC_LOGIC, NULL);
@ -813,7 +816,7 @@ static void rna_def_joystick_sensor(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem event_type_items[] = {
static EnumPropertyItem event_type_joystick_items[] = {
{SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
{SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
{SENS_JOY_HAT, "HAT", 0, "Hat", ""},
@ -854,7 +857,8 @@ static void rna_def_joystick_sensor(BlenderRNA *brna)
prop = RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_enum_items(prop, event_type_joystick_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
RNA_def_property_update(prop, NC_LOGIC, NULL);

View File

@ -1674,6 +1674,7 @@ static void rna_def_event(BlenderRNA *brna)
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Type", "");
@ -2120,6 +2121,7 @@ static void rna_def_keyconfig(BlenderRNA *brna)
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_type_itemf");
RNA_def_property_ui_text(prop, "Type", "Type of event");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
@ -2177,6 +2179,7 @@ static void rna_def_keyconfig(BlenderRNA *brna)
prop = RNA_def_property(srna, "key_modifier", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "keymodifier");
RNA_def_property_enum_items(prop, event_type_items);
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
RNA_def_property_enum_funcs(prop, NULL, "rna_wmKeyMapItem_keymodifier_set", NULL);
RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier");
RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");

View File

@ -903,15 +903,21 @@ static void wm_user_modal_keymap_set_items(wmWindowManager *wm, wmKeyMap *km)
const char *WM_key_event_string(const short type, const bool compact)
{
const char *name = NULL;
EnumPropertyItem *it;
const int i = RNA_enum_from_value(event_type_items, (int)type);
if (i == -1) {
return "";
}
it = &event_type_items[i];
/* We first try enum items' description (abused as shortname here), and fall back to usual name if empty. */
if ((compact && RNA_enum_description(event_type_items, (int)type, &name) && name[0]) ||
RNA_enum_name(event_type_items, (int)type, &name))
{
return IFACE_(name);
if (compact && it->description[0]) {
/* XXX No context for enum descriptions... In practice shall not be an issue though. */
return IFACE_(it->description);
}
return "";
return CTX_IFACE_(BLT_I18NCONTEXT_UI_EVENTS, it->name);
}
/* TODO: also support (some) value, like e.g. double-click? */