[HOWTO] How To: Tie Menu Framework to Localization Package

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

[HOWTO] How To: Tie Menu Framework to Localization Package

Post by Tony Li »

If you're using the free Menu Framework addon available on the Extras page and also using Unity's Localization Package, you may want the Menu Framework's Options menu > Language dropdown to set the Localization Package's locale. To do this:

1. Add the DialogueSystemLocalizationPackageBridge component to your Dialogue Manager.

2. Make a subclass of the Menu System's Options class. Override the SetLanguageByIndex() method (at the bottom of the script) to set the Localization Package's Locale. When you set the Localization Package's Locale, the DialogueSystemLocalizationPackageBridge will automatically set the Dialogue System's localization, too.
OptionsWithLocalizationPackage.cs

Code: Select all

using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
namespace PixelCrushers.DialogueSystem.MenuSystem
{
    public class OptionsWithLocalizationPackage : Options
    {
        base.SetLanguageByIndex(index);
        
        // Get the available locales from Unity's Localization Package:
        var locales = LocalizationSettings.AvailableLocales.Locales;
        
        if (0 <= index && index < locales.Count)
        {
            // Set the selected locale:
            LocalizationSettings.SelectedLocale = locales[index];
        }
        else
        {
            Debug.LogWarning("Invalid language index.");
        }
    }
}
3. On your Menu System prefab, use your subclass in place of the original Options class. You can replace it in place to retain inspector assignments.
Post Reply