在Razor页面中无法使用本地化找到SharedResource

时间:2018-04-21 10:16:49

标签: c# asp.net-mvc asp.net-core razor-pages

我遵循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

的文件

0 个答案:

没有答案