Page 1 of 1

Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 6:35 am
by jlhacode
I'm currently using the OnExecute event that's associated with a Dialogue Entry node to send an event to a script that sets a new language code, then resets it.

Code: Select all

private string oldLanguageCode;

public void Foo(string newLanguageCode) {
    oldLangaugeCode = Localization.language;
    Localization.language = newLanguageCode;
}		
it's then reset with Localization.language = oldLanguageCode in a yield return null coroutine.

It works, except in PC responses because OnExecute is run after the user's input.

Is there a better way to approach this?

Re: Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 8:23 am
by Tony Li
Hi,

What's the reason for localizing only one dialogue entry? I'm trying to getting the context for this in case I can suggest a better way.

Another way would be to forget the OnExcute() event, and use OnConversationLine() and OnConversationResponseMenu() methods (more info). You could add a Boolean field to your dialogue entry template that specifies whether to do special localization for it or not. Rough example:

Code: Select all

void OnConversationLine(Subtitle subtitle)
{
    if (Field.LookupBool(subtitle.dialogueEntry.fields, "Localize Me"))
    {
        subtitle.formattedText.text = /* your special localization code */
    }
}

void OnConversationResponseMenu(Response[] responses)
{
    foreach (var response in responses)
    {
        if (Field.LookupBool(response.destinationEntry.fields, "Localize Me"))
        {
            response.formattedText.text = /* your special localization code */
        }
     }
}

Re: Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 2:52 pm
by jlhacode
I want to have an NPC that yells in a different language when he's upset. the language will change based on the player's system language.

Your solution definitely fits my use-case, but I changed it to get the localized text from the localized field in the template.

Here was my solution:

Code: Select all

    public StringReference nativeLanguageCode;
    public StringReference targetLanguageCode;

    public void CheckChangeLanguageToNativeForOneEntry(Subtitle subtitle) {
        if (Field.LookupBool(subtitle.dialogueEntry.fields, "useNativeLanguage")) {
            var nativeString = Field.LookupValue(subtitle.dialogueEntry.fields, nativeLanguageCode.Value);
            subtitle.formattedText.text = nativeString;
        }
    }

    public void CheckChangeLanguageToNativeForOneEntry(Response[] responses) {
        foreach (var response in responses) {
            if (Field.LookupBool(response.destinationEntry.fields, "useNativeLanguage")) {
                var nativeString = Field.LookupValue(response.destinationEntry.fields, nativeLanguageCode.Value);
                response.formattedText.text = nativeString;
            }
        }
    }
I had a little bit of confusion over the naming of Response.destinationEntry. It mentions that, "The dialogue entry that this response links to. In other words, if this response is selected, the dialogue system will go to this dialogue entry."

This led me to believe that the destinationEntry is a reference to the DialogueEntry that shows after the response is interacted with. However, it seems like what's actually happening is that Response.destinationEntry.fields shows a representation of the List<Field> of the Response itself instead of the one referenced down the line.

Is that correct? This is just for my understanding.

Additionally, I have another question regarding Text Tables. is there any way we can get the Field ID of a Field Text value by using the Field Text value itself? I'm trying to get a value in a different language without knowing the Field name or the Field ID.

Re: Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 3:49 pm
by Tony Li
jlhacode wrote: Fri Jul 03, 2020 2:52 pmI had a little bit of confusion over the naming of Response.destinationEntry. It mentions that, "The dialogue entry that this response links to. In other words, if this response is selected, the dialogue system will go to this dialogue entry."

This led me to believe that the destinationEntry is a reference to the DialogueEntry that shows after the response is interacted with. However, it seems like what's actually happening is that Response.destinationEntry.fields shows a representation of the List<Field> of the Response itself instead of the one referenced down the line.

Is that correct? This is just for my understanding.
Yes, that's correct.
jlhacode wrote: Fri Jul 03, 2020 2:52 pmAdditionally, I have another question regarding Text Tables. is there any way we can get the Field ID of a Field Text value by using the Field Text value itself? I'm trying to get a value in a different language without knowing the Field name or the Field ID.
Here's the Text Table API: TextTable

If the field name is the same as its default text, you can TextTable.GetFieldID("fieldName").

Otherwise you might need to go through the entire TextTable.fields list.

Re: Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 3:55 pm
by jlhacode
Alright, I'll look into it. Thanks for your help Tony.

Re: Localizing the dialogue for one Dialogue Entry

Posted: Fri Jul 03, 2020 4:49 pm
by Tony Li
Happy to help! :-)