Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have been able to successfully run an asp.net mvc6 localization sample app however all the .resx files are placed in one "resources" folder.

If you have a look at this sample application You will notice that all the resources are placed in the root directory folder: "Resources" and it is referenced in the Startup.cs file like this:

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

The current application I am working on has multiple areas and ideally I would like to better organize these .resx files. Otherwise it's going to get very messy.

Is this even possible yet in MVC6?

like image 550
Cool Breeze Avatar asked Jan 26 '16 01:01

Cool Breeze


2 Answers

One possible thing you can do is to create seperate folders per area in your resource route folder. In those "area folders" you can create several specific resource files.

Seems quite manageable to me.

For ex.

Resources

  • CatalogArea
    • ProductTranslations.resx
    • CategoryTranslations.resx
  • SupportArea
    • KnowledgeBaseTranslations.resx
like image 169
Tom B. Avatar answered Oct 19 '22 23:10

Tom B.


You can store resource (and not just resource files - for example I store my translations in json file) where ever you want. You just have to override:

  • IStringLocalizer
  • IStringLocalizerFactory
like image 34
Dawid Rutkowski Avatar answered Oct 19 '22 23:10

Dawid Rutkowski