After some searching, I’ve written the following code in Program.cs:
#region Localization
builder.Services.AddLocalization(option =>
{
option.ResourcesPath = "Resources";
});
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[] { "en", "ru" };
options.SetDefaultCulture(supportedCultures[0])
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
});
#endregion
app.UseRequestLocalization();
I’m trying to use localization like this:
[ApiController]
[Route("api/[controller]")]
public class AuthController : ControllerBase
{ private readonly static Logger _logger = LogManager.GetCurrentClassLogger();
private readonly IStringLocalizer<AuthController> _localizer;
public AuthController(IStringLocalizer<AuthController> localizer)
{
_localizer = localizer;
}
[HttpGet("test")]
public string Test()
{
return _localizer["About Title"];
}
}
I’ve tried adding ui-culture=ru to the request and setting Accept-Language to ru, but the server still returns “About Title”
I wanted to get an answer in one of the localization languages
New contributor
Polite Human is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.