Question

I have a custom sitemapprovider which loads pages from the database.

Pages (pageid, fk_pageid (parent), title, url, show_in_menu)

I would like to globalize/localize the title of the page. What's the best method?

Was it helpful?

Solution

When you create your SiteMapNode objects, use the constructor that allows you to specify implicit/explicit resource keys. I'd recommend going with explicit resource keys.

http://msdn.microsoft.com/en-us/library/ms150104.aspx

"To programmatically specify resources for localization, either set the value of implicitResourceKey to a unique name that will be used to identify localized resources for the node or set explicitResourceKeys to a NameValueCollection collection of name/value pairs where name is the node property or custom attribute to localize and value contains localization values for the node property or custom attribute. The localized values can then be set in the appropriate .resx files. For more information about how to localize the Title, Description, and any custom properties of a SiteMapNode object, see How to: Localize Site-Map Data. For the syntax requirements of the explicitResourceKeys collection, see NameValueCollection."

Normally to localize a static site map, you would use a resource expression like the following: "$Resources:<ClassName>,<KeyName>,<DefaultValue>".

Instead, add the <ClassName>, <KeyName>, and <DefaultValue> values to the explicitResourceKey NameValueCollection in the order they appear in the expression, all added using the same key.

So if your expression would have been "$Resources:SiteMapResourceFileOrClass,RootNode.Title,My Root Node", instead do the following:

explicitResourceKeys.Add("Title", "SiteMapResourceFileOrClass")
explicitResourceKeys.Add("Title", "RootNode.Title")
explicitResourceKeys.Add("Title", "My Root Node")

You can do the same for Description.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top