Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TranslationServer.set_locale only acts on scenes inside tree #85051

Closed
acgc99 opened this issue Nov 18, 2023 · 5 comments
Closed

TranslationServer.set_locale only acts on scenes inside tree #85051

acgc99 opened this issue Nov 18, 2023 · 5 comments

Comments

@acgc99
Copy link

acgc99 commented Nov 18, 2023

Godot version

v4.2.rc1.official [ad72de5]

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

bug.zip

@timothyqiu
Copy link
Member

timothyqiu commented Nov 19, 2023

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.

@acgc99
Copy link
Author

acgc99 commented Nov 19, 2023

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.

@arran-nz
Copy link

arran-nz commented Feb 8, 2024

Can confirm, this behaviour is present in 4.2.1

@Infini-Creation
Copy link

Looks like I encounter this issue in v4.3.dev2.official [3524346] 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 ? :/).

@timothyqiu
Copy link
Member

Not reproducible in 4.3.

Fixed by #87530 as it sends NOTIFICATION_TRANSLATION_CHANGED when a control is entering tree.

Feel free to reopen this issue if you can still reproduce this problem with a different setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants