How I can set the culture of the ui automatically based on the users’browser?
All I found about this is Globalize.culture("pt-BR"); But it sets pt-BR as default and I dont want set this by default! I want only set this if the user is pt-BR!
How can I do this? And the validator methods, how can I set them for a specific culture?
How I can set the culture of the ui automatically based on the users’browser?
Share
In a ASP.NET MVC the
web.configis the right place. There is a quick summary, the first snippet shows, how could be e.g.pt-BRculture forcedIf application is ready to accept the culture from the client (browser), settings should be
The above setting will take a Language selected in client browser (e.g.
cs-CZin my case). If none is defined then system settings will be used.Final snippet shows, how to allow client to set and send intended culture, but in case that no Language is pre-selected, override the system setting with some other default value pt-BR
Extended: culture settings for
jQueryvalidatorand numeric inputNote: I am definitely not an expert in
jQueryand globalization techniques. This is example how I do adjustvalidatorto correctly process any numeric inputrazor View part (
X()is a shortcut fornew HtmlString()):jQuery part (custom methods for min and max)
And then jQuery.validator evaluates input values for cs-CZ:
10 000,00correctly as well as en-US:10,000.00.