locked
AspNet Core 3.1 : No Manifest exist for the current culture RRS feed

  • Question

  • User-1602535186 posted
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.AspNetCore.Authorization;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Localization;
    
    namespace DemoApp
    {
        [Produces("application/json")]
        [Route("api/[controller]")]
        public class TranslationsController : Controller
        {
            private readonly IStringLocalizer<SharedResource> _localizer;
    
            public TranslationsController(IStringLocalizer<SharedResource> localizer)
            {
                _localizer = localizer;
            }
    
            [HttpGet]
            public ActionResult List()
            {
                Dictionary<string, string> translations = _localizer.GetAllStrings().ToDictionary(x => x.Name, x => x.Value);
                return new JsonResult(translations);
            }
        }
    }

    I am getting error for this _localizer.GetAllStrings() in my aspnet core 3.1 application. I am having resx file with name ShareResource.resx in my resources folder

    Thursday, April 16, 2020 3:10 PM

Answers

  • User-854763662 posted

    Hi TechAspirant ,

    Here is a working demo :

    Startup.cs

    public void ConfigureServices(IServiceCollection services)
            {
                services.AddLocalization(options => options.ResourcesPath = "Resources");
    
                services.AddControllersWithViews()
                    .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
                    .AddDataAnnotationsLocalization(); 
            }
    
            // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
            public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
            {
                //...
    
                var supportedCultures = new[]
                {
                    new CultureInfo("en-US"),
                    new CultureInfo("fr"),
                };
    
                app.UseRequestLocalization(new RequestLocalizationOptions
                {
                    DefaultRequestCulture = new RequestCulture("en-US"),
                    // Formatting numbers, dates, etc.
                    SupportedCultures = supportedCultures,
                    // UI strings that we have localized.
                    SupportedUICultures = supportedCultures
                });
    
                app.UseHttpsRedirection();
                app.UseStaticFiles();
    
                app.UseRouting();
    
                app.UseAuthorization();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Home}/{action=Index}/{id?}");
                });
            }

    Resource files path and SharedResource.cs which is created in the root of the project

    Controller

        [Produces("application/json")]
        [Route("api/[controller]")]
        public class TranslationsController : Controller
        {
            private readonly IStringLocalizer<SharedResource> _localizer;
    
            public TranslationsController(IStringLocalizer<SharedResource> localizer)
            {
                _localizer = localizer;
            }
    
            [HttpGet]
            public ActionResult List()
            {
                Dictionary<string, string> translations = _localizer.GetAllStrings().ToDictionary(x => x.Name, x => x.Value);
                return new JsonResult(translations);
            }
        }

    Here is my demo link, you could refer to.

    Best Regards,

    Sherry

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, April 17, 2020 7:46 AM