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.
source share