我开始开发多语言网站并通过查看Youtube视频我编码了。在我的索引页面它工作得很好。但我不知道如何使用它关于我们页面(我的第二个视图)。你能不能请帮我解决这个问题。 /这是MVC网站。
我的网站可以像这样访问
http://localhost:10228< - 对于英语
http://localhost:10228/Home/ChangeLanguage?lang=hi< - 印地语
问题是当我转到另一个像AboutUs这样的视图时它没有检测到语言。(总是以英文显示)
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);
}
}
}
@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)
@using InNews.App_GlobalResources
<li>@Html.ActionLink(multilanguage.Home, "Index", "Home")</li>
<li>@Html.ActionLink(multilanguage.AboutUs, "AboutUs", "Home")</li>
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();
}
请你帮我解决这个问题。