Get cultureinfo with country code
I am trying to get CultureInfo with country code. I am using hostip.info to get the country code.
For example, " http://api.hostip.info/?ip=207.46.197.32&position=true " returns me "US" for the country code or http://api.hostip.info/?ip=82.151.131.196&position= true returns "TR".
If I could have "en-US", "tr-TR" that's easy, but I can't have these culture names. I have country codes.
So, is there a way to get CultureInfo with country codes, or do you have any suggestions for getting CultureInfo with IP address?
source to share
Official public standards are the best source of use. See "CLDR - Unicode Common Locale Data Repository" at http://cldr.unicode.org/ .
Data files are available for download. Interesting documentation and guidelines are available.
source to share
I got the same problem because I got the country code from a third party IP address localization library. So here is my solution.
First I am trying to get culture information by country code. If that fails, I got all the information about the culture and then looked for the one that contains the country name (it is also possible that the country code (US) is contained in the CultureInfo.Name
(ru-US) field )
ci = CultureInfo.GetCultures(CultureTypes.AllCultures).Where(c => c.EnglishName.Contains(loc.countryName)).FirstOrDefault();
If there is more than one culture in a country, I followed the approach suggested by Doug Domenin
source to share