Skip to content

Commit

Permalink
Using string interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco committed May 5, 2016
1 parent 7e24747 commit bfda470
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions TagHelpers/LanguageSwitcherTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,73 +8,73 @@
namespace LanguageSwitcherTagHelper.TagHelpers
{
[HtmlTargetElement("language-switcher")]
public class LanguageSwitcherTagHelper : TagHelper
{
private IOptions<RequestLocalizationOptions> _locOptions;

public LanguageSwitcherTagHelper(IOptions<RequestLocalizationOptions> options)
public class LanguageSwitcherTagHelper : TagHelper
{
_locOptions = options;
}
private IOptions<RequestLocalizationOptions> _locOptions;

[ViewContext, HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public LanguageSwitcherTagHelper(IOptions<RequestLocalizationOptions> options)
{
_locOptions = options;
}

public DisplayMode Mode { get; set; } = DisplayMode.ImageAndText;
[ViewContext, HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }

public override void Process(TagHelperContext context, TagHelperOutput output)
{
var selectedCulture = ViewContext.HttpContext.Features.Get<IRequestCultureFeature>().RequestCulture.Culture;
var cultures = _locOptions.Value.SupportedUICultures;
public DisplayMode Mode { get; set; } = DisplayMode.ImageAndText;

output.TagName = null;

switch (Mode)
public override void Process(TagHelperContext context, TagHelperOutput output)
{
case DisplayMode.ImageAndText:
output.Content.AppendHtml(@"<ul class='nav navbar-nav navbar-right'>
var selectedCulture = ViewContext.HttpContext.Features.Get<IRequestCultureFeature>().RequestCulture.Culture;
var cultures = _locOptions.Value.SupportedUICultures;

output.TagName = null;

switch (Mode)
{
case DisplayMode.ImageAndText:
output.Content.AppendHtml($@"<ul class='nav navbar-nav navbar-right'>
<li class='dropdown'>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><img src='/images/" + selectedCulture.Name + ".png' /> " + selectedCulture.EnglishName + @"<span class='caret'></span></a>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><img src='/images/{selectedCulture.Name}.png' /> {selectedCulture.EnglishName}<span class='caret'></span></a>
<ul class='dropdown-menu'>");
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\"><img src='/images/{culture.Name}.png' /> {culture.EnglishName}</a></li>");
}
break;
case DisplayMode.Image:
output.Content.AppendHtml(@"<ul class='nav navbar-nav navbar-right'>
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\"><img src='/images/{culture.Name}.png' /> {culture.EnglishName}</a></li>");
}
break;
case DisplayMode.Image:
output.Content.AppendHtml($@"<ul class='nav navbar-nav navbar-right'>
<li class='dropdown'>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><img src='/images/" + selectedCulture.Name + @".png' /> <span class='caret'></span></a>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'><img src='/images/{selectedCulture.Name}.png' /> <span class='caret'></span></a>
<ul class='dropdown-menu'>");
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\"><img src='/images/{culture.Name}.png' /></a></li>");
}
break;
case DisplayMode.Text:
output.Content.AppendHtml(@"<ul class='nav navbar-nav navbar-right'>
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\"><img src='/images/{culture.Name}.png' /></a></li>");
}
break;
case DisplayMode.Text:
output.Content.AppendHtml($@"<ul class='nav navbar-nav navbar-right'>
<li class='dropdown'>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'> " + selectedCulture.EnglishName + @"<span class='caret'></span></a>
<a href='#' class='dropdown-toggle' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'> {selectedCulture.EnglishName}<span class='caret'></span></a>
<ul class='dropdown-menu'>");
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\">{culture.EnglishName}</a></li>");
}
break;
}
output.Content.AppendHtml(@"</ul>
foreach (var culture in cultures)
{
output.Content.AppendHtml($"<li><a href='#' onclick=\"useCookie('{culture.Name}')\">{culture.EnglishName}</a></li>");
}
break;
}
output.Content.AppendHtml(@"</ul>
</li>
</ul>");

output.Content.AppendHtml(@"<script type='text/javascript'>
output.Content.AppendHtml($@"<script type='text/javascript'>
function useCookie(code) {{
var culture = code;
var uiCulture = code;
var cookieValue = '" + CookieRequestCultureProvider.DefaultCookieName + @"=c='+code+'|uic='+code;
var cookieValue = '{CookieRequestCultureProvider.DefaultCookieName}=c='+code+'|uic='+code;
document.cookie = cookieValue;
window.location.reload();
}}
</script>");
}
}
}
}

0 comments on commit bfda470

Please sign in to comment.