0

My problem is that I want to use .net core's localization and I need my resource files to have the "BuildAction" of content rather than the default "Embedded". The reason I want them like that is that I want to let my customer change these values through the cms that I am building for them. i.e I need the resource files to be editable at runtime.

So far I followed the guidelines in Microsoft's documentation and I can get the localization to work if they are "Embedded". Here are the things I did so far:

I created a SharedResources class in the root directory of my project with the root namespace and I have my resx resource file in a folder called Resources with different suffixes for different languages such as SharedResources.en.resx. Also, I have the following code in Startup:

services.AddLocalization(options => options.ResourcesPath = "Resources");

And I am injecting the localizer like this in my classes and views:

private readonly IStringLocalizer<SharedResources> _sharedLocalizer;

and then I use it like:

var localizedString = _sharedLocalizer["TheTextKey"]

As I said, these all work but as soon as I change the "BuildAction" of my resource files, nothing works. I did find this text in the last line of this page in Microsoft's documentation:

If you use resource files for localization, it's important that they have an appropriate build action. They should be Embedded Resource, otherwise the ResourceStringLocalizer is not able to find these resources.

So is there a way at all to have user-editable localization through the .net core's pipeline so that I don't have to reinvent the wheel and come up with a whole new framework for editable localization?

roostaamir
  • 1,888
  • 5
  • 25
  • 50
  • You can try [this](https://stackoverflow.com/questions/676312/modifying-resx-file-in-c-sharp) to modify .resc file in runtime – Jerry Cai Jun 10 '21 at 09:08

0 Answers0