How to learn language of user on Asp.Net MVC? For example; If someone entered the website on United Kingtom, website will open by English language. Else someone entered the website on Turkey, website will open by Turkish language.
-
3It's called "cultures", there are some answers already about this. Let me find it for you. http://stackoverflow.com/questions/1560796/set-culture-in-an-asp-net-mvc-app – Joren Vandamme Apr 18 '16 at 13:32
-
Possible duplicate of [Set Culture in an ASP.Net MVC app](http://stackoverflow.com/questions/1560796/set-culture-in-an-asp-net-mvc-app) – Joren Vandamme Apr 18 '16 at 13:35
1 Answers
You need several things set up in your application:
A means to pre-detect the user's culture (this works best by mapping the IP Address via a GeoIP lookup to the country and its official language, or, less recommended using the user's browser language settings)
Internationalization and localization of the web site.
Some means to override the detected language.
The first item helps your website guess the user's most probable choice of language. The second allows displaying the site in that language. The third allows the user to change the language if the guess was wrong or the account is shared etc.
MaxMind offers free databases with code support and samples, and webservices (not free) for mapping an IP to a country.
As for localization you can do one of two things:
a. use RESX resources referenced in .cshtml views b. use different .cshtml views for each language
There are several materials for this, Hanselman's blog post is good start, for the rest search 'asp.net mvc localization'
Finally for the language override you can use a cookie and links on the page to switch to another language, cookie that you would check at the beginning of the request in order to set the current culture.

- 20,288
- 17
- 117
- 166
-
I think that mapping language to IP address is so good. What if british tourist in Turkey will open website? Accept-Language header is good point to determine default UI culture. At least there's mo chances that user got used to it. And another good option is to allow user to choose locale and store it in cookie – Chizh Jul 07 '16 at 21:11