Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No manifests exist for the current culture

teaching myself about .Net Core asp.

I have added a resource file to my solution. I have added a test string to this resource file. I am now trying to access this test string/key within my controller.

So, in my startup.cs I have this:

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?}");
    });
}

In my Controller I have this:

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

My resource file stored here:

enter image description here

My properties for this resource file are: enter image description here

I set a breakpoint here:

_localizer = localizer;

I inspect this variable and as you see the manifest has not been found... enter image description here

What am i not understanding please?

like image 787
Andrew Simpson Avatar asked Nov 02 '25 23:11

Andrew Simpson


2 Answers

Issue 1

Based on https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization

You're supposed to put your Resources in a folder called Resources under the root. You have it under the Properties folder...

This code block (slightly different from yours)
Statup.cs

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

resolves to that folder for me in my projects.

enter image description here


Issue 2

The other issue is your naming isn't done right. Take a look at the section called Working With Resource Files which will do a better job of explaining it to you than me putting it here.

like image 106
Svek Avatar answered Nov 04 '25 13:11

Svek


It looks like you just described my issue as I went through all of your steps, but it was nothing.

I noticed that localization required an extension class but the DLL for that extension was not in my dependencies. Anyway I used NuGet to install couple of dependencies and my project worked like a charm. Try to install the following and try again.

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

like image 21
mdASFARi Avatar answered Nov 04 '25 14:11

mdASFARi