-
-
Notifications
You must be signed in to change notification settings - Fork 752
Expand file tree
/
Copy pathLanguageSelector.razor
More file actions
32 lines (30 loc) · 1.1 KB
/
LanguageSelector.razor
File metadata and controls
32 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@using BlazorHero.CleanArchitecture.Shared.Constants.Localization
@inject Microsoft.Extensions.Localization.IStringLocalizer<LanguageSelector> _localizer
@if (LocalizationConstants.SupportedLanguages.Length > 1)
{
<MudMenu Icon="@Icons.Material.Outlined.Translate" Color="Color.Inherit" Direction="Direction.Bottom" OffsetY="true" Dense="true">
@foreach (var language in LocalizationConstants.SupportedLanguages)
{
<MudMenuItem OnClick="(()=> ChangeLanguageAsync(language.Code))">@_localizer[language.DisplayName]</MudMenuItem>
}
</MudMenu>
}
@code
{
private async Task ChangeLanguageAsync(string languageCode)
{
var result = await _clientPreferenceManager.ChangeLanguageAsync(languageCode);
if (result.Succeeded)
{
_snackBar.Add(result.Messages[0], Severity.Success);
_navigationManager.NavigateTo(_navigationManager.Uri, forceLoad: true);
}
else
{
foreach (var error in result.Messages)
{
_snackBar.Add(error, Severity.Error);
}
}
}
}