thebsh
August 26, 2024, 7:57pm
1
Godot Version
4.2
Question
how can i achieve this in c#:
message.text = tr("{character} picked up the {weapon}").format({character = "Ogre", weapon = "Sword"})
my problem is the .format cuz there is Tr() but not the format method.
what i have now
SubLabel.Text = Tr("oldman19")
oldman 19 is the tag for something like you are {name}
ndbn
August 26, 2024, 8:50pm
2
tr
in gdscript is really is self.tr(...)
, method of Object
- base class of all objects and returning String
.format
is method of String
I’m not c# user and have not C# RN, but godot must use embed c# String and it have format method too, check what Tr
return
Moreus
August 27, 2024, 10:52am
5
I tested solution with {0}{1} placeholders, not named placeholders. Placeholders required only in translated text not to the key.
my translation.csv:
keys en pl
Ogre Ogre Ogr
Sword Sword Miecz
Pick1 {0} picked up the {1} {0} podniósł {1}
GD.Print(string.Format(Tr("Pick1"), Tr("Ogre"), Tr("Sword")));
remember to set Test if you don’t change translation in code
Moreus
August 27, 2024, 11:14am
6
for named placeholders
keys en pl
Ogre Ogre Ogr
Sword Sword Miecz
Pick1 {0} picked up the {1} {0} podniósł {1}
Pick2 {character} picked up the {weapon} {character} podniósł {weapon}
GD.Print(Tr("Pick2").Replace("{character}", Tr("Ogre")).Replace("{weapon}", Tr("Sword")));
1 Like
thebsh
August 27, 2024, 1:21pm
7
thank you very much the replace method was what i needed.
1 Like
system
Closed
September 26, 2024, 1:21pm
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.