# PlayerPrefLocaleSelector

> Stores the last selected locale in PlayerPrefs and restores it on startup.

## Definition

* **Type:** Class
* **Namespace:** [Unity.Localization](/engine/6000.7/script-reference/unity/localization.md)
* **Assembly:** UnityEngine.LocalizationRuntimeModule
* **Implements:** [IStartupLocaleSelector](/engine/6000.7/script-reference/unity/localization/istartuplocaleselector.md), [IStartupLocaleInitialize](/engine/6000.7/script-reference/unity/localization/istartuplocaleinitialize.md)

```csharp
public class PlayerPrefLocaleSelector : IStartupLocaleSelector, IStartupLocaleInitialize
```

## Remarks

On startup this selector reads the locale code saved under [PlayerPrefLocaleSelector.PlayerPreferenceKey](/engine/6000.7/script-reference/unity/localization/playerpreflocaleselector/playerpreferencekey.md) from [PlayerPrefs](/engine/6000.7/script-reference/unityengine/playerprefs.md) and selects the matching locale. Because it also implements [IStartupLocaleInitialize](/engine/6000.7/script-reference/unity/localization/istartuplocaleinitialize.md), it subscribes to [LocalizationSettings.SelectedLocaleChanged](/engine/6000.7/script-reference/unity/localization/localizationsettings/selectedlocalechanged.md) 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](/engine/6000.7/script-reference/unity/localization/localizationsettings/startupselectors.md) to enable persistence.

Additional Resources: [IStartupLocaleSelector](/engine/6000.7/script-reference/unity/localization/istartuplocaleselector.md), [IStartupLocaleInitialize](/engine/6000.7/script-reference/unity/localization/istartuplocaleinitialize.md), [LocalizationSettings](/engine/6000.7/script-reference/unity/localization/localizationsettings.md)

Reads the previously saved locale when the game starts.

## Examples

```csharp
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                                                 |
| ------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| [PlayerPreferenceKey](/engine/6000.7/script-reference/unity/localization/playerpreflocaleselector/playerpreferencekey.md) | The PlayerPrefs key used to store the selected locale code. |
