public ActionResult SetLanguage(string langtag, string returnUrl) { // If valid 'langtag' passed. LanguageTag lt = LanguageTag.GetCachedInstance(langtag); if (lt.IsValid()) { // Set persistent cookie in the client to remember the language choice. Response.Cookies.Add(new HttpCookie("i18n.langtag") { Value = lt.ToString(), HttpOnly = true, Expires = DateTime.UtcNow.AddYears(1) }); } // Owise...delete any 'language' cookie in the client. else { var cookie = Response.Cookies["i18n.langtag"]; if (cookie != null) { cookie.Value = null; cookie.Expires = DateTime.UtcNow.AddMonths(-1); } } // Update PAL setting so that new language is reflected in any URL patched in the // response (Late URL Localization). HttpContext.SetPrincipalAppLanguageForRequest(lt); // Patch in the new langtag into any return URL. if (returnUrl.IsSet()) { returnUrl = LocalizedApplication.Current.UrlLocalizerForApp.SetLangTagInUrlPath(HttpContext, returnUrl, UriKind.RelativeOrAbsolute, lt == null ? null : lt.ToString()).ToString(); } // Redirect user agent as approp. Bootstrapper.Run(); return(Redirect(returnUrl)); }
public void AddAppLanguage(string langtag) { m_appLanguages[langtag] = LanguageTag.GetCachedInstance(langtag); }