Asp.net mvc Globalization. How do you do it?

Studying asp.net mvc, and whenever I worked, we had to localize our application. Look at a few articles, for example

I am a CONFERENCE. Mostly because my knowledge is small! What is the recommended way to do this? Have you made an app in the real world? Could you share the code? Will you get a snippet of how you solve the problem?

I am looking for a neat way, as you can do in asp.net. I need to enable the user to change languages ​​at runtime by clicking a flag or something.

Is there a basic method for overriding? Is there an example somewhere? Do you need to write some baseController class?

Thanks so much for your time.

+4
source share
2 answers

You must use resource files to handle localization. At the same time, you have the opportunity to get the language that the user selected earlier, or he chose right now. Here is a good blog on how to do this http://adamyan.blogspot.com/2010/02/aspnet-mvc-2-localization-complete.html

If the user does not have an active session, then there is no cookie that identifies him, you should use the browser language or, possibly, the geo-tracking service to determine sitelanguage. It is up to you to provide an easy way to change the current language ... And, as mentioned above, resource files will help you here.

+2
source

If you are using Asp.Net MVC

//A foreigner, has possibly brew a cookie for me public class SpeakNativeTongueAttribute : ActionFilterAttribute, IActionFilter { const string cookieName = "culture"; void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext) { var cookieKeys = filterContext.RequestContext.HttpContext.Request.Cookies.AllKeys; if (cookieKeys.Contains(cookieName)) { //eat the cookie var theCultureCookie = filterContext.RequestContext.HttpContext.Request.Cookies[cookieName]; var theCulture = theCultureCookie.Value; //say thanks in native tongue System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo(theCulture); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(theCulture); } else { //Didn't receive a cookie, don't speak their language } } } 

Set a cookie with Javascript if they click in a specific language and reload on the page.

0
source

All Articles