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"]; 
} 

답변

0

깨끗한 것 같습니다. 프로젝트를 재건하여 문제를 해결했습니다. 이 마지막 구성이 작동합니다.

services.AddLocalization(options => options.ResourcesPath = "Resources"); 

services.AddMvc() 
    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix) 
    .AddDataAnnotationsLocalization(); 


services.Configure<RequestLocalizationOptions>(options => 
{ 
    var supportedCultures = new[] { new CultureInfo("en"), new CultureInfo("es") }; 

    options.DefaultRequestCulture = new RequestCulture(culture: "en", uiCulture: "en"); 
    options.SupportedCultures = supportedCultures; 
    options.SupportedUICultures = supportedCultures; 
});