[HOWTO] How To: Localize Variable Text in Alerts

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
Tony Li
Posts: 22286
Joined: Thu Jul 18, 2013 1:27 pm

[HOWTO] How To: Localize Variable Text in Alerts

Post by Tony Li »

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:
variableField.png
variableField.png (16.9 KiB) Viewed 20 times

2. In C#, use DialogueManager.GetLocalizedText() to get the localized value of the Text Table field:

Code: Select all

string s = DialogueManager.GetLocalizedText("Earned");
3. Use String.Format() to replace the placeholders:

Code: Select all

s = string.Format(s, xpEarned, goldEarned);
4. Send this string to DialogueManager.ShowAlert():

Code: Select all

DialogueManager.ShowAlert(s);

See also: How To: Handle Player Gender In Dialogue Text
Post Reply