Fix auto-translations in editor

This commit is contained in:
kobewi 2023-03-17 01:58:30 +01:00
parent 0291fcd7b6
commit 8f8178bda6
7 changed files with 37 additions and 5 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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