2016-07-14 5 views
0

@Gerardo Grignoli의 here에 설명 된 방법을 사용했습니다. IStringLocalizer를 사용하려면 실패합니다.ASP.Net Core 1.0에서 IdentityErrorDescriber의 현지화

 private readonly IStringLocalizer _sharedLocalizer; 

    public CustomIdentityErrorDescriber(IStringLocalizerFactory stringLocalizerFactory) 
    { 
     _sharedLocalizer = stringLocalizerFactory.Create(typeof(SharedResource)); 
    } 

앱의 다른 위치에서 정상적으로 작동합니다. Startup.cs에서 여기

내 ConfigureServices :

public void ConfigureServices(IServiceCollection services) 
    { 
     // Add framework services. 
     services.AddDbContext<ApplicationDbContext>(
      options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); 

     //CustomIdentityErrorDescriber uses localization 
     services.AddLocalization(options => options.ResourcesPath = "Resources"); 

     // Configure supported cultures and localization options 
     services.Configure<RequestLocalizationOptions>(
      options => 
      { 
       var supportedCultures = new[] { new CultureInfo("en-US"), new CultureInfo("de-DE") }; 

       // State what the default culture for your application is. This will be used if no specific culture 
       // can be determined for a given request. 
       options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US"); 

       // You must explicitly state which cultures your application supports. 
       // These are the cultures the app supports for formatting numbers, dates, etc. 
       options.SupportedCultures = supportedCultures; 

       // These are the cultures the app supports for UI strings, i.e. we have localized resources for. 
       options.SupportedUICultures = supportedCultures; 
      }); 

     services.AddIdentity<ApplicationUser, IdentityRole>() 
      .AddErrorDescriber<CustomIdentityErrorDescriber>() 
      .AddEntityFrameworkStores<ApplicationDbContext>() 
      .AddDefaultTokenProviders(); 

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

     // Add application services. 
     services.AddTransient<IEmailSender, AuthMessageSender>(); 
     services.AddTransient<ISmsSender, AuthMessageSender>(); 

     services.AddSingleton<IMapper>(sp => _mapperConfiguration.CreateMapper()); 
    } 

만 로컬 라이저 호출에 사용되는 키가 표시됩니다.

 public override IdentityError PasswordMismatch() { return new IdentityError { Code = nameof(PasswordMismatch), Description = _sharedLocalizer["Shared_IncorrectPassword"] }; } 

답변

1

나는 그것을 발견했다. 그렇지 않으면 RESX 파일이 Resources.Resources

에서 검색되는

_sharedLocalizer = stringLocalizerFactory.Create("SharedResource", location: null); 

을 : 여기에 내가 사용해야합니다