1
votes

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

1

1 Answers

0
votes

If the resources folder is not in the asp.net project, you must do the following:

        private readonly IStringLocalizer _stringLocalizer;
     
        public TestController(IStringLocalizerFactory stringLocalizerFactory)
        {
           _stringLocalizer = stringLocalizerFactory.Create(
            typeof(ConfirmationMailTitel).FullName,
            "ResourcesAssemblyName");
         }