How to localize menu items in an XML data source? RRS feed

  • Question

  • User1686721631 posted

    I need to localize menu items which come from an XML data source.  I tried the same method used to localize SiteMap file, but it did not work.

    Any suggestions?

    Tuesday, January 2, 2007 10:23 PM

All replies

  • User-1727354793 posted


    There are atleast two possible ways with SiteMaps. I will descripe the way I think is the most easy. To make it simple, I assume that you have a Web.sitemap file the root of your solution. I also assume that you use a menu control and that you have succesfully bound it to a SiteMapDataSource. If not, then let me know.

     I have created a small website that has the following Web.sitemap file included (The links are to Danish websites, but I hope it is ok):


    <?xml version="1.0" encoding="utf-8" ?>

    <siteMap enableLocalization="true" xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >

    <siteMapNode resourceKey="main" url="Http://www.test.dk" description="">

    <siteMapNode resourceKey="me" url="http://www.sorenagerbo.dk" description="" />

    <siteMapNode resourceKey="chess" url="http://www.dsu.dk" description="" />




    STEP 1:

    the difference from my file to yours would probably be that I have included enableLocalization="true" in the siteMap node and resourceKey="chess" in all the siteMapNodes.



    STEP 2:

    In your websolution you should include a folder called App_GlobalResources (if you not already have it). Right click your solution and in "Add ASP.NET folder" choos App_GlobalResources



    STEP 3:

    ín the App_GlobalResources add a Resouces File. Right click the foldername and Add New Item.

    Name the Resoucefile Web.sitemap.resx (always the same name as the sitemapfile + resx). This will now be your default ressourcefile for your Web.sitemap, and if the user is from china and you have not made a special resourcefile for China, then what you do in this file will be shown.



    STEP 4:

    Open the file and in Name column write main.title in the first line, next line chess.title and in the last line me.title.

    In each line write the value for the title.




    STEP 5:

    For each Language you want to translate to:

    Copy the Resourcefile in the same folder and rename it Web.sitemap.XX.resx, where XX=language. English would be Web.sitemap.en.resx.





    1) You can localize title and description, this means that in the ressourcefile you should do step 4 with main.Description, chess Description and so on.

    2) This is what MS write about the error in step 4:

    "Key names in global resource files should not include periods (.). However, periods are necessary in global resources that are referenced in site-map files when using implicit expressions. This is because of the resourceKey syntax. In some editing environments, such as Visual Web Developer, you might get a design-time error if you use a period in the key name. However, this shouldn't affect the ability to edit or save the file and can be ignored."

    3) If you have the same helpfile as I have, then you can use the link:


    Hope you can use my answer. Otherwise please contact me again.


    Thursday, January 4, 2007 11:25 AM
  • User1686721631 posted

    Thanks for the reply. It took me a while to reply cause I almost gave up on anybody responding to my post after waiting unanswered for a long time...

    I already have a localized SiteMap which I use as the source of a breadcrumb (SiteMapPath) control, and it works well. 

    My problem is different. I have a loginview control which I use to show  a different menu depending on user's role.

    My site will call a few aspx pages, each will show different content based on the menu item calling it.  Since the content these pages may change (new things to show) the menus must be dynamic.

    I now have a solution.  Maybe someone can give me a more elegant one.

    My solution uses XmlDataSource and databindings/menuitembinding to connect menus showing in the LoginView to xml files containing the menu items. 

    I created FirstRoleMenu.xml and FirstRoleMenu.es.xml , SecondRoleMenu.xml and SecondRoleMenu.es.xml .. and so on for First Role, Second Role in (en)glish and (es)paniol.

    In the Page_Load event, I detect the user role and selected language so I find the XmlDataSource control and set its DataFile property to the right XML file for the user role and the selected language.

    I can add new content and menu items and roles dynamically (by editing or adding the correct XML menu files for the role or language).



    Monday, January 15, 2007 9:51 PM