Added a signature legal agreement warning and integrated the resource file (resx) as a JavaScript object into the _Layout.cshtml file. This enables the agreement warning to support multiple languages.
This commit is contained in:
33
EnvelopeGenerator.Web/Controllers/LocalizationController.cs
Normal file
33
EnvelopeGenerator.Web/Controllers/LocalizationController.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using EnvelopeGenerator.Application.Resources;
|
||||
using Ganss.Xss;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace EnvelopeGenerator.Web.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class LocalizationController : ControllerBase
|
||||
{
|
||||
private readonly IStringLocalizer<Resource> _localizer;
|
||||
private readonly ILogger<LocalizationController> _logger;
|
||||
private readonly HtmlSanitizer _sanitizer;
|
||||
|
||||
public LocalizationController(IStringLocalizer<Resource> localizer, ILogger<LocalizationController> logger, HtmlSanitizer sanitizer)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_logger = logger;
|
||||
_sanitizer = sanitizer;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult GetLocalized([FromQuery] string[]? name = null, [FromQuery] string[]? ignore = null)
|
||||
{
|
||||
ignore ??= Array.Empty<string>();
|
||||
var pairs = name?.ToDictionary(n => n, n => _localizer[n].Value)
|
||||
?? _localizer.GetAllStrings().Where(ls => !ignore.Contains(ls.Name)).ToDictionary(ls => ls.Name, ls => ls.Value); ;
|
||||
return Ok(pairs);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user