我遵循Razor Views中使用的模式,但在使用Razor Pages时,它找不到资源。我需要以不同的方式实现它吗?
Startup.cs :
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(o => {
o.ResourcesPath = "Resources";
});
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = "Resources")
.AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseRequestLocalization(new RequestLocalizationOptions {
DefaultRequestCulture = new RequestCulture("no"),
SupportedCultures = this.SupportedCultures,
SupportedUICultures = this.SupportedCultures
});
app.UseMvc();
}
private IList<CultureInfo> SupportedCultures
{
get
{
return new List<CultureInfo>
{
new CultureInfo("no"),
new CultureInfo("en")
};
}
}
_ViewImports.cshtml :
@using FFU.Home.Galaxy;
@using Microsoft.AspNetCore.Mvc.Localization;
@namespace FFU.Home.Galaxy.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, LC.Tools.Utility.TagHelpers
@inject IViewLocalizer _local
@inject IHtmlLocalizer<SharedResources> _shared
_Layout.cshtml :
<title>@_shared.GetString("Title") - Friends For Understanding</title>
_shared.GetString(“Title”)。ResourceNotFound为True
文件夹Resources包含两个名为 SharedResources.en.resx 和 SharedResources.no.resx
的文件