Hi have a sitemap on my mvc 4 application like this:
<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">
<mvcSiteMapNode title="Users" controller="User" action="Index" area="" preservedRouteParameters="culture,projectid">
<mvcSiteMapNode title="New" controller="User" action="Create" area="" preservedRouteParameters="culture,projectid"/>
<mvcSiteMapNode title="Edit" controller="User" action="Edit" area="" preservedRouteParameters="culture,projectid,id"/>
<mvcSiteMapNode title="Profile" controller="User" action="Details" area="" preservedRouteParameters="culture,projectid,id"/>
</mvcSiteMapNode>
</mvcSiteMap>
I have few resources files in another project that i use for globalize my app, I need the resources files in a separate project because its used in few projects like ddl.
How can i implement globalization for my sitemap?
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.Or
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