QrRapido/Providers/CustomRouteDataRequestCultureProvider.cs
Ricardo Carneiro 162e28ae5a
All checks were successful
Deploy QR Rapido / test (push) Successful in 43s
Deploy QR Rapido / build-and-push (push) Successful in 16m43s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 1m55s
fix: PIX + idioma espanhol e SEO
2026-01-25 12:04:24 -03:00

38 lines
1.6 KiB
C#

using Microsoft.AspNetCore.Localization;
namespace QRRapidoApp.Providers
{
public class CustomRouteDataRequestCultureProvider : IRequestCultureProvider
{
public Task<ProviderCultureResult?> DetermineProviderCultureResult(HttpContext httpContext)
{
// First check if the middleware has already determined the culture (e.g. for static routes like /es-PY/pix)
if (httpContext.Items.TryGetValue("Culture", out var cultureItem) && cultureItem is string cultureFromMiddleware)
{
var supportedCultures = new[] { "pt-BR", "es-PY" };
if (supportedCultures.Contains(cultureFromMiddleware))
{
return Task.FromResult<ProviderCultureResult?>(new ProviderCultureResult(cultureFromMiddleware, cultureFromMiddleware));
}
}
// Fallback to route data (standard routing)
var routeValues = httpContext.GetRouteData()?.Values;
if (routeValues != null && routeValues.TryGetValue("culture", out var cultureValue))
{
var culture = cultureValue?.ToString();
if (!string.IsNullOrEmpty(culture))
{
// Map the supported cultures
var supportedCultures = new[] { "pt-BR", "es-PY" };
if (supportedCultures.Contains(culture))
{
return Task.FromResult<ProviderCultureResult?>(new ProviderCultureResult(culture, culture));
}
}
}
return Task.FromResult<ProviderCultureResult?>(null);
}
}
}