godot
godot copied to clipboard
`TranslationServer.set_locale` only acts on scenes inside tree
Godot version
v4.2.rc1.official [ad72de508]
System information
Godot v4.2.rc1 - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1050 (NVIDIA; 31.0.15.4617) - Intel(R) Core(TM) i5-8300H CPU @ 2.30GHz (8 Threads)
Issue description
TranslationServer.set_locale
only acts on scenes inside tree. Not sure if this is expected or it is bug.
I'm working on an app that removes from tree (but doesn't delete) unused pages/screens. When locale is changed from the configuration page, only that page strings are updated.
Steps to reproduce
On the main scene, create a scene with a Label
and text = "Hello"
. Create another scene, with another Label
, same text
.
Generate .pot
and translate it.
On _ready
function of the main scene, instantiate the other scene, change locale and then add the scene to tree. Only the Label
that was there from start is updated.
Minimal reproduction project
The text is changed when
-
text
is set updated -
NOTIFICATION_TRANSLATION_CHANGED
is received- But controls outside the tree won't receive this notification
Technically we can always send NOTIFICATION_TRANSLATION_CHANGED
when a control is entering tree. Then there's no need to do atr()
calls separately, e.g. in set_text()
. But we should check other controls about this change.
If someone faces this issue in the meanwhile, to bypass this bug, I did TranslationServer.set_locale
before adding the page to the tree again, since sending NOTIFICATION_TRANSLATION_CHANGED
to the page (parent node) doesn't propagates it to its children (labels, buttons...).
Notice that this workaround works because if you set some locale TranslationServer.set_locale("en")
(on the configuration page), and then you set it again (going back to home page adding it to the tree), TranslationServer.set_locale("en")
, the notification is sent, although locale doesn't really change. I think that is redundant, although it is how setters work.
Can confirm, this behaviour is present in 4.2.1
Looks like I encounter this issue in v4.3.dev2.official [352434668] too, but with a little difference.
My sub-scenes are already in the scene, but hidden, and when they become visible, texts are not translated as they should be. I can only guess notifications are not sent to hidden scenes in tree either (kind of bad "optimization" in such case I guess, like "they are hidden anyway, no need to notify them" but when they'll become visible ? :/).