Currently I'm using resources files to localize MVC4 project in a standard key/value way. I'm now looking into best solution to separate some keys based on controller/action they belong to. There is always raw solution in creating keys such as Home.Index.Title but that's just workaround. Is there a way to work with resx files where they could be designed with parent/child nodes, where highest node would be Controller, then Action and finally Field, so that they can be queried by LINQ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Resx files always have a simple key/value structure. If the aim is to organise the resources and make them easy to locate for maintenance, I can suggest a couple of other approaches.
If the resources in question are for use in views, you can create one resource file per view in an App_LocalResources folder within the view folder and organise them that way, indirectly linked to a specific controller and action.
If the resources are for use in the controller itself, you can create a set of folders within (say) a ~/Resources folder that represents the controllers and within each, a resource file for each action. That way, the resource namespaces will indicate the controller/action where the resources are consumed.