1
0
mirror of synced 2024-11-24 15:00:16 +01:00
TaikoLocalServer/TaikoWebUI/Shared/ChooseLanguage.razor
2024-03-09 12:04:31 -05:00

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);
}
}