[HOWTO] How To: Localize Variable Text in Alerts
Posted: Fri Dec 20, 2024 9:56 pm
If you've assigned a Text Table to the Dialogue Manager's Display Settings > Localization Settings > Text Table field, then when you show an alert the Dialogue System will check if the alert message matches a field name in the Text Table. If so, it will use the translation for the current language.
You may at times have a need to show variable text, such as "You earned [xpEarned] XP and [goldEarned] coins".
However, the catch is that different languages have different syntax. So it's not just a matter of translating "You earned" + "XP and" + "coins". Instead:
1. In your Text Table asset, use {0} as a placeholder for xpEarned and {1} as a placeholder for goldEarned:
2. In C#, use DialogueManager.GetLocalizedText() to get the localized value of the Text Table field:
3. Use String.Format() to replace the placeholders:
4. Send this string to DialogueManager.ShowAlert():
See also: How To: Handle Player Gender In Dialogue Text
You may at times have a need to show variable text, such as "You earned [xpEarned] XP and [goldEarned] coins".
However, the catch is that different languages have different syntax. So it's not just a matter of translating "You earned" + "XP and" + "coins". Instead:
1. In your Text Table asset, use {0} as a placeholder for xpEarned and {1} as a placeholder for goldEarned:
2. In C#, use DialogueManager.GetLocalizedText() to get the localized value of the Text Table field:
Code: Select all
string s = DialogueManager.GetLocalizedText("Earned");
Code: Select all
s = string.Format(s, xpEarned, goldEarned);
Code: Select all
DialogueManager.ShowAlert(s);
See also: How To: Handle Player Gender In Dialogue Text