@* Components/CultureSwitcher.razor *@
@inject IJSRuntime JSRuntime
@inject NavigationManager Navigation
@code {
[Parameter]
public string[] SupportedCultures { get; set; } = new[]
{
"en",
"ar",
"es",
"de"
};
private string SelectedCulture
{
get => CultureInfo.CurrentUICulture.Name;
set
{
if (CultureInfo.CurrentUICulture.Name != value)
{
// Persist selection
JSRuntime.InvokeVoidAsync("cultureInfo.set", value);
// Reload to apply new culture
Navigation.NavigateTo(Navigation.Uri, forceLoad: true);
}
}
}
}