@using System.Globalization @using Microsoft.AspNetCore.Localization @code { [CascadingParameter] private HttpContext? HttpContext { get; set; } // Pin whatever the middleware negotiated (Accept-Language, or the configured default) into the // culture cookie on the very first visit. Without this the language picker would be the only // thing that ever writes the cookie, so a reader whose browser asked for German would be served // German until the moment they touched the picker — and the picker would open showing English. protected override void OnInitialized() => HttpContext?.Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, CookieRequestCultureProvider.MakeCookieValue( new RequestCulture(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture)), new CookieOptions { Path = "/", Expires = DateTimeOffset.UtcNow.AddYears(1), SameSite = SameSiteMode.Lax, HttpOnly = true, IsEssential = true, }); }