当前文化不存在清单

No manifests exist for the current culture

自学 .Net Core asp。

我已将资源文件添加到我的解决方案中。 我在这个资源文件中添加了一个测试字符串。 我现在正尝试在我的控制器中访问此测试 string/key。

所以,在我的 startup.cs 我有这个:

public void ConfigureServices(IServiceCollection services)
{
    services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });

    services.AddMvc()
       .AddViewLocalization(
            LanguageViewLocationExpanderFormat.Suffix,
                opts => { opts.ResourcesPath = "Resources"; })
    .AddDataAnnotationsLocalization();

    services.Configure<RequestLocalizationOptions>(
        opts =>
        {
            var supportedCultures = new List<CultureInfo>
            {
                    new CultureInfo("en-GB"),
                    new CultureInfo("en-US"),
                    new CultureInfo("en"),
                    new CultureInfo("fr-FR"),
                    new CultureInfo("fr"),
            };

            opts.DefaultRequestCulture = new RequestCulture("en");
            // Formatting numbers, dates, etc.
            opts.SupportedCultures = supportedCultures;
            // UI strings that we have localized.
            opts.SupportedUICultures = supportedCultures;
        });
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, WorkerContext context)
{
    app.UseStaticFiles();

    var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
    app.UseRequestLocalization(options.Value);

    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

在我的控制器中我有这个:

public class HomeController : Controller
{
    private readonly IStringLocalizer<HomeController> _localizer;
    public HomeController(IStringLocalizer<HomeController> localizer)
    {
        _localizer = localizer;
    }
}

我的资源文件存储在这里:

我对这个资源文件的属性是:

我这里设置了一个断点:

_localizer = 定位器;

我检查了这个变量,但如您所见,尚未找到清单...

请问我有什么不明白的?

第 1 期

基于https://docs.microsoft.com/en-us/aspnet/core/fundamentals/localization

您应该将 Resources 放在根目录下名为 Resources 的文件夹中。你在 Properties 文件夹下...

此代码块(与您的略有不同)
Statup.cs

services.AddLocalization(options => options.ResourcesPath = "Resources");

在我的项目中为我解析到该文件夹​​。


第 2 期

另一个问题是您的命名不正确。看看名为 Working With Resource Files 的部分,它比我把它放在这里更好地向您解释。

在我完成您的所有步骤时,您似乎只是描述了我的问题,但实际上并没有什么。

我注意到本地化需要扩展 class 但该扩展的 DLL 不在我的依赖项中。无论如何,我使用 NuGet 安装了几个依赖项,我的项目运行得非常棒。尝试安装以下并重试。

Microsoft.Extensions.Localization, Microsoft.AspNetCore.Mvc.Localization