Localization in SitemapNodeInfo

Topics: Web Client Software Factory, Project Management Forum, UIP Application Block discussion, User Forum
Mar 28, 2009 at 5:52 AM
Hi
I am working webapplication project .Problem is Localization in SiteMapNodeInfo
I try 

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Home", "~/", "$resources:MyAppGlobalResourceFile,MyKey,MyDefaultValue");

 

SiteMapNodeInfo moduleNode = new SiteMapNodeInfo("Administration", "~/Administration/Default.aspx", "$resources:Common,Administration,Administration");

 

siteMapBuilderService.AddNode(moduleNode);

but not working  please send any solution.

Apr 1, 2009 at 5:20 PM

Hi,

You can try using implicit expressions to localize the title of the node like it is explained in this old thread:

·         Localization of SiteMapNodes broken?

 

As it is said in that thread, you should perform the following steps:

1.       Create a Resource file inside the App_GlobalResources in your WebSite (in this example: ResourceFile.resx).

2.       Add a Resource key inside the resource file for the Node’s title:

    Key: “MyNode.Title”

    Value: “Your Node’s Title”

3.       Add a class inside the App_Code folder of your WebSite that inherits from ModuleSiteMapProvider and override the initialize method with the following code:

    public class MySiteMapProvider : Microsoft.Practices.CompositeWeb.Providers.ModuleSiteMapProvider

    {

        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)

        {

            base.Initialize(name, config);

      this.EnableLocalization = true;

      this.ResourceKey = "ResourceFile"; // name of the Global Resource File

        }

    }

4.       Modify your Web.Config file inside your WebSite to use your new SiteMap Provider:

    <siteMap defaultProvider="MySiteMapProvider" enabled="true">

        <providers>

            <add name="DefaultSiteMapProvider" type="Microsoft.Practices.CompositeWeb.Providers.ModuleSiteMapProvider, Microsoft.Practices.CompositeWeb" securityTrimmingEnabled="true"/>

            <add name="MySiteMapProvider" type="MyModuleSiteMapProvider, APP_CODE" securityTrimmingEnabled="true"/>

        </providers>

    </siteMap>

5.       Update your RegisterSiteMapInformation methods inside your Module’s controllers to use implicit expressions:

    protected virtual void RegisterSiteMapInformation(ISiteMapBuilderService siteMapBuilderService)

    {

        // add menu items

  SiteMapNodeInfo node = new SiteMapNodeInfo("NodeKey", "~/Default.aspx", "Default Node Title");

 

    // set the resource key

    node.ImplicitResourceKey = "MyNode";

 

    siteMapBuilderService.AddNode(node);

    }

 

Performing this steps you should retrieve the Node’s Title without problem. Also, you may want to check the following article that talks about SiteMaps localization:

·         How to: Localize Site-Map Data

 

Please, let me know if this helps.

 

Ezequiel Sculli

http://blogs.southworks.net/esculli/

Apr 2, 2009 at 3:46 AM
hi
I am not understanding this code. plz explain english.
Nov 13, 2009 at 2:56 PM

I completely understand the explanation - that's not the problem! Its a solultion that works, but has one big failing in my mind: this breaks the modularity of the whole application.

From what I'm reading, we will have to define strings in a resource file in the Shell projectthat will cover all the needs of all the modules that will ever be a part of this shell... but the Shell project should not know the intricate details of its modules, its the module's responsibility to know about itself including its resources.

This goes right against the whole point of the WCSF, has anyone found a modular solution to this?

Dec 2, 2009 at 6:10 AM

Hi,

 

Is there someone else that can´t seem to get this working? I have followed escullis example and it doesn´t work. Tried it in another project to with the same results. No localization for the sitemap nodes.

Please help.

 

//Sebastian