From 150f89352b35317936d06c23954e6be17fe5193a Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Mon, 27 Mar 2023 17:24:31 +0800 Subject: [PATCH] Auto translate popup menus of MenuButton and OptionButton Currently, `auto_translate` property of a `MenuButton` or `OptionButton` won't affect its popup menu. It's okay if you want to auto translate, but requires extra setup if you don't. --- doc/classes/Control.xml | 2 +- scene/gui/menu_button.cpp | 4 ++++ scene/gui/option_button.cpp | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index 578e759a632..b26c4029be8 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -927,7 +927,7 @@ Anchors the top edge of the node to the origin, the center or the end of its parent control. It changes how the top offset updates when the node moves or changes size. You can use one of the [enum Anchor] constants for convenience. - Toggles if any text should automatically change to its translated version depending on the current locale. Note that this will not affect any internal nodes (e.g. the popup of a [MenuButton]). + Toggles if any text should automatically change to its translated version depending on the current locale. Also decides if the node's strings should be parsed for POT generation. diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index e72efbecd67..3074bc369f8 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -169,6 +169,10 @@ void MenuButton::_notification(int p_what) { menu_btn_other->get_popup()->set_focused_item(-1); } } break; + + case NOTIFICATION_TRANSLATION_CHANGED: { + popup->set_auto_translate(is_auto_translating()); + } break; } } diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index dc1d6cc73e0..7918c847cba 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -128,7 +128,10 @@ void OptionButton::_notification(int p_what) { theme_cache.arrow_icon->draw(ci, ofs, clr); } break; - case NOTIFICATION_TRANSLATION_CHANGED: + case NOTIFICATION_TRANSLATION_CHANGED: { + popup->set_auto_translate(is_auto_translating()); + [[fallthrough]]; + } case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { popup->set_layout_direction((Window::LayoutDirection)get_layout_direction()); [[fallthrough]];