[HOWTO] How To: Show Localized Alerts

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

[HOWTO] How To: Show Localized Alerts

Post by Tony Li »

When you show an alert message, such as using the ShowAlert(message) Lua function or using DialogueManager.ShowAlert(message) in C#, the Dialogue System will automatically check for a translation of the message in the text table asset that's assigned to the Dialogue Manager's Display Settings > Localization Settings > Text Table field.

However, in some cases you may need to include variable content in the message.

For example, say you want to show a message that the current conversant has joined the party. For example in English, it might look like:

"Tony Joined Party"

One way to do this using the ShowAlert() Lua functions is:

Code: Select all

ShowAlert(Variable["Conversant"] .. " " .. GetTextTableValue("Joined Party")
The only catch is that it will always put the conversant's display name first, such as "Tony Joined Party".

If another language uses a different type of word order -- such as "Ymunodd Tony â'r Blaid" in Welsh -- you will need to handle it differently. In this case, you can write a C# method such as:

Code: Select all

void ShowConversantJoinedParty()
{
    string formatString = DialogueManager.GetLocalizedText("Conversant Joined Party");
    string message = string.Format(formatString, DialogueLua.GetVariable("Conversant").asString);
    DialogueManager.ShowAlert(message);
}
Then add a text table entry "Conversant Joined Party" with values such as:
  • English: "{0} Joined Party"
  • Welsh: "Ymunodd {0} â'r Blaid"
Register the method ShowConversantJoinedParty() with Lua (see here), and use it in your Script field instead of ShowAlert().
DaynerKurdi
Posts: 3
Joined: Mon May 26, 2025 7:26 am

Re: [HOW TO] How To: Show Localized Alerts

Post by DaynerKurdi »

Hello Tony.

this exactly what I want. but got one more question regarding the C# script.

is it a mono script and needed to be attached to any gameObjec in the scene, or need to be attached with dialogue manager gameObject? or can it be a native C# script and sleep within the asset folder?
User avatar
Tony Li
Posts: 23417
Joined: Thu Jul 18, 2013 1:27 pm

Re: [HOWTO] How To: Show Localized Alerts

Post by Tony Li »

Hi,

Please see Registering Functions With Lua. It will be a regular C# script, typically on the Dialogue Manager GameObject. If it's on the Dialogue Manager, use an Awake method like:

Code: Select all

void Awake()
{
     Lua.RegisterFunction(nameof(ShowConversantJoinedParty), this, SymbolExtensions.GetMethodInfo(() => ShowConversantJoinedParty()));
}
Post Reply