Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to Localize DNN TabsHow to Localize DNN Tabs
Previous
 
Next
New Post
12/15/2009 12:38 PM
 

 

This post is based on DNN version 5.1.1 which as to date does not come with any localization feature on menus./tabs
 
  • Make a duplicate copy of DNN standard navigation control Nav.ascx from \Website\admin\Skins.
  • Create a new folder under \Website\DesktopModules folder, name it anything suitable e.g LocalizedNav.
  • Copy the duplicate copy of Nav.ascx into the newly created folder and rename it to LocNav.ascx.
  • Locate the skin file (of the portal) that needs to be implemented with localized navigation control.
  • Replace the DNN standard navigation control @ Register directive on the skin with directive of the LocNav.ascx control.

          From <%@ Register TagPrefix="dnn" TagName="NAV" Src="~/Admin/Skins/Nav.ascx" %>

       To <%@ Register TagPrefix="dnn" TagName="NAV" Src="~/DesktopModules/LocalizedNav/LocNav.ascx" %>

  • Run the portal with the skin to make sure the LocNav.ascx is working properly.
  • Then open the file LocNav.ascx.vb and start modifying it (for this post I am using LocNav.ascx.cs since I've converted it to C#).
  • Create a private property to get the localized menu from cache, if it is not available it will get from database and stored it into cache again. Refer to http://www.west-wind.com/presentations/wwDbResourceProvider/ article to implement customized method/class to retreive all localized values from database.

Dictionary<string, Dictionary<string, string>> LocalResource

{

    get

    {

        string strCacheKey = "menus";

        Dictionary<string, Dictionary<string, string>> resources = DataCache.GetCache<Dictionary<string, Dictionary<string, string>>>(strCacheKey);

 

        if (resources == null) //If resources not available in cache, retrieve from database

        {

            resources = DbResource.GetStrings("menus"); //This customized method/class to get all localized values from database

            int cacheTimeout = 20 * Convert.ToInt32(DotNetNuke.Entities.Host.Host.PerformanceSetting);

            DataCache.SetCache(strCacheKey, resources, TimeSpan.FromMinutes(cacheTimeout));

        }

 

        return resources;

    }

}

  • Next create a private method to retrieve specific localized value of menu from LocalResource property.

private string GetLocalResource(string resourceId)

{

    Dictionary<string, string> resources;

    LocalResource.TryGetValue(System.Threading.Thread.CurrentThread.CurrentCulture.Name, out resources);

 

    string resourceValue = string.Empty;

 

    if (resources != null)

    {

        resources.TryGetValue(resourceId, out resourceValue);

    }

 

    if (string.IsNullOrEmpty(resourceValue))

    {

        return string.Empty;

    }

    else

    {

        return resourceValue;

    }

}

  • Then create a recursive method to perform localization on portal menus. We need a recursive method because of the complex hierarchy of the menus. We cannot fixed or can never tell how many levels each node of menu has. The recursive method will drill down into each level and perform the translation as long as the node have subnode (another sub level of menus).

private void LocalizedNode(DNNNodeCollection nodes)

{

    foreach (DNNNode node in nodes)

    {

        string tabResourceId = "tab_" + node.Text.ToLower().Replace(" ", string.Empty);

        if (!string.IsNullOrEmpty(GetLocalResource(tabResourceId)))

        {

            node.Text = GetLocalResource(tabResourceId);

        }

 

        if (node.HasNodes)

        {

            LocalizedNode(node.DNNNodes);

        }

    }

}

  • Next, locale the private void BuildNodes(DNNNode objNode) method. Inside this method we will call the recursive method to perform localization on portal menus.

private void BuildNodes(DNNNode objNode)

{

    DNNNodeCollection objNodes = default(DNNNodeCollection);

    objNodes = GetNavigationNodes(objNode); //this is where DNN will get and generate all menus as DNNNodeCollection

 

    //Perform tabs/menus localization

    LocalizedNode(objNodes); //this is where we will call the recursive method

 

    this.Control.ClearNodes();

    //since we always bind we need to clear the nodes for providers that maintain their state

    this.Bind(objNodes); //this is where DNN will bind those menus to navigation control

}

 

 
New Post
2/5/2010 2:56 PM
 

Thanks for sharing - I hope one day the core will support localization...


Entrepreneur

PokerDIY Tournament Manager - PokerDIY Tournament Manager<
PokerDIY Game Finder - Mobile Apps powered by DNN
PokerDIY - Connecting Poker Players

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0How to Localize DNN TabsHow to Localize DNN Tabs


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out