Locale

Locale Info

The default locale is appropriate for tasks that involve presenting data to the user. In this case, you want to use the user's date/time formats, number formats, rules for conversion to lowercase, and so on. In this case, it's safe to use the convenience methods.

The default locale is not appropriate for machine-readable output. The best choice there is usually Locale.US. This locale is guaranteed to be available on all devices, and the fact that it has no surprising special cases and is frequently used (especially for computer-computer communication) means that it tends to be the most efficient choice too.

Following code snippet shows how to retrieve basic Locale info:

UM_Location.OnLocaleLoaded += HandleLocaleInfoLoaded;
UM_Location.Instance.GetLocale();

private void HandleLocaleInfoLoaded (UM_LocaleInfo locale){
        UM_Location.OnLocaleLoaded -= HandleLocaleInfoLoaded;

		Debug.Log("Locale Info:", "Country:" + locale.CountryCode + "/" 
		                          + locale.DisplayCountry + "  :   " + "Language:" 
		                          + locale.LanguageCode + "/" 
		                          + locale.DisplayLanguage);
	}

The locale info is represented as the UM_LocaleInfo object.

public class UM_LocaleInfo {

	private ISN_Locale _IOSLocale;
	private AN_Locale _ANLocale;

	private UM_LocaleInfo(){}

	public UM_LocaleInfo(ISN_Locale locale) {
		_IOSLocale= locale;
	}

	public UM_LocaleInfo(AN_Locale locale) {
		_ANLocale = locale;
	}

//Returns the country code for this locale, or "" if this locale doesn't correspond to a specific country.
	public string CountryCode {
		get {
			switch (Application.platform) {
			case RuntimePlatform.Android:
				return _ANLocale.CountryCode;
			case RuntimePlatform.IPhonePlayer:
				return _IOSLocale.CountryCode;
			}
			return string.Empty;
		}
	}
	
//Returns the name of this locale's country, localized to locale. Returns the empty string if this locale does not correspond to a specific country.
	public string DisplayCountry {
		get {
			switch (Application.platform) {
			case RuntimePlatform.Android:
				return _ANLocale.DisplayCountry;
			case RuntimePlatform.IPhonePlayer:
				return _IOSLocale.DisplayCountry;
			}
			return string.Empty;
		}
	}
	
//Returns the language code for this Locale or the empty string if no language was set.
	public string LanguageCode {
		get {
			switch (Application.platform) {
			case RuntimePlatform.Android:
				return _ANLocale.LanguageCode;
			case RuntimePlatform.IPhonePlayer:
				return _IOSLocale.LanguageCode;
			}
			return string.Empty;
		}
	}
	
//Returns the name of this locale's language, localized to locale. If the language name is unknown, the language code is returned.
	public string DisplayLanguage {
		get {
			switch (Application.platform) {
			case RuntimePlatform.Android:
				return _ANLocale.DisplayLanguage;
			case RuntimePlatform.IPhonePlayer:
				return _IOSLocale.DisplayLanguage;
			}
			return string.Empty;
		}
	}
}