45 lines
1.4 KiB
Plaintext
45 lines
1.4 KiB
Plaintext
@using Microsoft.Extensions.Options
|
|
@using TaikoWebUI.Settings
|
|
@inject NavigationManager NavigationManager
|
|
@inject IJSRuntime JsRuntime
|
|
@inject IOptions<WebUiSettings> Settings
|
|
|
|
<MudMenu Icon="@Icons.Material.Filled.Language" Color="Color.Inherit" Size="Size.Small" Dense="true">
|
|
<MudText Align="Align.Center" GutterBottom="true">@Localizer["UI Language"]</MudText>
|
|
<MudDivider />
|
|
@foreach (var culture in supportedCultures)
|
|
{
|
|
<MudMenuItem OnClick="() => RequestCultureChange(culture.Key)" OnTouch="() => RequestCultureChange(culture.Key)">@culture.Value</MudMenuItem>
|
|
}
|
|
</MudMenu>
|
|
|
|
@code {
|
|
private 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);
|
|
}
|
|
}
|