mirror of
https://github.com/chyzy/RSystem-MVC
synced 2024-11-22 15:20:27 +01:00
31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
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());
|
|
}
|
|
}
|
|
} |