If you're using a lot of changing texts in your #Godot games, you can re-use lines by using contextual placeholders. Those:
- make it easier to read than the %s placeholder
- make it easier for translation because the order can change
- cuts down of amount of strings you need
#GodotTips #gamedev
- make it easier to read than the %s placeholder
- make it easier for translation because the order can change
- cuts down of amount of strings you need
#GodotTips #gamedev
Comments
I use spreadsheets, so I ususally just set a string before like
var noun = tr("APPLES") if apples > 1 else tr("APPLE")
and then feed that into the sentence.
https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_format_string.html
But I had a blind spot before, so I'd really appreciate it if you could elaborate. I seem to have other use cases in mind.
%s ate %s of your %s
vs
{creature} ate {x} of your {food}
For those who are working in C#, the equivalent is an interpreted string. It would be like:
string text = $"Oh, no! {creature} ate {x} of your {food}!"
Then you assign values to the creature, x, and food properties elsewhere in your script.
https://www.w3schools.com/cs/cs_strings_interpol.php
vat text: String = "Oh no! %s ate %s of your %s" % [creature_name, amount, food_name]
('scuse my fat fingers)
"%.2f kg" % [weight_in_kg_as_a_float]
"22.1 kg"
"%03d" % [age]
"009"
This is how it's always been done since I started in the 80's, so it's natural to me :)
If you need to jump between languages, you look for the common tooling ;-)
I'm not super experienced in coding and I'm using gdscript exclusively right now, so I'm looking for what is easiest to understand for me, plus what works best for localization.
The solutions are the same shape, it's just they are spoken in a funny accent! :D
Here's the documentation: https://docs.godotengine.org/en/stable/tutorials/i18n/internationalizing_games.html#placeholders
A thing that threw me off at first was that you have to put the tr("reference") into another set of paranthesis for the .format() to work -> (tr("reference").format()
I tried poedit but it confused me so I went back to spreadsheets haha
But I want to give poedit another shot, eventually.