diff --git a/doc/classes/Control.xml b/doc/classes/Control.xml index c3ec2b9e3cd..07f41192f7c 100644 --- a/doc/classes/Control.xml +++ b/doc/classes/Control.xml @@ -937,9 +937,8 @@ 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. - Also decides if the node's strings should be parsed for POT generation. Enables whether rendering of [CanvasItem] based children should be clipped to this control's rectangle. If [code]true[/code], parts of a child which would be visibly outside of this control's rectangle will not be rendered and won't receive input. diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index ada4bd04e6d..a46bb593d47 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -186,6 +186,32 @@ [b]Note:[/b] [SceneTree]'s group methods will [i]not[/i] work on this node if not inside the tree (see [method is_inside_tree]). + + + + + + Translates a [param message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation. + This method works the same as [method Object.tr], with the addition of respecting the [member auto_translate_mode] state. + If [method Object.can_translate_messages] is [code]false[/code], or no translation is available, this method returns the [param message] without changes. See [method Object.set_message_translation]. + For detailed examples, see [url=$DOCS_URL/tutorials/i18n/internationalizing_games.html]Internationalizing games[/url]. + + + + + + + + + + Translates a [param message] or [param plural_message], using the translation catalogs configured in the Project Settings. Further [param context] can be specified to help with the translation. + This method works the same as [method Object.tr_n], with the addition of respecting the [member auto_translate_mode] state. + If [method Object.can_translate_messages] is [code]false[/code], or no translation is available, this method returns [param message] or [param plural_message], without changes. See [method Object.set_message_translation]. + The [param n] is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language. + For detailed examples, see [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url]. + [b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended to handle these cases with [method atr]. + + @@ -203,7 +229,7 @@ - Returns [code]true[/code] if the node can receive processing notifications and input callbacks ([constant NOTIFICATION_PROCESS], [method _input], etc) from the [SceneTree] and [Viewport]. The returned value depends on [member process_mode]: + Returns [code]true[/code] if the node can receive processing notifications and input callbacks ([constant NOTIFICATION_PROCESS], [method _input], etc.) from the [SceneTree] and [Viewport]. The returned value depends on [member process_mode]: - If set to [constant PROCESS_MODE_PAUSABLE], returns [code]true[/code] when the game is processing, i.e. [member SceneTree.paused] is [code]false[/code]; - If set to [constant PROCESS_MODE_WHEN_PAUSED], returns [code]true[/code] when the game is paused, i.e. [member SceneTree.paused] is [code]true[/code]; - If set to [constant PROCESS_MODE_ALWAYS], always returns [code]true[/code]; @@ -923,6 +949,10 @@ + + Defines if any text should automatically change to its translated version depending on the current locale (for nodes such as [Label], [RichTextLabel], [Window], etc.). See [enum AutoTranslateMode]. + Also decides if the node's strings should be parsed for POT generation. + An optional description to the node. It will be displayed as a tooltip when hovering over the node in the editor's Scene dock. @@ -1180,10 +1210,10 @@ Notification received when the [TextServer] is changed. - Inherits [member process_mode] from the node's parent. For the root node, it is equivalent to [constant PROCESS_MODE_PAUSABLE]. This is the default for any newly created node. + Inherits [member process_mode] from the node's parent. This is the default for any newly created node. - Stops processing when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_WHEN_PAUSED]. + Stops processing when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_WHEN_PAUSED], and the default for the root node. Process [b]only[/b] when [member SceneTree.paused] is [code]true[/code]. This is the inverse of [constant PROCESS_MODE_PAUSABLE]. @@ -1233,5 +1263,15 @@ The node will be placed at the end of the parent's children list, after any non-internal sibling. + + Inherits [member auto_translate_mode] from the node's parent. This is the default for any newly created node. + + + Always automatically translate. This is the inverse of [constant AUTO_TRANSLATE_MODE_DISABLED], and the default for the root node. + + + Never automatically translate. This is the inverse of [constant AUTO_TRANSLATE_MODE_ALWAYS]. + String parsing for POT generation will be skipped for this node and children that are set to [constant AUTO_TRANSLATE_MODE_INHERIT]. + diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index c2405f8e902..bb27ea6eb73 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -1032,7 +1032,7 @@ If [method can_translate_messages] is [code]false[/code], or no translation is available, this method returns [param message] or [param plural_message], without changes. See [method set_message_translation]. The [param n] is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language. For detailed examples, see [url=$DOCS_URL/tutorials/i18n/localization_using_gettext.html]Localization using gettext[/url]. - [b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended handling these cases with [method tr]. + [b]Note:[/b] Negative and [float] numbers may not properly apply to some countable subjects. It's recommended to handle these cases with [method tr]. diff --git a/doc/classes/Window.xml b/doc/classes/Window.xml index 57d26bf3844..63caaefe070 100644 --- a/doc/classes/Window.xml +++ b/doc/classes/Window.xml @@ -557,7 +557,7 @@ If [code]true[/code], the window will be on top of all other windows. Does not work if [member transient] is enabled. - + Toggles if any text should automatically change to its translated version depending on the current locale. diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 1ff403291fd..128bd5e7017 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -7137,14 +7137,14 @@ AnimationTrackEditor::AnimationTrackEditor() { transition_selection->add_item(TTR("Back", "Transition Type"), Tween::TRANS_BACK); transition_selection->add_item(TTR("Spring", "Transition Type"), Tween::TRANS_SPRING); transition_selection->select(Tween::TRANS_LINEAR); // Default - transition_selection->set_auto_translate(false); // Translation context is needed. + transition_selection->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Translation context is needed. ease_selection = memnew(OptionButton); ease_selection->add_item(TTR("In", "Ease Type"), Tween::EASE_IN); ease_selection->add_item(TTR("Out", "Ease Type"), Tween::EASE_OUT); ease_selection->add_item(TTR("InOut", "Ease Type"), Tween::EASE_IN_OUT); ease_selection->add_item(TTR("OutIn", "Ease Type"), Tween::EASE_OUT_IN); ease_selection->select(Tween::EASE_IN_OUT); // Default - ease_selection->set_auto_translate(false); // Translation context is needed. + ease_selection->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Translation context is needed. ease_fps = memnew(SpinBox); ease_fps->set_min(1); ease_fps->set_max(999); diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index da0182b1761..604449b04b7 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -794,7 +794,7 @@ CreateDialog::CreateDialog() { rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); recent = memnew(ItemList); - recent->set_auto_translate(false); + recent->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); rec_vb->add_margin_child(TTR("Recent:"), recent, true); recent->set_allow_reselect(true); recent->connect("item_selected", callable_mp(this, &CreateDialog::_history_selected)); diff --git a/editor/dependency_editor.cpp b/editor/dependency_editor.cpp index 4be6afbcff4..5eccc7673a1 100644 --- a/editor/dependency_editor.cpp +++ b/editor/dependency_editor.cpp @@ -398,7 +398,7 @@ DependencyEditorOwners::DependencyEditorOwners() { file_options->connect("id_pressed", callable_mp(this, &DependencyEditorOwners::_file_option)); owners = memnew(ItemList); - owners->set_auto_translate(false); + owners->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); owners->set_select_mode(ItemList::SELECT_MULTI); owners->connect("item_clicked", callable_mp(this, &DependencyEditorOwners::_list_rmb_clicked)); owners->connect("item_activated", callable_mp(this, &DependencyEditorOwners::_select_file)); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index 6c859ce2369..9c0d474f498 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -100,7 +100,7 @@ ScrollContainer *EditorAbout::_populate_list(const String &p_name, const Listadd_child(lbl); ItemList *il = memnew(ItemList); - il->set_auto_translate(false); + il->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); il->set_h_size_flags(Control::SIZE_EXPAND_FILL); il->set_same_column_width(true); il->set_auto_height(true); diff --git a/editor/editor_feature_profile.cpp b/editor/editor_feature_profile.cpp index aa44ea380b8..c08e99b2a48 100644 --- a/editor/editor_feature_profile.cpp +++ b/editor/editor_feature_profile.cpp @@ -932,7 +932,7 @@ EditorFeatureProfileManager::EditorFeatureProfileManager() { HBoxContainer *profiles_hbc = memnew(HBoxContainer); profile_list = memnew(OptionButton); profile_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); - profile_list->set_auto_translate(false); + profile_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); profiles_hbc->add_child(profile_list); profile_list->connect("item_selected", callable_mp(this, &EditorFeatureProfileManager::_profile_selected)); diff --git a/editor/editor_layouts_dialog.cpp b/editor/editor_layouts_dialog.cpp index e1b370f44ae..bd9a4ea1bff 100644 --- a/editor/editor_layouts_dialog.cpp +++ b/editor/editor_layouts_dialog.cpp @@ -114,7 +114,7 @@ EditorLayoutsDialog::EditorLayoutsDialog() { add_child(makevb); layout_names = memnew(ItemList); - layout_names->set_auto_translate(false); + layout_names->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); layout_names->set_auto_height(true); layout_names->set_custom_minimum_size(Size2(300 * EDSCALE, 50 * EDSCALE)); layout_names->set_visible(true); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 663cddc0da2..e95d0b47466 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6912,7 +6912,7 @@ EditorNode::EditorNode() { editor_layouts = memnew(PopupMenu); editor_layouts->set_name("Layouts"); - editor_layouts->set_auto_translate(false); + editor_layouts->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); settings_menu->add_child(editor_layouts); editor_layouts->connect("id_pressed", callable_mp(this, &EditorNode::_layout_menu_option)); settings_menu->add_submenu_item(TTR("Editor Layout"), "Layouts"); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index f237649c5de..46a648e1b96 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -374,7 +374,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() { option_button->set_h_size_flags(SIZE_EXPAND_FILL); option_button->set_clip_text(true); option_button->set_flat(true); - option_button->set_auto_translate(false); + option_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); default_layout->add_child(option_button); option_button->connect("item_selected", callable_mp(this, &EditorPropertyTextEnum::_option_selected)); @@ -728,7 +728,7 @@ EditorPropertyEnum::EditorPropertyEnum() { options = memnew(OptionButton); options->set_clip_text(true); options->set_flat(true); - options->set_auto_translate(false); + options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); add_child(options); add_focusable(options); options->connect("item_selected", callable_mp(this, &EditorPropertyEnum::_option_selected)); @@ -2955,7 +2955,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() { assign->set_flat(true); assign->set_h_size_flags(SIZE_EXPAND_FILL); assign->set_clip_text(true); - assign->set_auto_translate(false); + assign->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); assign->set_expand_icon(true); assign->connect("pressed", callable_mp(this, &EditorPropertyNodePath::_node_assign)); SET_DRAG_FORWARDING_CD(assign, EditorPropertyNodePath); diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 27ce27591f2..74db32df194 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -1018,7 +1018,7 @@ EditorResourcePicker::EditorResourcePicker(bool p_hide_assign_button_controls) { assign_button->set_h_size_flags(SIZE_EXPAND_FILL); assign_button->set_expand_icon(true); assign_button->set_clip_text(true); - assign_button->set_auto_translate(false); + assign_button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); SET_DRAG_FORWARDING_GCD(assign_button, EditorResourcePicker); add_child(assign_button); assign_button->connect("pressed", callable_mp(this, &EditorResourcePicker::_resource_selected)); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index 4a066b3d3e2..5de56b9d903 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -1212,7 +1212,7 @@ ProjectExportDialog::ProjectExportDialog() { preset_vb->add_child(mc); mc->set_v_size_flags(Control::SIZE_EXPAND_FILL); presets = memnew(ItemList); - presets->set_auto_translate(false); + presets->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog); mc->add_child(presets); presets->connect("item_selected", callable_mp(this, &ProjectExportDialog::_edit_preset)); diff --git a/editor/gui/editor_file_dialog.cpp b/editor/gui/editor_file_dialog.cpp index 4d1fd1f7b7e..a84a6657754 100644 --- a/editor/gui/editor_file_dialog.cpp +++ b/editor/gui/editor_file_dialog.cpp @@ -1909,7 +1909,7 @@ EditorFileDialog::EditorFileDialog() { fav_down->connect("pressed", callable_mp(this, &EditorFileDialog::_favorite_move_down)); favorites = memnew(ItemList); - favorites->set_auto_translate(false); + favorites->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); fav_vb->add_child(favorites); favorites->set_v_size_flags(Control::SIZE_EXPAND_FILL); favorites->connect("item_selected", callable_mp(this, &EditorFileDialog::_favorite_selected)); @@ -1919,7 +1919,7 @@ EditorFileDialog::EditorFileDialog() { rec_vb->set_custom_minimum_size(Size2(150, 100) * EDSCALE); rec_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); recent = memnew(ItemList); - recent->set_auto_translate(false); + recent->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); recent->set_allow_reselect(true); rec_vb->add_margin_child(TTR("Recent:"), recent, true); recent->connect("item_selected", callable_mp(this, &EditorFileDialog::_recent_selected)); @@ -1943,7 +1943,7 @@ EditorFileDialog::EditorFileDialog() { // Item (files and folders) list with context menu. item_list = memnew(ItemList); - item_list->set_auto_translate(false); + item_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); item_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); item_list->connect("item_clicked", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_clicked)); item_list->connect("empty_clicked", callable_mp(this, &EditorFileDialog::_item_list_empty_clicked)); diff --git a/editor/gui/editor_object_selector.cpp b/editor/gui/editor_object_selector.cpp index c97d68fb35d..fd46788c738 100644 --- a/editor/gui/editor_object_selector.cpp +++ b/editor/gui/editor_object_selector.cpp @@ -238,7 +238,7 @@ EditorObjectSelector::EditorObjectSelector(EditorSelectionHistory *p_history) { current_object_label = memnew(Label); current_object_label->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); current_object_label->set_h_size_flags(SIZE_EXPAND_FILL); - current_object_label->set_auto_translate(false); + current_object_label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); main_hb->add_child(current_object_label); sub_objects_icon = memnew(TextureRect); @@ -247,7 +247,7 @@ EditorObjectSelector::EditorObjectSelector(EditorSelectionHistory *p_history) { main_hb->add_child(sub_objects_icon); sub_objects_menu = memnew(PopupMenu); - sub_objects_menu->set_auto_translate(false); + sub_objects_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); add_child(sub_objects_menu); sub_objects_menu->connect("about_to_popup", callable_mp(this, &EditorObjectSelector::_about_to_show)); sub_objects_menu->connect("id_pressed", callable_mp(this, &EditorObjectSelector::_id_pressed)); diff --git a/editor/gui/editor_scene_tabs.cpp b/editor/gui/editor_scene_tabs.cpp index 915b161372d..476b06f52bb 100644 --- a/editor/gui/editor_scene_tabs.cpp +++ b/editor/gui/editor_scene_tabs.cpp @@ -377,7 +377,7 @@ EditorSceneTabs::EditorSceneTabs() { scene_tabs->set_tab_close_display_policy((TabBar::CloseButtonDisplayPolicy)EDITOR_GET("interface/scene_tabs/display_close_button").operator int()); scene_tabs->set_max_tab_width(int(EDITOR_GET("interface/scene_tabs/maximum_width")) * EDSCALE); scene_tabs->set_drag_to_rearrange_enabled(true); - scene_tabs->set_auto_translate(false); + scene_tabs->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); scene_tabs->set_h_size_flags(Control::SIZE_EXPAND_FILL); tabbar_container->add_child(scene_tabs); diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index 6c8e8b75efc..7fb52251cef 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -1601,7 +1601,7 @@ void SceneTreeDialog::set_valid_types(const Vector &p_valid) { Label *label = memnew(Label); hb->add_child(label); label->set_text(name); - label->set_auto_translate(false); + label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); } show_all_nodes->show(); diff --git a/editor/history_dock.cpp b/editor/history_dock.cpp index 6ec240fdf08..7375abb65ae 100644 --- a/editor/history_dock.cpp +++ b/editor/history_dock.cpp @@ -248,7 +248,7 @@ HistoryDock::HistoryDock() { global_history_checkbox->connect("toggled", callable_mp(this, &HistoryDock::refresh_history).unbind(1)); action_list = memnew(ItemList); - action_list->set_auto_translate(false); + action_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); add_child(action_list); action_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); action_list->connect("item_selected", callable_mp(this, &HistoryDock::seek_history)); diff --git a/editor/plugins/animation_blend_space_1d_editor.cpp b/editor/plugins/animation_blend_space_1d_editor.cpp index 92b3569c06b..d52a2057af3 100644 --- a/editor/plugins/animation_blend_space_1d_editor.cpp +++ b/editor/plugins/animation_blend_space_1d_editor.cpp @@ -804,7 +804,7 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() { animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); animations_menu->set_name("AddAnimations"); - animations_menu->set_auto_translate(false); + animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeBlendSpace1DEditor::_add_animation_type)); open_file = memnew(EditorFileDialog); diff --git a/editor/plugins/animation_blend_space_2d_editor.cpp b/editor/plugins/animation_blend_space_2d_editor.cpp index 9e82368a71e..30104f0ab43 100644 --- a/editor/plugins/animation_blend_space_2d_editor.cpp +++ b/editor/plugins/animation_blend_space_2d_editor.cpp @@ -1083,7 +1083,7 @@ AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() { animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); animations_menu->set_name("AddAnimations"); - animations_menu->set_auto_translate(false); + animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_add_animation_type)); open_file = memnew(EditorFileDialog); diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 99151ac7602..78b46479752 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -239,7 +239,7 @@ void AnimationNodeBlendTreeEditor::update_graph() { MenuButton *mb = memnew(MenuButton); mb->set_text(anim->get_animation()); mb->set_icon(get_editor_theme_icon(SNAME("Animation"))); - mb->set_auto_translate(false); + mb->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); mb->set_disabled(read_only); Array options; diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index b08d2e966d6..3f9f609dbac 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -1886,7 +1886,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug animation->set_h_size_flags(SIZE_EXPAND_FILL); animation->set_tooltip_text(TTR("Display list of animations in player.")); animation->set_clip_text(true); - animation->set_auto_translate(false); + animation->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); autoplay = memnew(Button); autoplay->set_theme_type_variation("FlatButton"); @@ -1985,7 +1985,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug blend_editor.tree->connect(SNAME("item_edited"), callable_mp(this, &AnimationPlayerEditor::_blend_edited)); blend_editor.next = memnew(OptionButton); - blend_editor.next->set_auto_translate(false); + blend_editor.next->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); blend_vb->add_margin_child(TTR("Next (Auto Queue):"), blend_editor.next); autoplay->connect(SNAME("pressed"), callable_mp(this, &AnimationPlayerEditor::_autoplay_pressed)); diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index 9f8fbc6dfce..08c52f6d12d 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -1779,7 +1779,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { animations_menu = memnew(PopupMenu); menu->add_child(animations_menu); animations_menu->set_name("AddAnimations"); - animations_menu->set_auto_translate(false); + animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeStateMachineEditor::_add_animation_type)); connect_menu = memnew(PopupMenu); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 9d7305f9ae7..132b85b090e 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5544,7 +5544,7 @@ CanvasItemEditor::CanvasItemEditor() { selection_menu = memnew(PopupMenu); add_child(selection_menu); selection_menu->set_min_size(Vector2(100, 0)); - selection_menu->set_auto_translate(false); + selection_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); selection_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_selection_result_pressed)); selection_menu->connect("popup_hide", callable_mp(this, &CanvasItemEditor::_selection_menu_hide), CONNECT_DEFERRED); diff --git a/editor/plugins/packed_scene_translation_parser_plugin.cpp b/editor/plugins/packed_scene_translation_parser_plugin.cpp index c5c791ca8eb..04d4c6d779d 100644 --- a/editor/plugins/packed_scene_translation_parser_plugin.cpp +++ b/editor/plugins/packed_scene_translation_parser_plugin.cpp @@ -52,32 +52,58 @@ Error PackedSceneEditorTranslationParserPlugin::parse_file(const String &p_path, Ref state = Ref(loaded_res)->get_state(); Vector parsed_strings; - List tabcontainer_paths; + Vector> atr_owners; + Vector tabcontainer_paths; for (int i = 0; i < state->get_node_count(); i++) { String node_type = state->get_node_type(i); - bool is_control = ClassDB::is_parent_class(node_type, "Control"); - if (!is_control && !ClassDB::is_parent_class(node_type, "Window")) { - continue; + String parent_path = state->get_node_path(i, true); + + // Find the `auto_translate_mode` property. + bool auto_translating = true; + bool auto_translate_mode_found = false; + for (int j = 0; j < state->get_node_property_count(i); j++) { + if (state->get_node_property_name(i, j) != "auto_translate_mode") { + continue; + } + + auto_translate_mode_found = true; + + int idx_last = atr_owners.size() - 1; + if (idx_last > 0 && !parent_path.begins_with(atr_owners[idx_last].first)) { + // Switch to the previous auto translation owner this was nested in, if that was the case. + atr_owners.remove_at(idx_last); + idx_last -= 1; + } + + int auto_translate_mode = (int)state->get_node_property_value(i, j); + if (auto_translate_mode == Node::AUTO_TRANSLATE_MODE_DISABLED) { + auto_translating = false; + } + + atr_owners.push_back(Pair(state->get_node_path(i), auto_translating)); + + break; } - // Find the `auto_translate` property, and abort the string parsing of the node if disabled. - bool auto_translating = true; - for (int j = 0; j < state->get_node_property_count(i); j++) { - if (state->get_node_property_name(i, j) == "auto_translate" && (bool)state->get_node_property_value(i, j) == false) { - auto_translating = false; - break; + // If `auto_translate_mode` wasn't found, that means it is set to its default value (`AUTO_TRANSLATE_MODE_INHERIT`). + if (!auto_translate_mode_found) { + int idx_last = atr_owners.size() - 1; + if (idx_last > 0 && atr_owners[idx_last].first == parent_path) { + auto_translating = atr_owners[idx_last].second; + } else { + atr_owners.push_back(Pair(state->get_node_path(i), true)); } } // Parse the names of children of `TabContainer`s, as they are used for tab titles. if (!tabcontainer_paths.is_empty()) { - String parent_path = state->get_node_path(i, true); if (!parent_path.begins_with(tabcontainer_paths[tabcontainer_paths.size() - 1])) { // Switch to the previous `TabContainer` this was nested in, if that was the case. - tabcontainer_paths.pop_back(); + tabcontainer_paths.remove_at(tabcontainer_paths.size() - 1); } - if (is_control && auto_translating && !tabcontainer_paths.is_empty() && parent_path == tabcontainer_paths[tabcontainer_paths.size() - 1]) { + if (auto_translating && !tabcontainer_paths.is_empty() && ClassDB::is_parent_class(node_type, "Control") && + parent_path == tabcontainer_paths[tabcontainer_paths.size() - 1]) { parsed_strings.push_back(state->get_node_name(i)); } } diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 335aa33c4a6..e6a1b76c78e 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -3872,7 +3872,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { scripts_vbox->add_child(filter_scripts); script_list = memnew(ItemList); - script_list->set_auto_translate(false); + script_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); scripts_vbox->add_child(script_list); script_list->set_custom_minimum_size(Size2(150, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing script_list->set_v_size_flags(SIZE_EXPAND_FILL); @@ -3917,7 +3917,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { overview_vbox->add_child(filter_methods); members_overview = memnew(ItemList); - members_overview->set_auto_translate(false); + members_overview->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); overview_vbox->add_child(members_overview); members_overview->set_allow_reselect(true); @@ -3926,7 +3926,7 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) { members_overview->set_allow_rmb_select(true); help_overview = memnew(ItemList); - help_overview->set_auto_translate(false); + help_overview->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); overview_vbox->add_child(help_overview); help_overview->set_allow_reselect(true); help_overview->set_custom_minimum_size(Size2(0, 60) * EDSCALE); //need to give a bit of limit to avoid it from disappearing diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index a018ec095ba..8625e468fa6 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -659,7 +659,7 @@ ShaderEditorPlugin::ShaderEditorPlugin() { window_wrapper->connect("window_visibility_changed", callable_mp(this, &ShaderEditorPlugin::_window_changed)); shader_list = memnew(ItemList); - shader_list->set_auto_translate(false); + shader_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); shader_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); vb->add_child(shader_list); shader_list->connect("item_selected", callable_mp(this, &ShaderEditorPlugin::_shader_selected)); diff --git a/editor/plugins/shader_file_editor_plugin.cpp b/editor/plugins/shader_file_editor_plugin.cpp index 69ad2741142..38cc51d3c0e 100644 --- a/editor/plugins/shader_file_editor_plugin.cpp +++ b/editor/plugins/shader_file_editor_plugin.cpp @@ -256,7 +256,7 @@ ShaderFileEditor::ShaderFileEditor() { add_child(main_hs); versions = memnew(ItemList); - versions->set_auto_translate(false); + versions->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); versions->connect("item_selected", callable_mp(this, &ShaderFileEditor::_version_selected)); versions->set_custom_minimum_size(Size2i(200 * EDSCALE, 0)); main_hs->add_child(versions); diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 2476d28986c..2495d28e3cd 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -1880,7 +1880,7 @@ SpriteFramesEditor::SpriteFramesEditor() { add_child(file); frame_list = memnew(ItemList); - frame_list->set_auto_translate(false); + frame_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); frame_list->set_v_size_flags(SIZE_EXPAND_FILL); frame_list->set_icon_mode(ItemList::ICON_MODE_TOP); frame_list->set_texture_filter(TEXTURE_FILTER_NEAREST_WITH_MIPMAPS); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 53bdf79d870..8f369b23b2b 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -2246,7 +2246,7 @@ ThemeTypeDialog::ThemeTypeDialog() { add_type_vb->add_child(add_type_options_label); add_type_options = memnew(ItemList); - add_type_options->set_auto_translate(false); + add_type_options->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); add_type_options->set_v_size_flags(Control::SIZE_EXPAND_FILL); add_type_vb->add_child(add_type_options); add_type_options->connect("item_selected", callable_mp(this, &ThemeTypeDialog::_add_type_options_cbk)); @@ -3416,7 +3416,7 @@ ThemeTypeEditor::ThemeTypeEditor() { theme_type_list = memnew(OptionButton); theme_type_list->set_h_size_flags(SIZE_EXPAND_FILL); theme_type_list->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_ELLIPSIS); - theme_type_list->set_auto_translate(false); + theme_type_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); type_list_hb->add_child(theme_type_list); theme_type_list->connect("item_selected", callable_mp(this, &ThemeTypeEditor::_list_type_selected)); diff --git a/editor/plugins/tiles/atlas_merging_dialog.cpp b/editor/plugins/tiles/atlas_merging_dialog.cpp index d03445b4129..e49ba5844ac 100644 --- a/editor/plugins/tiles/atlas_merging_dialog.cpp +++ b/editor/plugins/tiles/atlas_merging_dialog.cpp @@ -311,7 +311,7 @@ AtlasMergingDialog::AtlasMergingDialog() { // Atlas sources item list. atlas_merging_atlases_list = memnew(ItemList); - atlas_merging_atlases_list->set_auto_translate(false); + atlas_merging_atlases_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); atlas_merging_atlases_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); atlas_merging_atlases_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); atlas_merging_atlases_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); diff --git a/editor/plugins/tiles/tile_map_layer_editor.cpp b/editor/plugins/tiles/tile_map_layer_editor.cpp index bc19735c4f7..e2f6cb0f389 100644 --- a/editor/plugins/tiles/tile_map_layer_editor.cpp +++ b/editor/plugins/tiles/tile_map_layer_editor.cpp @@ -2401,7 +2401,7 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { sources_bottom_actions->add_child(source_sort_button); sources_list = memnew(ItemList); - sources_list->set_auto_translate(false); + sources_list->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); sources_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); sources_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); @@ -2441,7 +2441,7 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { // Scenes collection source. scene_tiles_list = memnew(ItemList); - scene_tiles_list->set_auto_translate(false); + scene_tiles_list->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); scene_tiles_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); scene_tiles_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); scene_tiles_list->set_select_mode(ItemList::SELECT_MULTI); @@ -2467,7 +2467,7 @@ TileMapLayerEditorTilesPlugin::TileMapLayerEditorTilesPlugin() { int thumbnail_size = 64; patterns_item_list = memnew(ItemList); - patterns_item_list->set_auto_translate(false); + patterns_item_list->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); patterns_item_list->set_max_columns(0); patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP); patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2); @@ -3529,7 +3529,7 @@ TileMapLayerEditorTerrainsPlugin::TileMapLayerEditorTerrainsPlugin() { tilemap_tab_terrains->add_child(terrains_tree); terrains_tile_list = memnew(ItemList); - terrains_tile_list->set_auto_translate(false); + terrains_tile_list->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); terrains_tile_list->set_h_size_flags(Control::SIZE_EXPAND_FILL); terrains_tile_list->set_max_columns(0); terrains_tile_list->set_same_column_width(true); diff --git a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp index 4a0b5e21174..ca4ffeecc22 100644 --- a/editor/plugins/tiles/tile_proxies_manager_dialog.cpp +++ b/editor/plugins/tiles/tile_proxies_manager_dialog.cpp @@ -345,7 +345,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(source_level_label); source_level_list = memnew(ItemList); - source_level_list->set_auto_translate(false); + source_level_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); source_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); source_level_list->set_select_mode(ItemList::SELECT_MULTI); source_level_list->set_allow_rmb_select(true); @@ -357,7 +357,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(coords_level_label); coords_level_list = memnew(ItemList); - coords_level_list->set_auto_translate(false); + coords_level_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); coords_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); coords_level_list->set_select_mode(ItemList::SELECT_MULTI); coords_level_list->set_allow_rmb_select(true); @@ -369,7 +369,7 @@ TileProxiesManagerDialog::TileProxiesManagerDialog() { vbox_container->add_child(alternative_level_label); alternative_level_list = memnew(ItemList); - alternative_level_list->set_auto_translate(false); + alternative_level_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); alternative_level_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); alternative_level_list->set_select_mode(ItemList::SELECT_MULTI); alternative_level_list->set_allow_rmb_select(true); diff --git a/editor/plugins/tiles/tile_set_editor.cpp b/editor/plugins/tiles/tile_set_editor.cpp index bb950dbf635..06fcfbfb418 100644 --- a/editor/plugins/tiles/tile_set_editor.cpp +++ b/editor/plugins/tiles/tile_set_editor.cpp @@ -854,7 +854,7 @@ TileSetEditor::TileSetEditor() { p->set_item_checked(TilesEditorUtils::SOURCE_SORT_ID, true); sources_list = memnew(ItemList); - sources_list->set_auto_translate(false); + sources_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); sources_list->set_fixed_icon_size(Size2(60, 60) * EDSCALE); sources_list->set_h_size_flags(SIZE_EXPAND_FILL); sources_list->set_v_size_flags(SIZE_EXPAND_FILL); @@ -934,7 +934,7 @@ TileSetEditor::TileSetEditor() { //// Patterns //// int thumbnail_size = 64; patterns_item_list = memnew(ItemList); - patterns_item_list->set_auto_translate(false); + patterns_item_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); patterns_item_list->set_max_columns(0); patterns_item_list->set_icon_mode(ItemList::ICON_MODE_TOP); patterns_item_list->set_fixed_column_width(thumbnail_size * 3 / 2); diff --git a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp index 6224ab72dcd..1529ddadb60 100644 --- a/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp +++ b/editor/plugins/tiles/tile_set_scenes_collection_source_editor.cpp @@ -560,7 +560,7 @@ TileSetScenesCollectionSourceEditor::TileSetScenesCollectionSourceEditor() { split_container_right_side->add_child(right_vbox_container); scene_tiles_list = memnew(ItemList); - scene_tiles_list->set_auto_translate(false); + scene_tiles_list->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); scene_tiles_list->set_h_size_flags(SIZE_EXPAND_FILL); scene_tiles_list->set_v_size_flags(SIZE_EXPAND_FILL); SET_DRAG_FORWARDING_CDU(scene_tiles_list, TileSetScenesCollectionSourceEditor); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index ddecf31352c..c69e85454fc 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -573,7 +573,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool String prop_name = dp.name.strip_edges(); if (!prop_name.is_empty()) { Label *label = memnew(Label); - label->set_auto_translate(false); // TODO: Implement proper translation switch. + label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. label->set_text(prop_name + ":"); hbox->add_child(label); } @@ -845,7 +845,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool hb->add_child(remove_btn); } else { Label *label = memnew(Label); - label->set_auto_translate(false); // TODO: Implement proper translation switch. + label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. label->set_text(name_left); label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact hb->add_child(label); @@ -895,7 +895,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool type_box->connect("item_selected", callable_mp(editor, &VisualShaderEditor::_change_output_port_type).bind(p_id, i), CONNECT_DEFERRED); } else { Label *label = memnew(Label); - label->set_auto_translate(false); // TODO: Implement proper translation switch. + label->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. label->set_text(name_right); label->add_theme_style_override("normal", editor->get_theme_stylebox(SNAME("label_style"), SNAME("VShaderEditor"))); //more compact hb->add_child(label); @@ -6771,7 +6771,7 @@ public: } else { prop_name_str = prop_name_str.capitalize() + ":"; } - prop_name->set_auto_translate(false); // TODO: Implement proper translation switch. + prop_name->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // TODO: Implement proper translation switch. prop_name->set_text(prop_name_str); prop_name->set_visible(false); hbox->add_child(prop_name); diff --git a/editor/project_manager/project_list.cpp b/editor/project_manager/project_list.cpp index 67aaa855013..234390c136f 100644 --- a/editor/project_manager/project_list.cpp +++ b/editor/project_manager/project_list.cpp @@ -238,7 +238,7 @@ ProjectListItemControl::ProjectListItemControl() { main_vbox->add_child(title_hb); project_title = memnew(Label); - project_title->set_auto_translate(false); + project_title->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); project_title->set_name("ProjectName"); project_title->set_h_size_flags(Control::SIZE_EXPAND_FILL); project_title->set_clip_text(true); diff --git a/editor/project_manager/project_tag.cpp b/editor/project_manager/project_tag.cpp index de9213177b3..8fb05b549e2 100644 --- a/editor/project_manager/project_tag.cpp +++ b/editor/project_manager/project_tag.cpp @@ -66,7 +66,7 @@ ProjectTag::ProjectTag(const String &p_text, bool p_display_close) { button = memnew(Button); add_child(button); - button->set_auto_translate(false); + button->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); button->set_text(p_text.capitalize()); button->set_focus_mode(FOCUS_NONE); button->set_icon_alignment(HORIZONTAL_ALIGNMENT_RIGHT); diff --git a/editor/scene_create_dialog.cpp b/editor/scene_create_dialog.cpp index ef700d83525..4c22b37d9db 100644 --- a/editor/scene_create_dialog.cpp +++ b/editor/scene_create_dialog.cpp @@ -275,7 +275,7 @@ SceneCreateDialog::SceneCreateDialog() { root_name_edit = memnew(LineEdit); gc->add_child(root_name_edit); root_name_edit->set_tooltip_text(TTR("When empty, the root node name is derived from the scene name based on the \"editor/naming/node_name_casing\" project setting.")); - root_name_edit->set_auto_translate(false); + root_name_edit->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); root_name_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); root_name_edit->connect("text_submitted", callable_mp(this, &SceneCreateDialog::accept_create).unbind(1)); } diff --git a/modules/gridmap/editor/grid_map_editor_plugin.cpp b/modules/gridmap/editor/grid_map_editor_plugin.cpp index b8902694c9e..c6b68e9d347 100644 --- a/modules/gridmap/editor/grid_map_editor_plugin.cpp +++ b/modules/gridmap/editor/grid_map_editor_plugin.cpp @@ -1316,7 +1316,7 @@ GridMapEditor::GridMapEditor() { EDITOR_DEF("editors/grid_map/preview_size", 64); mesh_library_palette = memnew(ItemList); - mesh_library_palette->set_auto_translate(false); + mesh_library_palette->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); add_child(mesh_library_palette); mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL); mesh_library_palette->connect("gui_input", callable_mp(this, &GridMapEditor::_mesh_library_palette_input)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index b9b68127dbe..2124ffb8060 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -268,6 +268,7 @@ String Control::properties_managed_by_container[] = { bool Control::_set(const StringName &p_name, const Variant &p_value) { ERR_MAIN_THREAD_GUARD_V(false); String name = p_name; + if (!name.begins_with("theme_override")) { return false; } @@ -309,7 +310,6 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { } else { return false; } - } else { if (name.begins_with("theme_override_icons/")) { String dname = name.get_slicec('/', 1); @@ -333,12 +333,14 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { return false; } } + return true; } bool Control::_get(const StringName &p_name, Variant &r_ret) const { ERR_MAIN_THREAD_GUARD_V(false); String sname = p_name; + if (!sname.begins_with("theme_override")) { return false; } @@ -2996,7 +2998,6 @@ void Control::set_layout_direction(Control::LayoutDirection p_direction) { ERR_FAIL_INDEX((int)p_direction, 4); data.layout_dir = p_direction; - data.is_rtl_dirty = true; propagate_notification(NOTIFICATION_LAYOUT_DIRECTION_CHANGED); } @@ -3097,21 +3098,17 @@ bool Control::is_localizing_numeral_system() const { return data.localize_numeral_system; } +#ifndef DISABLE_DEPRECATED void Control::set_auto_translate(bool p_enable) { ERR_MAIN_THREAD_GUARD; - if (p_enable == data.auto_translate) { - return; - } - - data.auto_translate = p_enable; - - notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED); + set_auto_translate_mode(p_enable ? AUTO_TRANSLATE_MODE_ALWAYS : AUTO_TRANSLATE_MODE_DISABLED); } bool Control::is_auto_translating() const { ERR_READ_THREAD_GUARD_V(false); - return data.auto_translate; + return can_auto_translate(); } +#endif // Extra properties. @@ -3172,14 +3169,6 @@ void Control::_notification(int p_notification) { } break; case NOTIFICATION_ENTER_TREE: { -#ifdef TOOLS_ENABLED - if (is_part_of_edited_scene()) { - // Don't translate Controls on scene when inside editor. - set_message_translation(false); - notification(NOTIFICATION_TRANSLATION_CHANGED); - } -#endif - // Emits NOTIFICATION_THEME_CHANGED internally. set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this)); } break; @@ -3192,6 +3181,7 @@ void Control::_notification(int p_notification) { case NOTIFICATION_EXIT_TREE: { set_theme_context(nullptr, false); + release_focus(); get_viewport()->_gui_remove_control(this); } break; @@ -3506,8 +3496,10 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_layout_direction"), &Control::get_layout_direction); ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Control::is_layout_rtl); +#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate); ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating); +#endif ClassDB::bind_method(D_METHOD("set_localize_numeral_system", "enable"), &Control::set_localize_numeral_system); ClassDB::bind_method(D_METHOD("is_localizing_numeral_system"), &Control::is_localizing_numeral_system); @@ -3558,9 +3550,12 @@ void Control::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio"); ADD_GROUP("Localization", ""); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "localize_numeral_system"), "set_localize_numeral_system", "is_localizing_numeral_system"); +#ifndef DISABLE_DEPRECATED + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_auto_translate", "is_auto_translating"); +#endif + ADD_GROUP("Tooltip", "tooltip_"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "tooltip_text", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip_text", "get_tooltip_text"); diff --git a/scene/gui/control.h b/scene/gui/control.h index e0bd624edf7..8bcd9554577 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -253,7 +253,6 @@ private: bool is_rtl_dirty = true; bool is_rtl = false; - bool auto_translate = true; bool localize_numeral_system = true; // Extra properties. @@ -624,11 +623,10 @@ public: void set_localize_numeral_system(bool p_enable); bool is_localizing_numeral_system() const; +#ifndef DISABLE_DEPRECATED void set_auto_translate(bool p_enable); bool is_auto_translating() const; - _FORCE_INLINE_ String atr(const String p_string) const { - return is_auto_translating() ? tr(p_string) : p_string; - }; +#endif // Extra properties. diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 080b6873377..89c627a7a80 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -149,10 +149,6 @@ 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 45cc9623be5..8fc21c077b7 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -127,10 +127,7 @@ void OptionButton::_notification(int p_what) { theme_cache.arrow_icon->draw(ci, ofs, clr); } break; - case NOTIFICATION_TRANSLATION_CHANGED: { - popup->set_auto_translate(is_auto_translating()); - [[fallthrough]]; - } + case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: { popup->set_layout_direction((Window::LayoutDirection)get_layout_direction()); [[fallthrough]]; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index dfbc9406600..77e00e4ab43 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -99,6 +99,26 @@ void Node::_notification(int p_notification) { } } + // Update auto translate mode. + if (data.auto_translate_mode == AUTO_TRANSLATE_MODE_INHERIT && !data.parent) { + ERR_PRINT("The root node can't be set to Inherit auto translate mode, reverting to Always instead."); + data.auto_translate_mode = AUTO_TRANSLATE_MODE_ALWAYS; + } + data.is_auto_translate_dirty = true; + +#ifdef TOOLS_ENABLED + // Don't translate UI elements when they're being edited. + if (is_part_of_edited_scene()) { + set_message_translation(false); + } else if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) { + notification(NOTIFICATION_TRANSLATION_CHANGED); + } +#else + if (data.auto_translate_mode != AUTO_TRANSLATE_MODE_DISABLED) { + notification(NOTIFICATION_TRANSLATION_CHANGED); + } +#endif + if (data.input) { add_to_group("_vp_input" + itos(get_viewport()->get_instance_id())); } @@ -136,11 +156,11 @@ void Node::_notification(int p_notification) { remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_id())); } - // Remove from processing first + // Remove from processing first. if (_is_any_processing()) { _remove_from_process_thread_group(); } - // Remove the process group + // Remove the process group. if (data.process_thread_group_owner == this) { _remove_process_group(); } @@ -217,6 +237,12 @@ void Node::_notification(int p_notification) { memdelete(child); } } break; + + case NOTIFICATION_TRANSLATION_CHANGED: { + if (data.inside_tree) { + data.is_auto_translate_dirty = true; + } + } break; } } @@ -1149,6 +1175,49 @@ bool Node::is_processing_unhandled_key_input() const { return data.unhandled_key_input; } +void Node::set_auto_translate_mode(AutoTranslateMode p_mode) { + ERR_THREAD_GUARD + if (data.auto_translate_mode == p_mode) { + return; + } + + if (p_mode == AUTO_TRANSLATE_MODE_INHERIT && data.inside_tree && !data.parent) { + ERR_FAIL_MSG("The root node can't be set to Inherit auto translate mode."); + } + + data.auto_translate_mode = p_mode; + data.is_auto_translating = p_mode != AUTO_TRANSLATE_MODE_DISABLED; + data.is_auto_translate_dirty = true; + + propagate_notification(NOTIFICATION_TRANSLATION_CHANGED); +} + +Node::AutoTranslateMode Node::get_auto_translate_mode() const { + return data.auto_translate_mode; +} + +bool Node::can_auto_translate() const { + ERR_READ_THREAD_GUARD_V(false); + if (!data.is_auto_translate_dirty || data.auto_translate_mode != AUTO_TRANSLATE_MODE_INHERIT) { + return data.is_auto_translating; + } + + data.is_auto_translate_dirty = false; + + Node *parent = data.parent; + while (parent) { + if (parent->data.auto_translate_mode == AUTO_TRANSLATE_MODE_INHERIT) { + parent = parent->data.parent; + continue; + } + + data.is_auto_translating = parent->data.auto_translate_mode == AUTO_TRANSLATE_MODE_ALWAYS; + break; + } + + return data.is_auto_translating; +} + StringName Node::get_name() const { return data.name; } @@ -3488,6 +3557,9 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("set_physics_process_internal", "enable"), &Node::set_physics_process_internal); ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal); + ClassDB::bind_method(D_METHOD("set_auto_translate_mode", "mode"), &Node::set_auto_translate_mode); + ClassDB::bind_method(D_METHOD("get_auto_translate_mode"), &Node::get_auto_translate_mode); + ClassDB::bind_method(D_METHOD("get_window"), &Node::get_window); ClassDB::bind_method(D_METHOD("get_last_exclusive_window"), &Node::get_last_exclusive_window); ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree); @@ -3525,6 +3597,9 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("set_unique_name_in_owner", "enable"), &Node::set_unique_name_in_owner); ClassDB::bind_method(D_METHOD("is_unique_name_in_owner"), &Node::is_unique_name_in_owner); + ClassDB::bind_method(D_METHOD("atr", "message", "context"), &Node::atr, DEFVAL("")); + ClassDB::bind_method(D_METHOD("atr_n", "message", "plural_message", "n", "context"), &Node::atr_n, DEFVAL("")); + #ifdef TOOLS_ENABLED ClassDB::bind_method(D_METHOD("_set_property_pinned", "property", "pinned"), &Node::set_property_pinned); #endif @@ -3635,6 +3710,10 @@ void Node::_bind_methods() { BIND_ENUM_CONSTANT(INTERNAL_MODE_FRONT); BIND_ENUM_CONSTANT(INTERNAL_MODE_BACK); + BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_INHERIT); + BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_ALWAYS); + BIND_ENUM_CONSTANT(AUTO_TRANSLATE_MODE_DISABLED); + ADD_SIGNAL(MethodInfo("ready")); ADD_SIGNAL(MethodInfo("renamed")); ADD_SIGNAL(MethodInfo("tree_entered")); @@ -3657,11 +3736,15 @@ void Node::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Inherit,Pausable,When Paused,Always,Disabled"), "set_process_mode", "get_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_priority"), "set_process_priority", "get_process_priority"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_physics_priority"), "set_physics_process_priority", "get_physics_process_priority"); + ADD_SUBGROUP("Thread Group", "process_thread"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_group", PROPERTY_HINT_ENUM, "Inherit,Main Thread,Sub Thread"), "set_process_thread_group", "get_process_thread_group"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_group_order"), "set_process_thread_group_order", "get_process_thread_group_order"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_thread_messages", PROPERTY_HINT_FLAGS, "Process,Physics Process"), "set_process_thread_messages", "get_process_thread_messages"); + ADD_GROUP("Auto Translate", "auto_translate_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "auto_translate_mode", PROPERTY_HINT_ENUM, "Inherit,Always,Disabled"), "set_auto_translate_mode", "get_auto_translate_mode"); + ADD_GROUP("Editor Description", "editor_"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "editor_description", PROPERTY_HINT_MULTILINE_TEXT), "set_editor_description", "get_editor_description"); diff --git a/scene/main/node.h b/scene/main/node.h index 5d246cc18e1..bbbdb87a328 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -108,6 +108,12 @@ public: INTERNAL_MODE_BACK, }; + enum AutoTranslateMode { + AUTO_TRANSLATE_MODE_INHERIT, + AUTO_TRANSLATE_MODE_ALWAYS, + AUTO_TRANSLATE_MODE_DISABLED, + }; + struct Comparator { bool operator()(const Node *p_a, const Node *p_b) const { return p_b->is_greater_than(p_a); } }; @@ -211,6 +217,10 @@ private: bool display_folded = false; bool editable_instance = false; + AutoTranslateMode auto_translate_mode = AUTO_TRANSLATE_MODE_INHERIT; + mutable bool is_auto_translating = true; + mutable bool is_auto_translate_dirty = true; + mutable NodePath *path_cache = nullptr; } data; @@ -506,6 +516,7 @@ public: void propagate_call(const StringName &p_method, const Array &p_args = Array(), const bool p_parent_first = false); /* PROCESSING */ + void set_physics_process(bool p_process); double get_physics_process_delta_time() const; bool is_physics_processing() const; @@ -647,6 +658,7 @@ public: void set_display_folded(bool p_folded); bool is_displayed_folded() const; + /* NETWORK */ virtual void set_multiplayer_authority(int p_peer_id, bool p_recursive = true); @@ -666,6 +678,17 @@ public: Ref get_multiplayer() const; + /* INTERNATIONALIZATION */ + + void set_auto_translate_mode(AutoTranslateMode p_mode); + AutoTranslateMode get_auto_translate_mode() const; + bool can_auto_translate() const; + + _FORCE_INLINE_ String atr(const String p_message, const StringName p_context = "") const { return can_auto_translate() ? tr(p_message, p_context) : p_message; } + _FORCE_INLINE_ String atr_n(const String p_message, const StringName &p_message_plural, int p_n, const StringName p_context = "") const { return can_auto_translate() ? tr_n(p_message, p_message_plural, p_n, p_context) : p_message; } + + /* THREADING */ + void call_deferred_thread_groupp(const StringName &p_method, const Variant **p_args, int p_argcount, bool p_show_error = false); template void call_deferred_thread_group(const StringName &p_method, VarArgs... p_args) { @@ -725,6 +748,7 @@ VARIANT_ENUM_CAST(Node::ProcessMode); VARIANT_ENUM_CAST(Node::ProcessThreadGroup); VARIANT_BITFIELD_CAST(Node::ProcessThreadMessages); VARIANT_ENUM_CAST(Node::InternalMode); +VARIANT_ENUM_CAST(Node::AutoTranslateMode); typedef HashSet NodeSet; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index ee0e7721a0a..2cbcc8e33ee 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -1755,6 +1755,7 @@ SceneTree::SceneTree() { root = memnew(Window); root->set_min_size(Size2i(64, 64)); // Define a very small minimum window size to prevent bugs such as GH-37242. root->set_process_mode(Node::PROCESS_MODE_PAUSABLE); + root->set_auto_translate_mode(Node::AUTO_TRANSLATE_MODE_ALWAYS); root->set_name("root"); root->set_title(GLOBAL_GET("application/config/name")); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 9e8047ce498..5952af60ee8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1517,7 +1517,6 @@ void Viewport::_gui_show_tooltip() { if (!base_tooltip) { gui.tooltip_label = memnew(Label); gui.tooltip_label->set_theme_type_variation(SNAME("TooltipLabel")); - gui.tooltip_label->set_auto_translate(gui.tooltip_control->is_auto_translating()); gui.tooltip_label->set_text(gui.tooltip_text); base_tooltip = gui.tooltip_label; panel->connect("mouse_entered", callable_mp(this, &Viewport::_gui_cancel_tooltip)); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index fd64220c2c3..3ec36f731ca 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -52,8 +52,8 @@ void Window::set_root_layout_direction(int p_root_dir) { bool Window::_set(const StringName &p_name, const Variant &p_value) { ERR_MAIN_THREAD_GUARD_V(false); - String name = p_name; + if (!name.begins_with("theme_override")) { return false; } @@ -95,7 +95,6 @@ bool Window::_set(const StringName &p_name, const Variant &p_value) { } else { return false; } - } else { if (name.begins_with("theme_override_icons/")) { String dname = name.get_slicec('/', 1); @@ -124,8 +123,8 @@ bool Window::_set(const StringName &p_name, const Variant &p_value) { bool Window::_get(const StringName &p_name, Variant &r_ret) const { ERR_READ_THREAD_GUARD_V(false); - String sname = p_name; + if (!sname.begins_with("theme_override")) { return false; } @@ -1308,14 +1307,6 @@ void Window::_notification(int p_what) { RS::get_singleton()->viewport_set_active(get_viewport_rid(), true); } -#ifdef TOOLS_ENABLED - if (is_part_of_edited_scene()) { - // Don't translate Windows on scene when inside editor. - set_message_translation(false); - notification(NOTIFICATION_TRANSLATION_CHANGED); - } -#endif - // Emits NOTIFICATION_THEME_CHANGED internally. set_theme_context(ThemeDB::get_singleton()->get_nearest_theme_context(this)); } break; @@ -2649,21 +2640,17 @@ bool Window::is_layout_rtl() const { } } +#ifndef DISABLE_DEPRECATED void Window::set_auto_translate(bool p_enable) { ERR_MAIN_THREAD_GUARD; - if (p_enable == auto_translate) { - return; - } - - auto_translate = p_enable; - - notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED); + set_auto_translate_mode(p_enable ? AUTO_TRANSLATE_MODE_ALWAYS : AUTO_TRANSLATE_MODE_DISABLED); } bool Window::is_auto_translating() const { ERR_READ_THREAD_GUARD_V(false); - return auto_translate; + return can_auto_translate(); } +#endif Transform2D Window::get_final_transform() const { ERR_READ_THREAD_GUARD_V(Transform2D()); @@ -2894,8 +2881,10 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("get_layout_direction"), &Window::get_layout_direction); ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Window::is_layout_rtl); +#ifndef DISABLE_DEPRECATED ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Window::set_auto_translate); ClassDB::bind_method(D_METHOD("is_auto_translating"), &Window::is_auto_translating); +#endif ClassDB::bind_method(D_METHOD("popup", "rect"), &Window::popup, DEFVAL(Rect2i())); ClassDB::bind_method(D_METHOD("popup_on_parent", "parent_rect"), &Window::popup_on_parent); @@ -2949,8 +2938,9 @@ void Window::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_stretch", PROPERTY_HINT_ENUM, "Fractional,Integer"), "set_content_scale_stretch", "get_content_scale_stretch"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor", PROPERTY_HINT_RANGE, "0.5,8.0,0.01"), "set_content_scale_factor", "get_content_scale_factor"); - ADD_GROUP("Localization", ""); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating"); +#ifndef DISABLE_DEPRECATED + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_auto_translate", "is_auto_translating"); +#endif ADD_GROUP("Theme", "theme_"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); diff --git a/scene/main/window.h b/scene/main/window.h index 4ae535848ae..73dba67f455 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -34,7 +34,6 @@ #include "scene/main/viewport.h" #include "scene/resources/theme.h" -class Control; class Font; class Shortcut; class StyleBox; @@ -138,8 +137,6 @@ private: LayoutDirection layout_dir = LAYOUT_DIRECTION_INHERITED; - bool auto_translate = true; - void _update_child_controls(); void _update_embedded_window(); @@ -389,15 +386,18 @@ public: void grab_focus(); bool has_focus() const; + Rect2i get_usable_parent_rect() const; + + // Internationalization. + void set_layout_direction(LayoutDirection p_direction); LayoutDirection get_layout_direction() const; bool is_layout_rtl() const; +#ifndef DISABLE_DEPRECATED void set_auto_translate(bool p_enable); bool is_auto_translating() const; - _FORCE_INLINE_ String atr(const String p_string) const { return is_auto_translating() ? tr(p_string) : p_string; }; - - Rect2i get_usable_parent_rect() const; +#endif // Theming.