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.
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.
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 .
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.
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).
You can use: HttpRequest.UserLanguages Property
: Gets a sorted string array of client language preferences.
Refer:
How to detect browser language
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With