Page 1 of 1
Localize variables inserted in dialogue
Posted: Wed Jan 05, 2022 3:46 am
by Swing Wren
Hello,
What would be the recommended way to localize variables inserted in dialogue?
Code: Select all
You make we laugh, your rank of [var=PlayerRank] is not enough to pass through the door
(PlayerRank may be things like student, master...)
Maybe at this point its wiser to just use custom tags and replace/translate the written text before its displayed?
Re: Localize variables inserted in dialogue
Posted: Wed Jan 05, 2022 9:08 am
by Tony Li
Hi,
You could process the text yourself in an
OnConversationLine method.
However, it might be easier to
register a localization function with Lua and use a [lua(
code)] markup tag. The example below adds a function LocalizeVar("variableName") that calls DialogueManager.GetLocalizedText(), which looks up the localized version of the variable value from the Text Table asset assigned to the Dialogue Manager's Display Settings > Localization Settings. You could change it to pull localizations from somewhere else such as i2 Localization or Unity's Localization package.
You'd use it like this:
Code: Select all
You make me laugh. Your rank of [lua(LocalizeVar("PlayerRank"))] is not enough to pass through the door
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
// Add to Dialogue Manager.
public class TestLocalize : MonoBehaviour
{
private void Awake()
{
Lua.RegisterFunction(nameof(LocalizeVar), this, SymbolExtensions.GetMethodInfo(() => LocalizeVar(string.Empty)));
}
private string LocalizeVar(string variableName)
{
string baseValue = DialogueLua.GetVariable(variableName).asString;
return DialogueManager.GetLocalizedText(baseValue);
}
}