0 votes

I'm not sure if this is already possible. But I am trying to find a easy way to translate parts of a dialog which is a block of bbcode in a RichTextLabel. It would be very nice if I can do things such as "[tr]translate this[/tr]" and have the RichTextEffect modify charfx via tr(charfx). Also, regex is not working with tr():

var test : String = "[item][tr]Herb[/tr][/item] is nice. [place][tr]Thunder Tower[/tr][/place] is far.";
var regx : RegEx = RegEx.new();
print(TranslationServer.get_locale() + " " + regx.sub(test, tr("$1"), true));


  zh [item]Herb[/item] is nice. [place]Thunder Tower[/place] is far.

The code below works:

print(tr("Thunder Tower"));


in Engine by (17 points)
edited by

Any help or comment on this??

1 Answer

0 votes

Generally speaking, when it comes to internationalization you don't mix partial translations in a line of text. You cannot make assumptions about sentence structure or how pluralization is handled between languages.

The standard way of handling translations with Godot is to have your translation strings defined in a CSV file. The engine will process it and create .translation files that you add to your project settings.

In your particular case, it looks like you want English text in more than one translation. That means some of your translation strings will look very similar to each other. Nothing wrong with that, though you may want to translate the entire string.

Example CSV file:

message1,"The herb is nice", "The 草藥 is nice"
message2,"Thunder Tower is far", "雷峰塔 is far"

You could certainly also add bbcode to the translation strings and feed them into the bbcode text field of a RichTextLabel if you wanted to. Or add variables to them, as described in the answer to this question.

The main takeaway here is to be feeding simple ids like message1 into the tr() function. Once you have the right string you can manipulate it for display purposes.

by (864 points)
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 [email protected] with your username.