I'm trying to use localization in a .NET Core 3.1 application.
I've added the following to my Startup.cs
file:
services.AddLocalization(o => o.ResourcesPath = "Resources");
services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new[]
{
new CultureInfo("de-DE"),
new CultureInfo("en-US")
};
options.DefaultRequestCulture = new RequestCulture("de-DE", "de-DE");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
In the assembly where I need the localization, I've created a folder named Resources
and in it a resource file called MailTexte.de-DE.resx
. In the same assembly, but in a different folder, I've added a class MailTexte.cs
:
public class MailTexte
{
public string ConfirmationMailTitel { get; } = string.Empty;
}
In the class where I need the localization, I've injected IStringLocalizer<MailTexte> stringLocalizer
into the constructor and I'm trying to get the value with
var titel = this.stringLocalizer["ConfirmationMailTitel"];
Unfortunately, when looking at the result, it says "Resource not found = true".
Am I missing something?
Thanks in advance