0
我遇到了一個奇怪的問題,並未在ASP.NET Core 1中發生。由於某種原因,如果我使用Index.es.cshtml
該視圖已正確找到,但如果我使用Localizer["Home"]
Index.cshtml
它不會被翻譯。重複每種語言的觀點並不是很理想。視圖已本地化,但沒有找到資源
public void ConfigureServices(IServiceCollection services)
{
var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("es") };
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture("en");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseRequestLocalization();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
}
查看路徑:
~/Views/Home/Index.cshtml
資源路徑:
~/Resources/Views/Home/Index.es.resx
Home => Inicio
所以,我預計這個工作,因爲文化已正確設置爲es
:
@inject IViewLocalizer Localizer
@{
ViewData["Title"] = Localizer["Home"];
}