Page 2 of 2

Re: Setting localization language via script made the dialogue manager to stop working

Posted: Sun Nov 19, 2023 10:28 am
by farazk86
Using a different Dialogue Manager in each scene that only survives in that scene would work better for me.

I did as advised and added this code to the Awake() of the dialogue scenes:

Code: Select all

DialogueManager.SetLanguage(PlayerPrefs.GetString("Language"));
But this is not working and the default english is being picked up. I then did a

Code: Select all

Debug.LogWarning(PlayerPrefs.GetString("Language"));
And its coming up as empty, thats why it may not be setting the language. But the following:

Code: Select all

Debug.LogWarning(PlayerPrefs.HasKey("Language"));
returns True, so the Key exists but the language string is not being saved to it.

Re: Setting localization language via script made the dialogue manager to stop working

Posted: Sun Nov 19, 2023 10:42 am
by Tony Li
Hi,

Inspect any Dialogue Manager. Expand Display Settings > Localization Settings, and click Reset Language PlayerPrefs.

Then change your Awake() method to:

Code: Select all

void Awake()
{
    if (PlayerPrefs.HasKey("Language")) DialogueManager.SetLanguage(PlayerPrefs.GetString("Language"));
}
Let me know if that resolves the issue.

Re: Setting localization language via script made the dialogue manager to stop working

Posted: Sun Nov 19, 2023 11:45 am
by farazk86
That did not help unfortunately, and the dialogue language did not change even after the advised resetting language player prefs in dialogue manager.

I am also using Lean Localization plugin to localize the UI, so I thought that maybe it is overwriting the "Language" key, but that is not the case, when I dug into the code, its saving under a different key, which is:

Code: Select all

PlayerPrefs.SetString("LeanLocalization.CurrentLanguage", currentLanguage);
So that is not the reason.

So, I decided to use a different key and manually call the PlayerPref.SetString() with this new key:

Code: Select all

if (language == "French")
        {
            DialogueManager.SetLanguage("fr");
            PlayerPrefs.SetString("dialogue_language", "fr");
        }            
        else if (language == "German")
        {
            DialogueManager.SetLanguage("de");
            PlayerPrefs.SetString("dialogue_language", "de");
        }            
        else if (language == "Portuguese")
        {
            DialogueManager.SetLanguage("pt");
            PlayerPrefs.SetString("dialogue_language", "pt");
        }
And then use this to load:

Code: Select all

DialogueManager.SetLanguage(PlayerPrefs.GetString("dialogue_language"));
With this change the dialogue text changes :)

Even now when I do

Code: Select all

Debug.LogWarning(PlayerPrefs.GetString("Language"));
it still returns empty, so for some reason the "Language" player pref is not saving or is being overwritten somewhere.

Re: Setting localization language via script made the dialogue manager to stop working

Posted: Sun Nov 19, 2023 12:01 pm
by Tony Li
Hi,

In that case it sounds like it's not using the "Language" PlayerPrefs, which is fine since you're handling it differently.