I would like to add localized strings in my view.
Resources/Views.Account.Login.en-US.resx
Views/Account/Login.cshtml
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
<div>
@System.Threading.Thread.CurrentThread.CurrentCulture.Name
@System.Threading.Thread.CurrentThread.CurrentUICulture.Name
@Localizer["Key"]
</div>
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var options = new RequestLocalizationOptions
{
SupportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US")
},
SupportedUICultures = new List<CultureInfo>
{
new CultureInfo("en-US")
},
DefaultRequestCulture = new RequestCulture("en-US")
};
app.UseRequestLocalization(options);
}
The generated HTML
en-US
en-US
Key
The expected HTML
en-US
en-US
Hello
Have I forgotten a step?
EDIT
If the resources is named Resources/Views.Account.Login.resx
is work correctly. Why ?