Added initial language switch implementation.

pull/279/head
Halil İbrahim Kalkan 7 years ago
parent 2963033713
commit d7b4437dd8

@ -1,4 +1,5 @@
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.LanguageSwitch;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.UserMenu;
using Volo.Abp.DependencyInjection;
@ -12,6 +13,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars
{
Items =
{
new ToolbarItem(typeof(LanguageSwitchViewComponent)),
new ToolbarItem(typeof(UserMenuViewComponent))
}
};

@ -2,5 +2,5 @@
@model Toolbar
@foreach (var toolbarItem in Model.Items)
{
<text>@(await Component.InvokeAsync(toolbarItem.ComponentType))</text>
<span>@(await Component.InvokeAsync(toolbarItem.ComponentType))</span>
}

@ -0,0 +1,14 @@
@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.LanguageSwitch
@model LanguageSwitchViewComponentModel
<div class="dropdown d-inline">
<a class="btn btn-link dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@Model.CurrentLanguage.DisplayName
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
@foreach (var language in Model.OtherLanguages)
{
<a class="dropdown-item" href="/Abp/Languages/Switch?culture=@(language.Name)&uiCulture=@(language.Name)">@language.DisplayName</a>
}
</div>
</div>

@ -0,0 +1,11 @@
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.LanguageSwitch
{
public class LanguageInfo
{
public string Name { get; set; }
public string DisplayName { get; set; }
public string Icon { get; set; }
}
}

@ -0,0 +1,49 @@
using System.Globalization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.LanguageSwitch
{
public class LanguageSwitchViewComponent : AbpViewComponent
{
private readonly RequestLocalizationOptions _options;
public LanguageSwitchViewComponent(IOptions<RequestLocalizationOptions> options)
{
_options = options.Value;
}
public IViewComponentResult Invoke()
{
//TODO: Better handle culture & uiculture separation!
var model = new LanguageSwitchViewComponentModel
{
CurrentLanguage = new LanguageInfo
{
Name = CultureInfo.CurrentUICulture.Name,
DisplayName = CultureInfo.CurrentUICulture.DisplayName,
Icon = null //TODO!
}
};
foreach (var supportedUiCulture in _options.SupportedUICultures)
{
if (model.CurrentLanguage.Name == supportedUiCulture.Name)
{
continue;
}
model.OtherLanguages.Add(new LanguageInfo
{
Name = supportedUiCulture.Name,
DisplayName = supportedUiCulture.DisplayName,
Icon = null //TODO!
});
}
return View("~/Views/Shared/Components/Theme/MainNavbar/Toolbar/Items/LanguageSwitch/Default.cshtml", model);
}
}
}

@ -0,0 +1,16 @@
using System.Collections.Generic;
namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Views.Shared.Components.Theme.MainNavbar.Toolbar.Items.LanguageSwitch
{
public class LanguageSwitchViewComponentModel
{
public LanguageInfo CurrentLanguage { get; set; }
public List<LanguageInfo> OtherLanguages { get; }
public LanguageSwitchViewComponentModel()
{
OtherLanguages = new List<LanguageInfo>();
}
}
}

@ -7,9 +7,17 @@
@inject IHtmlLocalizer<AbpUiResource> L
@if (CurrentUser.IsAuthenticated)
{
<span style="color: #fff">@CurrentUser.UserName</span> <text>(<a href="/Account/Logout">@L["Logout"]</a>)</text>
<div class="dropdown d-inline">
<a class="btn btn-link dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
@CurrentUser.UserName
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="/Account/Logout">@L["Logout"]</a>
</div>
</div>
}
else
{
<a href="/Account/Login">Login</a>
<a href="/Account/Login">@L["Login"]</a>
}

@ -19,6 +19,10 @@
<EmbeddedResource Include="Views\**\*.cshtml" />
<EmbeddedResource Include="wwwroot\**\*.*" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Remove="Views\Shared\Components\Theme\MainNavbar\Toolbar\Items\UserMenu\Default.cshtml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared\Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.csproj" />

@ -1,3 +1,8 @@
body {
padding-top: 5rem;
}
#main-navbar-tools a.dropdown-toggle {
text-decoration: none;
color: #fff;
}

@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc;
namespace Volo.Abp.AspNetCore.Mvc.Localization
{
[Area("Abp")]
[Route("Abp/Languages/[action]")]
public class AbpLanguagesController : AbpController
{
[HttpGet]
public IActionResult Switch(string culture, string uiCulture = "") //TODO: Implement return URL
{
//TODO: Check allowed languages and so on...
Response.Cookies.Append(CookieRequestCultureProvider.DefaultCookieName, $"c={culture}|uic={uiCulture ?? culture}");
return Redirect("/");
}
}
}
Loading…
Cancel
Save