开发者

How can i localize the url for a sitemap?

I have 2 links, one english one spa开发者_开发技巧nish. is there anyway i can localize that in .net? I was thinking of using sitemap


Sure, you can use resources for that, either global or local.

For local resource (pertinent to that .aspx page), switch to design mode, click Tools -> Generate Local Resource. This will create the "meta:resoucekey" bits for you for all of your server side controls and also will generate the resource file under a "App_LocalResources folder". Copy that resource file and rename it to the spanish that you want to use.

For example If your file name was mypage.aspx, the local resource generated would be mypage.aspx.resx and your new file will be mypage.aspx.es.resx (this will use traditional spanish). Markup below:

<asp:HyperLink runat="server" ID="myLink" Text="The Link" meta:resourcekey="myLink" />

In the local resource files, make sure the key matches the id: keys should be "myLink.NavigateURL" and the values should be your link

If you go the global resource route, then just add new resource file to the App_GlobalResources folder in the solution, name it whatever you want and make a copy of it for the other language. For example the new global resource is MyGlobalResources.resx. and the spanish resource MyGlobalResources.es.resx. Now put the following in your markup:

<asp:HyperLink runat="server" ID="myLink" NavigateURL="<%$ Resources:MyGlobalResources, myLink %>" Text="The Link" />

In the global resource files, the key is whatever your want. Just make sure it matches what you put in the markup: in this case the key should be "myLink" and the value should be your url.

Now, when you switch languages, the correct resource file should pick up and the correct URL should be shown.

P.S. You can localize lots of properties from the server side controls. I hard coded the "Text" property just for simplicity.

Here are a few links that go over localization:

http://msdn.microsoft.com/en-us/library/ms227427.aspx
http://www.west-wind.com/presentations/wwDbResourceProvider/introtolocalization.aspx
http://msdn.microsoft.com/en-us/magazine/cc163566.aspx

Hope I was clear enough :)

EDIT

I don't know how I completely missed the "sitemap" factor. The answer is yes and no. In a single site map you can only localize the Title,Description and custom attributes, not the URL. However, you can create a different sitemap for each locale and add them to the web.config file. Here is a link that explains how to do that (bottom of the page): Localize SiteMap

-D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜