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

SystemLocaleSelector

class in Unity.Localization


Implements interfaces:IStartupLocaleSelector

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

Detects the language the device is set to and matches the closest available locale.

This selector first tries SystemLocaleSelector.GetSystemCulture, which reports the language the user asked the operating system for. Apple platforms, Android and WebGL give that as a language tag carrying the region and the script, such as pt-BR or zh-Hant-TW; elsewhere it falls back to Globalization.CultureInfo.CurrentUICulture. When no locale matches it tries Application.systemLanguage, which every platform reports but which carries the language alone. Each answer is matched against LocaleIdentifier and then up the culture parent chain, so a device set to fr-FR selects fr when only fr is available. Disabled locales are passed over, so a disabled match does not stop the search. If nothing matches, SystemLocaleSelector.GetStartupLocale returns null and the next selector in LocalizationSettings.StartupSelectors runs. This selector is part of the default selector chain. Override SystemLocaleSelector.GetSystemCulture to supply a fixed culture in tests.

Additional resources: IStartupLocaleSelector, LocalizationSettings

Selects the locale that best matches the device language.

using Unity.Localization;

namespace Unity.Localization.Samples { public class SystemLocaleSelectorExample { public Locale Run() { var selector = new SystemLocaleSelector(); Locale locale = selector.GetStartupLocale(LocalizationSettings.Instance); return locale; } } }

Protected Methods

Method Description
GetSystemCulture Returns the culture used to detect the startup locale.