How can I add dynamic value to string from translation table?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By earlroxas

So I have this string in the translation table (csv file):
goal_timed,Clear stage under minutes,Selesaikan stage dalam menit,分にステージをクリアする

so I want to replace with some number, how can i do that?
and also the goal is to print the string to Label and it must respond to TranslationServer.set_locale()

:bust_in_silhouette: Reply From: jitspoe

You can change to be an index for the string format function: {0}

So your localized strings would be like “Clear the stage in under {0} minutes”.

And in gdscript, you’d do: tr(“goal_timed”).format(your_time_variable)

Note that you can also use named placeholders, so you can swap their order in translated strings:

# "goal_timed" translates to "The goal {name} was scored {amount} times!".
tr("goal_timed").format({name="Some name", amount=20})

Calinou | 2020-03-17 14:12

You can swap the order up with the indexes as well, can’t you? Like “This {0} is {1}”.format([“balloon”, “red”]) vs “This is a {1} {0}”.format([“balloon”, “red”]). The names can be a convenience thing, but seem like a bit of unnecessary extra string parsing.

jitspoe | 2020-03-19 06:24