@using System.Globalization @using Oqtane.Models @namespace Oqtane.Themes.Controls @inherits ThemeControlBase @inject ILanguageService LanguageService @inject ILocalizationCookieService LocalizationCookieService @inject NavigationManager NavigationManager @if (_supportedCultures?.Count() > 1) {
} @code{ private IEnumerable _supportedCultures; private string MenuAlignment = string.Empty; [Parameter] public string DropdownAlignment { get; set; } = string.Empty; // Empty or Left or Right [Parameter] public string ButtonClass { get; set; } = "btn-outline-secondary"; protected override async Task OnParametersSetAsync() { MenuAlignment = DropdownAlignment.ToLower() == "right" ? "dropdown-menu-end" : string.Empty; _supportedCultures = PageState.Languages.Select(l => new Culture { Name = l.Code, DisplayName = l.Name }); if (PageState.QueryString.ContainsKey("culture")) { var culture = PageState.QueryString["culture"]; if (_supportedCultures.Any(item => item.Name == culture)) { await LocalizationCookieService.SetLocalizationCookieAsync(culture); } NavigationManager.NavigateTo(NavigationManager.Uri.Replace($"?culture={culture}", "")); } } private async Task SetCultureAsync(string culture) { if (culture != CultureInfo.CurrentUICulture.Name) { var localizationCookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)); var interop = new Interop(JSRuntime); await interop.SetCookie(CookieRequestCultureProvider.DefaultCookieName, localizationCookieValue, 360, true, "Lax"); NavigationManager.NavigateTo(NavigationManager.Uri, true); } } }