How to better organize resx files in ASP.net MVC6 application

I managed to successfully launch the application for an example of localization of asp.net mvc6, however all .resx files are placed in the same "resources" folder.

If you look at this sample application , you will notice that all resources are placed in the root directory: β€œResources” and it is referenced in the Startup.cs file as follows:

services .AddMvc() .AddViewLocalization(options => options.ResourcesPath = "Resources") .AddDataAnnotationsLocalization(); 

The current application I'm working on has several areas, and ideally I would like to better organize these .resx files. Otherwise it will be very dirty.

Is this still possible in MVC6?

+6
source share
2 answers

One of the possible things you can do is create separate folders for each area in the resource route folder. In these "area folders" you can create several specific resource files.

Seems quite manageable for me.

For instance,

Resources

  • CatalogArea
    • ProductTranslations.resx
    • CategoryTranslations.resx
  • SupportArea
    • KnowledgeBaseTranslations.resx
+1
source

You can store resources (and not just resource files - for example, I store my translations in a json file), wherever you want. You just need to override:

  • IStringLocalizer
  • IStringLocalizerFactory
+1
source

All Articles