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
자원 경로 : 문화가 제대로 es
로 설정되어 있기 때문에
~/Resources/Views/Home/Index.es.resx
Home => Inicio
그래서, 나는이 일을 기대 :
@inject IViewLocalizer Localizer
@{
ViewData["Title"] = Localizer["Home"];
}