Improve culture cookie handling and localization responses
Refactored GetCulture to return null if cookie is missing or invalid, and added GetCultureOrDefault for fallback. Updated TestLocalizerController and CultureMiddleware to use new methods for more accurate culture detection. Localizer now returns only the localized string value.
This commit is contained in:
@@ -24,7 +24,7 @@ namespace EnvelopeGenerator.Web.Controllers.Test
|
||||
}
|
||||
|
||||
[HttpGet("{key}")]
|
||||
public IActionResult Localize([FromRoute] string key) => Ok(_localizer[key]);
|
||||
public IActionResult Localize([FromRoute] string key) => Ok(_localizer[key].Value);
|
||||
|
||||
[HttpGet("fi-class")]
|
||||
public IActionResult GetFIClass(string? lang = null) => lang is null ? Ok(_cultures.FIClasses) : Ok(_cultures[lang]?.FIClass);
|
||||
@@ -39,6 +39,6 @@ namespace EnvelopeGenerator.Web.Controllers.Test
|
||||
: NotFound();
|
||||
|
||||
[HttpGet("culture/user")]
|
||||
public IActionResult GetUserCulture() => Request.Cookies.GetCulture() is string cult ? Ok(cult) : NotFound();
|
||||
public IActionResult GetUserCulture() => Request.Cookies.GetCultureOrDefault() is string cult ? Ok(cult) : NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user