1
0
mirror of synced 2025-01-19 16:08:41 +01:00
TaikoLocalServer/TaikoWebUI/Shared/ChooseLanguage.razor
2024-01-23 01:23:11 +08:00

35 lines
976 B
Plaintext

@using System.Globalization;
@inject NavigationManager NavigationManager
@inject IJSRuntime JSRuntime
<MudMenu Icon="@Icons.Material.Filled.Language" Color="Color.Inherit">
@foreach (var culture in SupportedCultures)
{
<MudMenuItem OnClick="() => RequestCultureChange(culture.Key)">@culture.Value</MudMenuItem>
}
</MudMenu>
@code{
public readonly Dictionary<CultureInfo, string> SupportedCultures = new()
{
{ new CultureInfo("en-US"), "English" },
{ new CultureInfo("zh-Hans"), "简体中文" },
{ new CultureInfo("ja"), "日本語" },
};
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);
}
}