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?

+2


source to share


4 answers


If the request is made by a browser, the "Accept-Language" field in the HTTP request header will indicate the desired culture (s). Of course it is not from IP, but it might be a solution if you have HTTP request headers.

eg.



Accept-Language: en-us, en

+2


source


I'm not sure if you can do this in practice.



If you have Switzerland, Canada or India as your country code, which language do you need?

+1


source


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.

+1


source


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

0


source







All Articles