局在はStartup class
で設定され、アプリケーション全体で使用することができます。 AddLocalization
メソッドは、リソースおよびローカリゼーションを定義するためにConfigureServices
で使用されます。これはConfigureメソッドで使用できます。ここでは、RequestLocalizationOptions
を定義し、UseRequestLocalization
メソッドを使用してスタックに追加することができます。
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization()
.AddDataAnnotationsLocalization();
services.AddScoped<LanguageActionFilter>();
services.Configure<RequestLocalizationOptions>(
options =>
{
var supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("de-CH"),
new CultureInfo("fr-CH"),
new CultureInfo("it-CH")
};
options.DefaultRequestCulture = new RequestCulture(culture: "en-US", uiCulture: "en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
}
ありがとうございます。 :) – Nik