0
ASP.NET CORE MVCで翻訳をロードできません。.NET COREで異なる言語のリソースファイルがロードされない
マイstratupは、次のようになります。
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(
Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.Suffix,
opts => { opts.ResourcesPath = "Resources"; });
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("sk-SK"),
new CultureInfo("hu-HU"),
};
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new RequestCulture(culture: "sk-SK", uiCulture: "sk-SK");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
// Add framework services.
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<UserData, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
services.AddTransient<IProductService, ProductService>();
// Repository
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddScoped<IProductRepository, ProductRepository>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
ApplicationDbContext context)
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("sk-SK"),
new CultureInfo("hu-HU"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("sk-SK"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
//app.UseRequestCulture();
Mapper.Initialize(config =>
{
config.CreateMap<ProductData, ProductDetailViewModel>();
});
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
app.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseIdentity();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
DbInitializer.Initialize(context);
}
と私は
/Resources/Views/Product/Details.resx
/Resources/Views/Product/Details.sk.resx
/Resources/Views/Product/Details.sk-SK.resx
にリソースファイルを持っているし、私のDetails.cshtml
@using Microsoft.AspNetCore.Mvc.Localization
@inject IViewLocalizer Localizer
@{
ViewData["Title"] = Localizer["Manufacturer"];
}
問題は、私はいつもに起因してしまうことがありますDetails.sk.resxまたはDetails.sk-SK.resxからではなく、Details.resx
私は間違っていますか?ありがとう