Version: Unity 6.7 Beta (6000.7)
Language : English
Display dynamic values in a localized string
Create a file table provider for text files

Create a custom startup locale selector

Control which language the application starts in.

At startup, the selectors in the Localization settings run in order and the first one that returns an enabled locale decides the language. This example writes a selector that restores the user’s saved choice, with the same pattern as the built-in Player Pref selector. Use it as a starting point to store the choice in a save file, a cloud profile, or your own settings system.

Prerequisites

Before you start, make sure you have the following:

Write the selector

Implement IStartupLocaleSelector to choose the locale, and IStartupLocaleInitialize to run one-time setup after initialization. In this example, the setup subscribes to locale changes so the selector saves them:

[Serializable]
public class SaveFileLocaleSelector : IStartupLocaleSelector, IStartupLocaleInitialize
{
    [SerializeField] string m_PreferenceKey = "preferred-language";

    public Locale GetStartupLocale(LocalizationSettings settings)
    {
        // Returning null lets the next selector in the list decide.
        var code = PlayerPrefs.GetString(m_PreferenceKey);
        return string.IsNullOrEmpty(code) ? null : settings.GetLocale(new LocaleIdentifier(code));
    }

    public void PostInitialize(LocalizationSettings settings)
    {
        // Store later language changes so the next launch starts in the player's language.
        LocalizationSettings.SelectedLocaleChanged += locale => PlayerPrefs.SetString(m_PreferenceKey, locale.Code);
    }
}

The selector class must follow two constraints:

  • It must have the [Serializable] attribute. The settings serialize the selector list, and serialized fields, such as m_PreferenceKey, appear as options in the settings UI.
  • It must return null when it has no locale to offer. A null return passes the decision to the next selector, and localization treats a disabled locale the same way.

Register the selector

To register your selector:

  1. Open Edit > Project Settings > Localization.
  2. Add your selector to the startup selectors list. It appears in the add menu automatically.
  3. Move the saved-choice selector to the top of the list, so an explicit choice takes priority over the device language. Keep the System Locale Selector after it for first launch.

Test the selector

This selector follows the same pattern as the built-in Player Pref Locale Selector, but writes the choice to a file instead of PlayerPrefs. To verify that it persists the choice:

  1. Enter Play mode.
  2. Change the current language, for example with the language switcher in the Editor toolbar or with the built-in language selection controls.
  3. Exit Play mode and enter it again. The application starts in the language you selected.
  4. Delete the save file the selector wrote to, then enter Play mode again. The next selector in the list decides the language.

Additional resources

Display dynamic values in a localized string
Create a file table provider for text files