C#C
C#3y ago
3 replies
pyrodistic

❔ Access Resources File

Hey, sorry to bother - quick question. I created a EmailResources.resx file inside a "Resources" folder, where I have the Name-Value pair of "ConfirmationEmailSubject" - "Verify Your Email Address".
On Program.cs I have:
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddSingleton<IStringLocalizerFactory, ResourceManagerStringLocalizerFactory>();

On the controller I have instantiated the _localizer (private readonly IStringLocalizer<AuthController> _localizer), I have tried to do:
_localizer["EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources:ConfirmationEmailSubject"].Value;
_localizer["ConfirmationEmailSubject"];
_localizer["ConfirmationEmailSubject"].Value;
_localizer.GetString("ConfirmationEmailSubject");
_localizer.GetString("ConfirmationEmailSubject").Value;
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"];
_localizer["EmailResources.EmailResources:ConfirmationEmailSubject"].Value;

All of these are returning "ConfirmationEmailSubject" instead of "Verify Your Email Address". What am I doing wrong?

There's a lot of things I've tried on Program.cs. Still cannot do it.
Was this page helpful?