I am trying to achieve globalization/localization in my MVC 3 application. I don't want different Views for each language. Please suggest how I can proceed. Any supported links/URLs will be of great help.
Globalization is the process of designing the application in such a way that it can be used by users from across the globe (multiple cultures). Localization, on the other hand, is the process of customization to make our application behave depending on the current culture and locale.
One way you can do it is to have the drop down just redirect the page to a language specific URL (this is quite nice as you can send around language specific links) then in a base class on your controller, set the Thread's locale. This example has . aspx pages not razor . cshtml.
Globalization in a Nutshell. Localization is the adaptation of a resource or product to fit the demands of one specific culture or locale, while globalization is the adaption of a particular resource to fit the demands of multiple cultures and locales.
To have ASP.NET set the UI culture and culture to the first language that is specified in the current browser settings, set UICulture and Culture to auto. Alternatively, you can set this value to auto:culture_info_name, where culture_info_name is a culture name. For a list of culture names, see CultureInfo.
You localize it in the same way as any other application like this:
PublicResXFileCodeGenerator
Use the translations in place of text in your views like with the following code:
@Strings.MyString
Strings will be automatically translated in the view depending on CultureInfo.CurrentCulture but this is not set automatically for you
You will need to change the CurrentCulture
(potentially in Application_BeginRequest
). How you do this is up to you, it could be a route value which sets it or you can read the user's browser language
You can find a list of the user's prefered languages (in order) in HttpContext.Current.Request.UserLanguages
.
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