Support loading of translations on threads
This commit is contained in:
parent
d95b516d31
commit
5301bbb3a5
|
@ -82,6 +82,15 @@ void Translation::_set_messages(const Dictionary &p_messages) {
|
||||||
void Translation::set_locale(const String &p_locale) {
|
void Translation::set_locale(const String &p_locale) {
|
||||||
locale = TranslationServer::get_singleton()->standardize_locale(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())) {
|
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);
|
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_TRANSLATION_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ class Translation : public Resource {
|
||||||
virtual Dictionary _get_messages() const;
|
virtual Dictionary _get_messages() const;
|
||||||
virtual void _set_messages(const Dictionary &p_messages);
|
virtual void _set_messages(const Dictionary &p_messages);
|
||||||
|
|
||||||
|
void _notify_translation_changed_if_applies();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue