35 lines
976 B
Plaintext
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);
|
|
}
|
|
|
|
}
|
|
|