47 lines
1.7 KiB
Plaintext
47 lines
1.7 KiB
Plaintext
@namespace Oqtane.Themes.Controls
|
|
@inherits ThemeControlBase
|
|
@using System.Globalization
|
|
@using Microsoft.AspNetCore.Localization;
|
|
@using Oqtane.Models
|
|
@inject ILocalizationService LocalizationService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
@if (_supportedCultures != null && Visible)
|
|
{
|
|
<div class="btn-group" role="group">
|
|
<button id="btnCultures" type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
|
<span class="oi oi-globe"></span>
|
|
</button>
|
|
<div class="dropdown-menu" aria-labelledby="btnCultures">
|
|
@foreach (var culture in _supportedCultures)
|
|
{
|
|
<a class="dropdown-item @(CultureInfo.CurrentUICulture.Name == culture.Name ? "active" : String.Empty)" href="#" @onclick="@(async e => await SetCultureAsync(culture.Name))">@culture.DisplayName</a>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code{
|
|
private IEnumerable<Culture> _supportedCultures;
|
|
|
|
[Parameter]
|
|
public bool Visible { get; set; } = true;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_supportedCultures = await LocalizationService.GetCulturesAsync();
|
|
}
|
|
|
|
private async Task SetCultureAsync(string culture)
|
|
{
|
|
if (culture != CultureInfo.CurrentUICulture.Name)
|
|
{
|
|
var interop = new Interop(JSRuntime);
|
|
var localizationCookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture));
|
|
await interop.SetCookie(CookieRequestCultureProvider.DefaultCookieName, localizationCookieValue, 360);
|
|
|
|
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
|
}
|
|
}
|
|
}
|