Runtime Localization Issue for Quest Log and Dialogue System
Posted: Mon Dec 16, 2024 12:59 pm
Hi Tony,
I am currently working on a project using the Dialogue System for Unity and have implemented runtime language switching. While I can successfully update UI elements dynamically via UILocalizationManager.UpdateUIs() after calling DialogueManager.SetLanguage(languageCode), I noticed that active quests in the Quest Log and dialogues do not update immediately during runtime.
Current Behavior:
When switching languages during runtime, the UI updates correctly, but quest titles, descriptions, and dialogues remain in the previous language.
If I restart the game after switching the language, everything displays correctly in the new language.
Expected Behavior:
Quest Log entries and active dialogues should reflect the new language immediately after calling SetLanguage(), similar to how UI elements are updated.
Questions:
Is there a method to refresh or reload the Quest Log and active dialogues dynamically after switching languages?
Are additional steps required to ensure that quests and dialogues are updated in real-time?
Below is the script I am using to manage language switching:
using PixelCrushers;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using TMPro;
public class LanguageManager : MonoBehaviour
{
public UILocalizationManager localizationManager; // Reference to Localization Manager
public TMP_Dropdown languageDropdown; // Dropdown for selecting languages
public TextMeshProUGUI dropdownLabel; // Text to display selected language
private const string LANGUAGE_KEY = "LanguageS"; // Key for PlayerPrefs storage
private bool isInitializing = true;
void Start()
{
languageDropdown.onValueChanged.RemoveAllListeners();
LoadLanguage();
languageDropdown.onValueChanged.AddListener(OnDropdownChanged);
isInitializing = false;
}
private void LoadLanguage()
{
if (PlayerPrefs.HasKey(LANGUAGE_KEY))
{
string savedLanguage = PlayerPrefs.GetString(LANGUAGE_KEY);
if (savedLanguage == "Default")
{
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
}
else
{
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
}
}
else
{
string systemLanguage = Application.systemLanguage.ToString();
if (systemLanguage == "French")
{
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
}
else
{
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
}
}
}
private void OnDropdownChanged(int optionIndex)
{
if (isInitializing) return;
switch (optionIndex)
{
case 0:
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
break;
case 1:
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
break;
default:
Debug.LogWarning("Unknown language selection!");
break;
}
}
private void ApplyLanguage(string languageCode, int dropdownIndex)
{
localizationManager.UpdateUIs(languageCode);
languageDropdown.onValueChanged.RemoveListener(OnDropdownChanged);
languageDropdown.value = dropdownIndex;
dropdownLabel.text = dropdownIndex == 0 ? "Language A" : "Language B";
languageDropdown.onValueChanged.AddListener(OnDropdownChanged);
}
}
I would appreciate any advice or recommended solutions to address this issue.
Thank you for your time and support.
I am currently working on a project using the Dialogue System for Unity and have implemented runtime language switching. While I can successfully update UI elements dynamically via UILocalizationManager.UpdateUIs() after calling DialogueManager.SetLanguage(languageCode), I noticed that active quests in the Quest Log and dialogues do not update immediately during runtime.
Current Behavior:
When switching languages during runtime, the UI updates correctly, but quest titles, descriptions, and dialogues remain in the previous language.
If I restart the game after switching the language, everything displays correctly in the new language.
Expected Behavior:
Quest Log entries and active dialogues should reflect the new language immediately after calling SetLanguage(), similar to how UI elements are updated.
Questions:
Is there a method to refresh or reload the Quest Log and active dialogues dynamically after switching languages?
Are additional steps required to ensure that quests and dialogues are updated in real-time?
Below is the script I am using to manage language switching:
using PixelCrushers;
using PixelCrushers.DialogueSystem;
using UnityEngine;
using TMPro;
public class LanguageManager : MonoBehaviour
{
public UILocalizationManager localizationManager; // Reference to Localization Manager
public TMP_Dropdown languageDropdown; // Dropdown for selecting languages
public TextMeshProUGUI dropdownLabel; // Text to display selected language
private const string LANGUAGE_KEY = "LanguageS"; // Key for PlayerPrefs storage
private bool isInitializing = true;
void Start()
{
languageDropdown.onValueChanged.RemoveAllListeners();
LoadLanguage();
languageDropdown.onValueChanged.AddListener(OnDropdownChanged);
isInitializing = false;
}
private void LoadLanguage()
{
if (PlayerPrefs.HasKey(LANGUAGE_KEY))
{
string savedLanguage = PlayerPrefs.GetString(LANGUAGE_KEY);
if (savedLanguage == "Default")
{
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
}
else
{
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
}
}
else
{
string systemLanguage = Application.systemLanguage.ToString();
if (systemLanguage == "French")
{
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
}
else
{
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
}
}
}
private void OnDropdownChanged(int optionIndex)
{
if (isInitializing) return;
switch (optionIndex)
{
case 0:
ApplyLanguage("Default", 0);
DialogueManager.SetLanguage("Default");
break;
case 1:
ApplyLanguage("fr", 1);
DialogueManager.SetLanguage("fr");
break;
default:
Debug.LogWarning("Unknown language selection!");
break;
}
}
private void ApplyLanguage(string languageCode, int dropdownIndex)
{
localizationManager.UpdateUIs(languageCode);
languageDropdown.onValueChanged.RemoveListener(OnDropdownChanged);
languageDropdown.value = dropdownIndex;
dropdownLabel.text = dropdownIndex == 0 ? "Language A" : "Language B";
languageDropdown.onValueChanged.AddListener(OnDropdownChanged);
}
}
I would appreciate any advice or recommended solutions to address this issue.
Thank you for your time and support.