This is a migrated thread and some comments may be shown as answers.

how to do localization culture on radmenu coming from sitemap

5 Answers 89 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Vaibhav
Top achievements
Rank 1
Vaibhav asked on 25 Feb 2014, 10:07 AM
Hi 

I have a RadMenu which is getting populated from a sitemap 
I want to convert the text of menu based upon culture set from the language dropdown .

Could any one help me on this , how to achieve this with small piece of code.

Thanks

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 Feb 2014, 11:49 AM
Hi Vaibhav,

Please try the following c# code snippet to change the Text of The RadMenuItem.

C#:
protected void RadDropDownList1_SelectedIndexChanged(object sender, DropDownListEventArgs e)
{
    if (e.Text == "Change") //your condition
    {
        //accessing the menu item
        RadMenuItem menu = RadMenu1.FindItemByText("Home");
        //changing the text
        menu.Text = "Change";
    }
}

Thanks,
Shinu.

0
Vaibhav
Top achievements
Rank 1
answered on 25 Feb 2014, 05:19 PM
Hi Shinu,

As i mentioned my RadMenu is coming from the sitemap.
So i dont have RadMenu1.FindItemByText("Home"); as its generated at runtime..and same goes with the submenu.

One more thing here , I dont have a dropdown for language change, its a rad menu item with item template in it. Item template contain the anchor <a> tag's , if you remember from my last post. so need a work around here also.

I want to make it completely independent of hard codding.
 For eg- If my site map gets another node or some sub node, then my menu automatically handles that , similarly i want to create some function for localization culture.

And one more problem with your solution is ->
Even if i get the elementbyText once i change the value of it from one language to another, then from changing it to the 3rd language , i wont find the menu item, as it will look for the text ie form the first language (Home), and all the menu items are in 2nd language say french.

1)Searching for Home to convert from English to french- Found
2)Converted to HomeFrnech
3)searcing for Home again to change the language from french to german -> cant find because it does not exist. as the menu is changed from Home to HomeFrench

Any other suggestion ....by any one.....

0
Boyan Dimitrov
Telerik team
answered on 28 Feb 2014, 10:09 AM
Hello,

An easy and convenient way to avoid hard-coding in this code implementation would be to use the RadMenu ItemDataBound event. This event is fired for each menu item and you are able to access the current site map node in the e.Item.DataItem and cast that object to site map node. As far as I understand you have a drop-down that shows the current language preference so based on that value you are absolutely able to control the menu item text. So you can define your french translation for each site map node as a custom attribute. In the attached example the site map node with title "Home" has a custom attribute "frenchValue". In the RadMenu1_ItemDataBound event handler is shown how to access that custom value and set the current menu item's text value to that value.

Alternative way would be on Page_Init to determine which language preference is selected and load different site map file. In the code snippet is shown how you can load a french site map file if the current language preference is french.
//code behind
protected void Page_Init(object sender, EventArgs e)
   {
       if (//current language preference is set to french)
       {
           SiteMap1.SiteMapFile = "you french language site map file";
           RadMenu1.DataSource = SiteMap1;
           RadMenu1.DataBind();
       }     
   }

In this case you will not need to use the RadMenu ItemDataBound handler.

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Terry
Top achievements
Rank 1
answered on 12 Mar 2015, 05:46 PM
Hi Boyan,

Can you go one step further on this and access a sitemap custom attribute from client-side? When I attempt to access a custom attribute from client-side, I get an "undefined" error. Here's what I am doing:

<siteMapNode title="Maps" url="" roles="*" mapnum="2" />
 
var item = eventArgs.get_item();
var mapnum = item.get_attributes().getAttribute("mapnum");
alert(mapnum);


Thanks for your help,

Terry



































0
Hristo Valyavicharski
Telerik team
answered on 17 Mar 2015, 04:51 PM
Hi Terry,

The item attribute is not set in ItemDataBound event. Please look at this help article:
http://www.telerik.com/help/aspnet-ajax/menu-items-custom-attributes.html

you need something like this:

protected void RadMenu1_ItemDataBound(object sender,Telerik.Web.UI.RadMenuEventArgs e)
    DataRowView dataRow = (DataRowView)e.Item.DataItem;  
    e.Item.Attributes["Roles"] = dataRow["Roles"].ToString();
    e.Item.ToolTip = e.Item.Attributes["Roles"];
}


Regards,
Hristo Valyavicharski
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Menu
Asked by
Vaibhav
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vaibhav
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Terry
Top achievements
Rank 1
Hristo Valyavicharski
Telerik team
Share this question
or