.NET 来自数据库的本地化站点地图?

发布于 2024-08-24 05:45:26 字数 181 浏览 3 评论 0原文

我有一个自定义站点地图提供程序,它从数据库加载页面。

页面(pageid、fk_pageid(父级)、标题、url、show_in_menu)

我想全球化/本地化页面的title。最好的方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你鎻心 2024-08-31 05:45:26

创建 SiteMapNode 对象时,请使用允许您指定隐式/显式资源键的构造函数。我建议使用显式资源键。

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

“要以编程方式指定本地化资源,请将implicitResourceKey的值设置为将用于标识节点的本地化资源的唯一名称,或者将explicitResourceKeys设置为名称/值对的NameValueCollection集合,其中名称是节点要本地化的属性或自定义属性,值包含节点属性或自定义属性的本地化值,然后可以在相应的 .resx 文件中设置本地化值。 SiteMapNode 对象,请参阅如何:本地化站点地图数据。有关explicitResourceKeys 集合的语法要求,请参阅NameValueCollection。

通常,要本地化静态站点地图,您可以使用如下所示的资源表达式:"$Resources:,,"

相反,请将 值按照出现的顺序添加到explicitResourceKey NameValueCollection在表达式中,全部使用相同的键添加。

因此,如果您的表达式为 "$Resources:SiteMapResourceFileOrClass,RootNode.Title,My Root Node",请执行以下操作:

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

您可以对描述执行相同的操作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文