summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2023-03-17 01:58:30 +0100
committerkobewi <kobewi4e@gmail.com>2023-03-22 23:57:12 +0100
commit8f8178bda6d74e09283df85d4cb34a52843e1892 (patch)
tree074fa921a80ff53da77c6f474c598a372665e0da
parent0291fcd7b66bcb315a49c44de8031e5596de4216 (diff)
downloadredot-engine-8f8178bda6d74e09283df85d4cb34a52843e1892.tar.gz
Fix auto-translations in editor
-rw-r--r--core/object/object.cpp14
-rw-r--r--scene/gui/control.cpp7
-rw-r--r--scene/gui/menu_bar.cpp4
-rw-r--r--scene/main/node.cpp5
-rw-r--r--scene/main/node.h1
-rw-r--r--scene/main/timer.cpp2
-rw-r--r--scene/main/window.cpp9
7 files changed, 37 insertions, 5 deletions
diff --git a/core/object/object.cpp b/core/object/object.cpp
index 57aa1339ec..c324eab9bb 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1378,7 +1378,12 @@ String Object::tr(const StringName &p_message, const StringName &p_context) cons
if (!_can_translate || !TranslationServer::get_singleton()) {
return p_message;
}
- return TranslationServer::get_singleton()->translate(p_message, p_context);
+
+ if (Engine::get_singleton()->is_editor_hint()) {
+ return TranslationServer::get_singleton()->tool_translate(p_message, p_context);
+ } else {
+ return TranslationServer::get_singleton()->translate(p_message, p_context);
+ }
}
String Object::tr_n(const StringName &p_message, const StringName &p_message_plural, int p_n, const StringName &p_context) const {
@@ -1389,7 +1394,12 @@ String Object::tr_n(const StringName &p_message, const StringName &p_message_plu
}
return p_message_plural;
}
- return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
+
+ if (Engine::get_singleton()->is_editor_hint()) {
+ return TranslationServer::get_singleton()->tool_translate_plural(p_message, p_message_plural, p_n, p_context);
+ } else {
+ return TranslationServer::get_singleton()->translate_plural(p_message, p_message_plural, p_n, p_context);
+ }
}
void Object::_clear_internal_resource_paths(const Variant &p_var) {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 10f9529ca9..f78afed2c3 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2912,6 +2912,13 @@ 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
notification(NOTIFICATION_THEME_CHANGED);
} break;
diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp
index 0c12b98ad7..38fd616892 100644
--- a/scene/gui/menu_bar.cpp
+++ b/scene/gui/menu_bar.cpp
@@ -249,9 +249,11 @@ void MenuBar::_update_submenu(const String &p_menu_name, PopupMenu *p_child) {
}
bool MenuBar::is_native_menu() const {
- if (Engine::get_singleton()->is_editor_hint() && is_inside_tree() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this)) {
+#ifdef TOOLS_ENABLED
+ if (is_part_of_edited_scene()) {
return false;
}
+#endif
return (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_GLOBAL_MENU) && is_native);
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 62ce887c93..22bcfc947b 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2073,6 +2073,11 @@ bool Node::is_property_pinned(const StringName &p_property) const {
StringName Node::get_property_store_alias(const StringName &p_property) const {
return p_property;
}
+
+bool Node::is_part_of_edited_scene() const {
+ return Engine::get_singleton()->is_editor_hint() && is_inside_tree() && get_tree()->get_edited_scene_root() &&
+ (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_ancestor_of(this));
+}
#endif
void Node::get_storable_properties(HashSet<StringName> &r_storable_properties) const {
diff --git a/scene/main/node.h b/scene/main/node.h
index 493578bc5b..8ce42d04bd 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -382,6 +382,7 @@ public:
void set_property_pinned(const String &p_property, bool p_pinned);
bool is_property_pinned(const StringName &p_property) const;
virtual StringName get_property_store_alias(const StringName &p_property) const;
+ bool is_part_of_edited_scene() const;
#endif
void get_storable_properties(HashSet<StringName> &r_storable_properties) const;
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 4fd66312b7..0f4f18b495 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -35,7 +35,7 @@ void Timer::_notification(int p_what) {
case NOTIFICATION_READY: {
if (autostart) {
#ifdef TOOLS_ENABLED
- if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_ancestor_of(this))) {
+ if (is_part_of_edited_scene()) {
break;
}
#endif
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 5d3173a2a5..1ac6827158 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -490,7 +490,7 @@ bool Window::is_embedded() const {
bool Window::is_in_edited_scene_root() const {
#ifdef TOOLS_ENABLED
- return (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this));
+ return is_part_of_edited_scene();
#else
return false;
#endif
@@ -1138,6 +1138,13 @@ 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
notification(NOTIFICATION_THEME_CHANGED);
} break;