I'd like to know a reliable way to get the user's ISO 3166-1 alpha-2 (2-letter code, ex : US, CA) with c# in unity3d ?
I've tried RegionInfo.TwoLetterISORegionName but it returns an empty string.
Are they not implemented ?
How do I do this ?
EDIT : The main error I'm getting here is that the TwoLetterISORegionName is empty when I try and get it. The CultureInfo and RegionInfo are always returning United States as the culture unless I use this workaround :
[System.Runtime.InteropServices.DllImport("KERNEL32.DLL")]
private static extern int GetSystemDefaultLCID();
RegionInfo regionInfo = new RegionInfo(GetSystemDefaultLCID());
CultureInfo cultureInfo = new CultureInfo(GetSystemDefaultLCID());
However, the TwoLetterISORegionName is empty and the ThreeLetterWindowsRegionName returns something like "Canada", which is no good for me.
Hope that clarifies things.
UPDATE :
Here's the Debug information I get using the code above :
Debug.Log("----- REGION INFO -----"); // Empty
Debug.Log("CurrencyEnglishName : " + regionInfo.CurrencyEnglishName); // Empty
Debug.Log("CurrencyNativeName : " + regionInfo.CurrencyNativeName); // Not implemented exception
Debug.Log("CurrencySymbol : " + regionInfo.CurrencySymbol); // CAD
Debug.Log("DisplayName : " + regionInfo.DisplayName); // Empty
Debug.Log("EnglishName : " + regionInfo.EnglishName); // Empty
Debug.Log("GeoId : " + regionInfo.GeoId); // 959515600
Debug.Log("IsMetric : " + regionInfo.IsMetric); // True
Debug.Log("ISOCurrencySymbol : " + regionInfo.ISOCurrencySymbol); // Canadian Dollar
Debug.Log("Name : " + regionInfo.Name); // Empty
Debug.Log("NativeName : " + regionInfo.NativeName); // Empty
Debug.Log("ThreeLetterISORegionName : " + regionInfo.ThreeLetterISORegionName); // Empty
Debug.Log("ThreeLetterWindowsRegionName : " + regionInfo.ThreeLetterWindowsRegionName); // Canada
Debug.Log("TwoLetterISORegionName : " + regionInfo.TwoLetterISORegionName); // Empty
Obviously those are wrong values (well it's right, I'm in Canada and all, but the 3 letter code isn't "Canada", and the geoid can't be that big a number last I checked), or I'm missing something !
UPDATE2 : Upon further testing outside and inside of the Unity Editor, I've come to realize that the GeoID is always different... almost like a random number generator ! That feels wrong... Anyone has any ideas ?