I've found out today that for my site i could use a SiteMap provider which i've downloaded from Github for the MVC3, as my web application is MVC3.
Situation is following, my application is multilingual. I have a separate Library which contains all the resources. This Library is then added to my current project and everywhere where i need i use those resource files.
Now i've implemented the site map provider:
<mvcSiteMapNode title="$resources:Base,Home" controller="Home" action="Index" enableLocalization="true">
<mvcSiteMapNode title="Search" controller="Search" action="Index"/>
<mvcSiteMapNode title="Contact" controller="Contact" action="Index"/>
<mvcSiteMapNode title="About" controller="Home" action="About"/>
</mvcSiteMapNode>
But when i run it i get an error because it cannot find the resource with the key home. I think it is due to the fact that is outside of the application but in a separate Library.
How do i point to the resource file then, which is located din separate project?
I think it should be like this:
Assuming your:
ProjectName=MyProject
Folder which contains resources:LanguageFiles
Class in which resources are defined:Messaging
then.
It should be like this I believe..I am not sure but may be it works for you:
(assuming Home is the resource defined in the Messaging class)
The approach I would take would be to switch to external DI and then implement a custom IStringLocalizer class that can read the resources from another assembly. Here is a working example. I have created a demo application on GitHub as well.
Then you can inject it into your DI configuration module (StructureMap example shown, but any DI container will do).
First of all, you need to specify not to register the IStringLocalizer interface automatically by adding it to the excludeTypes variable.
Then provide an explicit registration of the ResourceManagerStringLocalizer (and its dependencies) instead.
Then it is just a matter of specifying the resources appropriately. You need to start them with the Base Name (in this case
SomeAssembly.Resources.Resource1
), and then specify the key of the resource as the second argument.Note that getting the BaseName right is the key to making it work. See the following MSDN documentation: http://msdn.microsoft.com/en-us/library/yfsz7ac5(v=vs.110).aspx