The Localize endpoint in TestLocalizerController now accepts the "key" parameter as a route parameter instead of a query string. The method signature was updated to use [FromRoute], and the route template was modified to include "{key}". This changes the endpoint usage from /localize?key=de_DE to /localize/de_DE.
45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using AngleSharp.Common;
|
|
using DigitalData.Core.API;
|
|
using EnvelopeGenerator.Application.Resources;
|
|
using EnvelopeGenerator.Web.Extensions;
|
|
using EnvelopeGenerator.Web.Models;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Localization;
|
|
using System.Globalization;
|
|
|
|
namespace EnvelopeGenerator.Web.Controllers.Test
|
|
{
|
|
[ApiController]
|
|
[Route("api/test/[controller]")]
|
|
public class TestLocalizerController : ControllerBase
|
|
{
|
|
private readonly IStringLocalizer _localizer;
|
|
private readonly Cultures _cultures;
|
|
|
|
public TestLocalizerController(IStringLocalizer<Resource> localizer, Cultures cultures)
|
|
{
|
|
_localizer = localizer;
|
|
_cultures = cultures;
|
|
}
|
|
|
|
[HttpGet("{key}")]
|
|
public IActionResult Localize([FromRoute] string key) => Ok(_localizer[key]);
|
|
|
|
[HttpGet("fi-class")]
|
|
public IActionResult GetFIClass(string? lang = null) => lang is null ? Ok(_cultures.FIClasses) : Ok(_cultures[lang]?.FIClass);
|
|
|
|
[HttpGet("culture")]
|
|
public IActionResult GetCultures(string? lang = null) => lang is null ? Ok(_cultures) : Ok(_cultures[lang]);
|
|
|
|
[HttpGet("culture/accept-language")]
|
|
public IActionResult GetCultureByAcceptLanguage()
|
|
=> HttpContext.GetCultureByAcceptLanguage()?.Name is string culture
|
|
? Ok(culture)
|
|
: NotFound();
|
|
|
|
[HttpGet("culture/user")]
|
|
public IActionResult GetUserCulture() => Request.Cookies.GetCulture() is string cult ? Ok(cult) : NotFound();
|
|
}
|
|
}
|