I started to develop Multi Language site and By viewing Youtube video i coded that.In my Index Page it works very nice.But i have no idea about how to use that to About Us page(my second view).Could you please give me a help to solve this issue. / This is MVC site.
My Site Can access like this
http://localhost:10228 <-- For English
http://localhost:10228/Home/ChangeLanguage?lang=hi <-- For Hindi
Problem is When i go to another view like AboutUs It doesn't detect the language.(always show in English )
Global.asax
protected void Application_AquireRequestState(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context != null && context.Request.Cookies != null)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies["_lang"];
if (cookie != null && cookie.Value != null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cookie.Value);
Thread.CurrentThread.CurrentCulture = new CultureInfo(cookie.Value);
}
}
}
_Layout.cshtml
@using InNews.App_GlobalResources
@Html.ActionLink(multilanguage.English, "ChangeLanguage", "Home", new { lang = "en" }, null)
@Html.ActionLink(multilanguage.Hindi, "ChangeLanguage", "Home", new { lang = "hi" }, null)
@Html.ActionLink(multilanguage.Japanese, "ChangeLanguage", "Home", new { lang = "jp" }, null)
_MenuPartial.cshtml(This is rendered to the layout page)
@using InNews.App_GlobalResources
<li>@Html.ActionLink(multilanguage.Home, "Index", "Home")</li>
<li>@Html.ActionLink(multilanguage.AboutUs, "AboutUs", "Home")</li>
HomeController
public ActionResult Index()
{
return View();
}
public ActionResult ChangeLanguage(string lang)
{
if (lang != null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
}
else
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
}
HttpCookie cookie = new HttpCookie("_lang");
cookie.Value = lang;
Response.Cookies.Add(cookie);
return View("Index");
}
public ActionResult AboutUs()
{
return View();
}
Could you please help me to solve this issue.