private void GetLocale(ISN_Locale locale) { IOSNativeUtility.OnLocaleLoaded -= GetLocale; string savedLanguage = PreferencesFactory.GetString("Language", useSecurePrefs: false); string systemLanguage = LanguageUtils.CountryCodeToLanguage(locale.CountryCode.ToLower()); // user does not changed his language manual // and system language is different from previous auto-detected if (systemLanguage != savedLanguage) { LanguageController.ChangeLanguage(systemLanguage); } }
string DeviceLanguage() { #if UNITY_EDITOR return(Application.systemLanguage.ToString()); #endif #if UNITY_ANDROID // Locale class var locale = new AndroidJavaClass("java.util.Locale"); // Get instance of Locale class var localeObject = locale.CallStatic <AndroidJavaObject>("getDefault"); // Returns the country/region code for this locale, which should either be the empty string, an uppercase ISO 3166 2-letter code, or a UN M.49 3-digit code. var country = localeObject.Call <string>("getCountry").ToLower(); MyDebug.Log("country:" + country); // Returns a name for the locale's country that is appropriate for display to the user. var displayCountry = localeObject.Call <string>("getDisplayCountry"); MyDebug.Log("displayCountry:" + displayCountry); // Returns a name for the locale that is appropriate for display to the user. var displayName = localeObject.Call <string>("getDisplayName"); MyDebug.Log("displayName:" + displayName); // Returns the language code of this Locale. var language = localeObject.Call <string>("getLanguage"); MyDebug.Log("language:" + language); return(LanguageUtils.CountryCodeToLanguage(country)); #endif return(Application.systemLanguage.ToString()); }