0 votes

How can I use the translation server to translate strings on an editor plugin? It just doesn't work as expected.

On my plugin.gd, on _enter_tree(), I do something like this

TranslationServer.add_translation(load("res://addons/myaddon/strings.pt.translation"))
print(tr("hi")) # prints "hi"
TranslationServer.set_locale("pt")
print(tr("hi")) # should print "oi" but prints "hi"

But if I create a normal scene and run the exactly same code on _ready(), it prints exactly what's expected

TranslationServer.add_translation(load("res://addons/myaddon/strings.pt.translation"))
print(tr("hi")) # prints "hi"
TranslationServer.set_locale("pt")
print(tr("hi")) # prints "oi" exactly as expected.

Maybe it is a bug? Or is this expected behavior and I should do something different when localizing plugins?

I would like to add that those tests are made after reloading the editor one time, that is, after the csv has been properly imported by the editor and the "*.pt.translation" has been generated.

Godot version 3.4.4 x64 windows
in Engine by (265 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.