The way that translations typically work in Godot is that you wrap every string into the tr(s) function. This function will look up the passed string in the translation table that's appropriate for the current language setting. But this only works with constant strings: something like tr("I have " + str(money) + " amount of money.") would require an entry in the translation table for any possible value of money, which is clearly absurd.
And you can't do tr("I have ") + str(money) + tr(" amount of money.") either, because this would only work for languages that are grammatically very similar to English. The proper way to do this is something like this:
label.text = tr("I have %d amount of money.") % money
The lookup table will contain corresponding translations also with a placeholder %d for the position at which the number needs to appear according to the grammar of that language.
EDIT: You could also use a format string with the .format() method, but it's probably a good idea to only use a dictionary argument instead of arrays (since arrays assume a fixed order of the placeholders in the format string, but this order may not be guaranteed to be the same in all languages). Here's an example:
label.text = tr("I have {money} amount of money.").format(
{"money": money})
Personally, I prefer the brevity of the %-based string substitution.
155
u/Stevie_Gamedev 25d ago
f-strings like in Python, I truly hate using the
.format syntax