Version: Unity 6.7 Alpha (6000.7)
LanguageEnglish
  • C#

LocalizationSettings.SelectedLocaleChanged

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Raised after the selected locale changes.

Subscribe to this static event to update UI or reload content when the user switches language. It is invoked after LocalizationSettings.SelectedLocale has changed, both during startup selection and on later changes; the new locale is passed to the handler. Because it is static, unsubscribe when your object is destroyed to avoid leaks. To run code once when initialization finishes instead, use LocalizationSettings.InitializationCompleted.

Additional resources: LocalizationSettings.SelectedLocale, LocalizationSettings.InitializationCompleted

<para>Refreshes a label whenever the locale changes.</para>

using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples { public class SelectedLocaleChangedExample : MonoBehaviour { void OnEnable() => LocalizationSettings.SelectedLocaleChanged += OnLocaleChanged; void OnDisable() => LocalizationSettings.SelectedLocaleChanged -= OnLocaleChanged;

void OnLocaleChanged(Locale locale) => Debug.Log($"Locale is now {locale?.Code}"); } }