sumatube/SumaTube/Middle/RequestLocalizationMiddleware.cs
2025-04-20 23:33:46 -03:00

30 lines
775 B
C#

namespace SumaTube.Middle
{
using Microsoft.AspNetCore.Http;
using System.Globalization;
using System.Threading.Tasks;
public class RequestLocalizationMiddleware
{
private readonly RequestDelegate _next;
public RequestLocalizationMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
var cookie = context.Request.Cookies["Language"];
if (!string.IsNullOrEmpty(cookie))
{
var culture = new CultureInfo(cookie);
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
}
await _next(context);
}
}
}