/// <summary> /// Uses <see cref="Application.systemLanguage"/> to find a matching <see cref="Locale"/> from the available locales. /// </summary> /// <param name="availableLocales"></param> /// <returns></returns> public Locale GetStartupLocale(ILocalesProvider availableLocales) { // We first check the CultureInfo as this is more accurate and contains regional information. var cultureInfo = GetSystemCulture(); var locale = availableLocales.GetLocale(cultureInfo); if (locale == null) { // Attempt to use CultureInfo fallbacks to find the closest locale while (cultureInfo != CultureInfo.InvariantCulture && locale == null) { locale = availableLocales.GetLocale(cultureInfo); cultureInfo = cultureInfo.Parent; } if (locale != null) { Debug.Log($"The Locale '{CultureInfo.CurrentUICulture}' is not available, however the parent locale '{locale.Identifier.CultureInfo}' is available."); } } // Fallback to Application.systemLanguage var systemLanguage = GetApplicationSystemLanguage(); if (locale == null && systemLanguage != SystemLanguage.Unknown) { locale = availableLocales.GetLocale(systemLanguage); } return(locale); }
public void CreateTestLocalizationSettings() { m_Settings = LocalizationSettingsHelper.CreateEmpty(); m_LocalesProvider = m_Settings.GetAvailableLocales(); m_LocalesProvider.AddLocale(Locale.CreateLocale(SystemLanguage.Arabic)); m_LocalesProvider.AddLocale(Locale.CreateLocale(SystemLanguage.English)); m_LocalesProvider.AddLocale(Locale.CreateLocale(SystemLanguage.French)); m_LocalesProvider.AddLocale(Locale.CreateLocale(SystemLanguage.German)); m_LocalesProvider.AddLocale(Locale.CreateLocale(SystemLanguage.Japanese)); }