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:
My properties for this resource file are:
I set a breakpoint here:
_localizer = localizer;
I inspect this variable and as you see the manifest has not been found...
What am i not understanding please?
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