44 lines
1.6 KiB
Plaintext
44 lines
1.6 KiB
Plaintext
@namespace Oqtane.Themes.Controls
|
|
@inherits ThemeControlBase
|
|
@using System.Globalization
|
|
@inject ILocalizationService LocalizationService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
@if (_supportedCultures != null)
|
|
{
|
|
<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 @(_selectedCulture == culture ? "active" : String.Empty)" href="#" @onclick="@(async e => await SetCultureAsync(culture))">@CultureInfo.GetCultureInfo(culture).DisplayName</a>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
|
|
@code{
|
|
private string _selectedCulture;
|
|
private string[] _supportedCultures;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
var interop = new Interop(JSRuntime);
|
|
_selectedCulture = await interop.GetLocalStorage("OqtaneCulture");
|
|
_supportedCultures = await LocalizationService.GetSupportedCultures();
|
|
}
|
|
|
|
private async Task SetCultureAsync(string culture)
|
|
{
|
|
if (culture != CultureInfo.CurrentUICulture.Name)
|
|
{
|
|
var interop = new Interop(JSRuntime);
|
|
await interop.SetLocalStorage("OqtaneCulture", culture);
|
|
|
|
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
|
}
|
|
}
|
|
}
|