Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localization - how to get the client locale in asp.net mvc?

My question is my title.

 Localization - how to get the client locale in asp.net mvc ?

I saw some posts regarding based on url routing, is there any way I can get the data from browser or from request to server and process. Is there any way to get the browser locale from asp.net. I am cretaing custom display attribute to handle localization as mentioned in this answer.

This is because I am using DB for keeping my localized values. My plan is to get the data and using Display Attribute , it will display the local values. I need the locale from browser. So is it possible to get the browser's locale and query before rendering based on it.

Thanks in advance.

like image 769
kbvishnu Avatar asked Oct 15 '12 13:10

kbvishnu


People also ask

What is MVC localization?

Localization, on the other hand, is the process of customization to make our application behave depending on the current culture and locale. These two things go together. Image is used from: Globalization. Getting Started. Create MVC application.

How will you localize ASP NET application?

To opt-in to localization, we need to modify our Startup file. We'll be registering a few services, configuring options, and registering middleware. All steps that are common-place for additions in an ASP.NET application. Starting in our ConfigureServices method, we need to make a call to AddLocalization .

How will you localize URL in MVC application?

To offer a website in multiple languages using ASP.Net we simply need to add some resource. resx files to our project and voilà. Based on the language of the browser, IIS will match the localization resource.

What is localization C#?

Localization is the process of customizing your application for a given culture and locale. Cultures and Locales. The language needs to be associated with the particular region where it is spoken, and this is done by using locale (language + location).


1 Answers

You can use: HttpRequest.UserLanguages Property : Gets a sorted string array of client language preferences.

Refer:

How to detect browser language

like image 83
Kapil Khandelwal Avatar answered Nov 15 '22 04:11

Kapil Khandelwal