Search code examples
asp.net-mvc-3resourcesembedded-resourceresx

Organizing .resx files in mvc 3 application


I have a question about organizing .resx files in mvc3 application. So far I have managed to do the following:

  • Creating new class library in a solution for resources and adding resources for two languages. Everything works fine when I have for example:

Resources.resx //default language Resources.en.resx //english language

But I want to have such organization in my class library:

DefaultLanguage foder - Resources.resx

en folder - Resources.en.resx

I want to organize resources by folders. I think it is more appropriate for people who will translate the site and it is also more maintainable. When I organize resources in such a way the web page returns an error...cannot find error. Am I missing something? I know that you should not have folder name in namespace because that would mean that referencing resource in View is dependent on folder name and this is not correct.

The point is I would like to have the same behaviour of resources wheter they are organized in folders or not...

By the way: I check on the web and could not find any appropriate solution.

Thank you for your answers!


Solution

  • MVC3 uses ASP.NET resource management. See ASP.NET documentation for details. If you want to rely on ASP.NET behaviour and generated strongly typed classes, then you must keep resource file from default language and other language specific resource files together.

    To have the same tree structure that you suggested, then you have to implement your own resource management. You probably don't want to do that, because (at least some) resource editing tools rely on that behaviour.

    On our projects we have one resource (and his translations) for each view. They are in folder Localization within MVC3 project. Inside we keep the same tree structure as is within Views folder. This is more or less the same as ASP.NET local resources are organized. Common strings are kept in one .resx file on root of Localization folder. This ensures maintainability.

    To keep your people that will do translation happy you have to pick good .resx editing tool.