1
0
mirror of https://github.com/chyzy/RSystem-MVC synced 2024-11-23 07:30:26 +01:00
RSystem-MVC-Fork/RSystem/Helpers/LanguageHelper.cs

31 lines
1.1 KiB
C#
Raw Normal View History

2018-04-17 11:20:49 +02:00
using System.Web.Mvc;
using System.Web.Routing;
namespace RSystem.Helpers
{
public static class LanguageHelper
{
public static MvcHtmlString LangSwitcher(this UrlHelper url, string Name, RouteData routeData, string lang)
{
var liTagBuilder = new TagBuilder("li");
var aTagBuilder = new TagBuilder("a");
aTagBuilder.AddCssClass("language-switch");
var routeValueDictionary = new RouteValueDictionary(routeData.Values);
if (routeValueDictionary.ContainsKey("lang"))
{
if(routeData.Values["lang"] as string != lang)
{
routeValueDictionary["lang"] = lang;
}
}
else if(lang!="pl")
routeValueDictionary.Add("lang",lang);
aTagBuilder.MergeAttribute("href", url.RouteUrl(routeValueDictionary));
aTagBuilder.SetInnerText(Name);
liTagBuilder.InnerHtml = aTagBuilder.ToString();
return new MvcHtmlString(liTagBuilder.ToString());
}
}
}