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:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user