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