My Razor page looks like this.
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
<h1>@Localizer["Index"]</h1>
...
My Startup.cs contains the following.
public void ConfigureServices(IServiceCollection services)
{
...
services.AddLocalization(a => a.ResourcesPath = "/");
services.Configure<RequestLocalizationOptions>(a =>
{
CultureInfo[] supportedCultures = {
new CultureInfo("sv-SE"),
new CultureInfo("se")
};
a.DefaultRequestCulture = new RequestCulture("se");
a.SupportedCultures = supportedCultures;
a.SupportedUICultures = supportedCultures;
});
...
}
I placed a file called Controllers.HomeController.se.resx directly in the project's root. The controller HomeController contains the injection.
public class HomeController : Controller
{
private readonly Context _context;
private readonly IStringLocalizer<HomeController> _localizer;
public HomeController(Context context, IStringLocalizer<HomeController> localizer)
{
_context = context;
_localizer = localizer;
}
...
}
The application doesn't crash but the string renedered is Index and not the value from the RESX file. I've tried to follow the docs as closely as possible but apparently I've missed something. I need help finding what that would be.
I breakpointed and checked the value of _localizer["Index"] in the constructor. As expected, the flag for the file not being found is set to true. Checking the value of SearchedLocation gives me Web...Controllers.MemberController. I can't tell if those three dots is the correct one for the RESX file in the project's root. I was expecting se somewhere in the name too.