45 lines
1.3 KiB
Plaintext
45 lines
1.3 KiB
Plaintext
@using System.Globalization;
|
|
@using Microsoft.Extensions.Options
|
|
@using TaikoWebUI.Settings
|
|
@inject NavigationManager NavigationManager
|
|
@inject IJSRuntime JSRuntime
|
|
@inject IOptions<WebUiSettings> Settings
|
|
|
|
<MudMenu Icon="@Icons.Material.Filled.Translate" Color="Color.Inherit" Size="Size.Small" Dense="true">
|
|
@foreach (var culture in SupportedCultures)
|
|
{
|
|
<MudMenuItem OnClick="() => RequestCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
|
}
|
|
</MudMenu>
|
|
|
|
@code {
|
|
public Dictionary<CultureInfo, string> SupportedCultures = new();
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
base.OnInitialized();
|
|
foreach (var language in Settings.Value.SupportedLanguages)
|
|
{
|
|
SupportedCultures.Add(new CultureInfo(language.CultureCode), language.DisplayName);
|
|
}
|
|
|
|
if (SupportedCultures.Count == 0)
|
|
{
|
|
SupportedCultures.Add(new CultureInfo("en-US"), "English");
|
|
}
|
|
}
|
|
|
|
private void RequestCultureChange(CultureInfo newCulture)
|
|
{
|
|
if (Equals(CultureInfo.CurrentCulture, newCulture))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var js = (IJSInProcessRuntime)JSRuntime;
|
|
js.InvokeVoid("blazorCulture.set", newCulture.Name);
|
|
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
|
|
}
|
|
|
|
}
|