diff options
author | Yuri Sizov <yuris@humnom.net> | 2023-07-26 18:39:27 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-07-26 18:39:27 +0200 |
commit | 7c204874eb079fbd401a13e6222878425b7287bf (patch) | |
tree | 5eaab38f776795973fe2c97c8aefb4c63d021a42 /core/string | |
parent | 92960b7a22dabe26bb724b7b0d00a5fd03324f3a (diff) | |
parent | 5301bbb3a5cbf94e38662b7ac977ba20f341c8ca (diff) | |
download | redot-engine-7c204874eb079fbd401a13e6222878425b7287bf.tar.gz |
Merge pull request #78747 from RandomShaper/fix_trans_threading
Support loading of translations on threads
Diffstat (limited to 'core/string')
-rw-r--r-- | core/string/translation.cpp | 9 | ||||
-rw-r--r-- | core/string/translation.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/core/string/translation.cpp b/core/string/translation.cpp index 3ca2e5ccdf..02380c92bb 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -82,6 +82,15 @@ void Translation::_set_messages(const Dictionary &p_messages) { void Translation::set_locale(const String &p_locale) { locale = TranslationServer::get_singleton()->standardize_locale(p_locale); + if (Thread::is_main_thread()) { + _notify_translation_changed_if_applies(); + } else { + // Avoid calling non-thread-safe functions here. + callable_mp(this, &Translation::_notify_translation_changed_if_applies).call_deferred(); + } +} + +void Translation::_notify_translation_changed_if_applies() { if (OS::get_singleton()->get_main_loop() && TranslationServer::get_singleton()->get_loaded_locales().has(get_locale())) { OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED); } diff --git a/core/string/translation.h b/core/string/translation.h index 01d239f81c..ca8b460312 100644 --- a/core/string/translation.h +++ b/core/string/translation.h @@ -47,6 +47,8 @@ class Translation : public Resource { virtual Dictionary _get_messages() const; virtual void _set_messages(const Dictionary &p_messages); + void _notify_translation_changed_if_applies(); + protected: static void _bind_methods(); |