Add endpoints for culture detection and improve cookie parsing

Added two endpoints to TestLocalizerController for retrieving culture from Accept-Language and user cookies. Enhanced GetCulture extension to parse and return the actual culture string from cookies. Updated usings for new extension methods.
This commit is contained in:
2026-02-12 16:11:40 +01:00
parent 745e9c7bfe
commit ab57dd4cee
2 changed files with 24 additions and 1 deletions

View File

@@ -61,7 +61,18 @@ public static class WebExtensions
#region Cookie
public static string? GetCulture(this IRequestCookieCollection cookies)
=> cookies[CookieRequestCultureProvider.DefaultCookieName];
{
var cookieValue = cookies[CookieRequestCultureProvider.DefaultCookieName];
if (!string.IsNullOrEmpty(cookieValue))
{
var culture = CookieRequestCultureProvider.ParseCookieValue(cookieValue)?.Cultures.FirstOrDefault().Value;
if (!string.IsNullOrEmpty(culture))
return culture;
}
return null;
}
public static void SetCulture(this IResponseCookies cookies, string culture)
{