Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


PlayerPrefLocaleSelector

Stores the last selected locale in PlayerPrefs and restores it on startup.
Read time 1 minuteLast updated 13 days ago

Definition

public class PlayerPrefLocaleSelector : IStartupLocaleSelector, IStartupLocaleInitialize

Remarks

On startup this selector reads the locale code saved under PlayerPrefLocaleSelector.PlayerPreferenceKey from PlayerPrefs and selects the matching locale. Because it also implements IStartupLocaleInitialize, it subscribes to LocalizationSettings.SelectedLocaleChanged after initialization and writes the new code whenever the locale changes, so the choice persists across sessions. If no code is stored or no available locale matches, GetStartupLocale returns null and the next selector runs. Add it to LocalizationSettings.StartupSelectors to enable persistence.
Reads the previously saved locale when the game starts.

Examples

using Unity.Localization;namespace Unity.Localization.Samples{ public class PlayerPrefLocaleSelectorExample { public Locale Run() { var selector = new PlayerPrefLocaleSelector { PlayerPreferenceKey = "selected-locale" }; Locale saved = selector.GetStartupLocale(LocalizationSettings.Instance); return saved; } }}

Properties

Property

Description

PlayerPreferenceKeyThe PlayerPrefs key used to store the selected locale code.