Esempio n. 1
0
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var lang = filterContext.RequestContext.HttpContext.Request["lang"];

            if (!string.IsNullOrEmpty(lang))
            {
                McdAMContext.SetLanguage(lang);
            }
        }
Esempio n. 2
0
        private void SetAppLangulage()
        {
            var langCookie = HttpContext.Current.Request.Cookies["Mcd_AM.LangTag"];

            if (langCookie != null)
            {
                var langtag = langCookie.Value;

                i18n.LanguageTag lt = i18n.LanguageTag.GetCachedInstance(langtag);
                if (lt.IsValid())
                {
                    // Set persistent cookie in the client to remember the language choice.
                    Response.Cookies.Add(new HttpCookie("Mcd_AM.LangTag")
                    {
                        Value    = lt.ToString(),
                        HttpOnly = true,
                        Expires  = DateTime.UtcNow.AddYears(1)
                    });

                    switch (langtag)
                    {
                    case "zh":
                        McdAMContext.SetLanguage("ZHCN");
                        break;

                    case "en":
                        McdAMContext.SetLanguage("ENUS");
                        break;
                    }
                }
                // Owise...delete any 'language' cookie in the client.
                else
                {
                    var cookie = Response.Cookies["Mcd_AM.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.Current.SetPrincipalAppLanguageForRequest(lt);
            }
        }