Create multi-language structure with ASP.NET MVC @yasinkuyu
PM> Install-Package Localization
Usage
- <li>@Html.ActionLinkLocalization("English", "Index", "Locales", new { lang = "en_US" })</li>
- <li>@Html.ActionLinkLocalization("Türkçe", "Index", "Locales", new { lang = "tr_TR" })</li>
and more...
Or
- <a href="Locales/?lang=en_US">English</a>
- <a href="Locales/?lang=tr_TR">Türkçe</a>
and more...
Index.cshtml
@Html.Get("homepage") or @Html.Localize("homepage")
Video Tutorial
Requirements
Localization
en_US.xml
tr_TR.xml
and more...
Bin
Insya.Localization.dll
System.ComponentModel.DataAnnotations
Default locale
public void DefaultLocale( )
{
HttpCookie cookie = Request.Cookies.Get("CacheLang");
if ( cookie == null)
{
HttpCookie newCookie = new HttpCookie("CacheLang");
newCookie.Value = "en_US";
Response.Cookies.Add(newCookie);
}
}
Structure
Views
Xml file
<item id="homepage">Home Page</item>
Razor
@Html.Localize("homepage")
Or
@Html.Get("homepage")
Code Behind
Localization.Localize("homepage")
Or
Localization.Get("homepage")
@Html.ActionLinkLocalization()
@Html.ActionLocalization()
请发表评论