如何本地化MvcSiteMapProvider [英] How to localize the MvcSiteMapProvider

查看:59
本文介绍了如何本地化MvcSiteMapProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎以任何方式都试图对MvcSiteMapProvider进行本地化,但是我不明白.如我所知,当您使用app_globalresources文件夹时,它可以工作,但是如果您使用MVC,则不是一个选择,因为MVC不支持它们(至少发布功能不发布文件).

I tried to localize the MvcSiteMapProvider in almost any way, but I don't get it. As I figured out it works when you use app_globalresources folder, but that is not an option, if you work with MVC because MVC does not support them (at least the publish feature does not publish the files).

当前,我网站的资源文件位于一个名为words.resx(和words.de-DE.resx)的文件中,该文件位于一个名为Resources的新文件夹下.我已将构建操作设置为嵌入式资源",始终复制",并将工具更改为PublicResXFileCodeGenerator.

Currently my resource file for the web site is in a file called words.resx (and words.de-DE.resx) which is located under a new folder called Resources. I've set the build action to "Embedded Resource", "Copy always" and changed the tool to PublicResXFileCodeGenerator.

对于SiteMap,我不在乎它是隐式还是显式本地化....我尝试了这两种方法,并对resx文件使用了不同的命名方式,并对自定义工具使用了不同的设置,但没有一个起作用.

For the SiteMap, i don't care if it is implicit or explicit localization.... I tried both and used different namings of the resx files and different settings for the custom tool, but none of them worked.

有人有这个工作吗?

亲切的问候 安迪

推荐答案

注意::将资源放入App_GlobalResources文件夹的另一种方法(实施IStringLocalizer .

NOTE: An alternative approach to putting your resources in the App_GlobalResources folder (which isn't supported very well by MVC) would be to implement IStringLocalizer.

本地化在很大程度上与Microsoft的SiteMapProvider保持不变,该网站最初是MvcSiteMapProvider所基于的.对于本地化,您仍然可以按照如何进行操作:大部分情况下,本地化Site-Map数据文档.

Localization has remained largely unchanged from Microsoft's SiteMapProvider, which MvcSiteMapProvider was originally based on. For localization, you can still follow the How to: Localize Site-Map Data document for the most part.

启用本地化是在appSettings的MvcSiteMapProvider_EnableLocalization设置中完成的;或者,如果使用外部DI,则可以通过将设置传递给SiteMapBuilderSet的enableLocalization构造函数参数在DI配置中进行设置.默认情况下启用.

Enabling localization is done in the MvcSiteMapProvider_EnableLocalization setting in appSettings, or if using external DI, you would set it in your DI configuration by passing the setting to the enableLocalization constructor parameter of SiteMapBuilderSet. It is enabled by default.

我建议使用显式本地化,因为隐式本地化需要一些帮助并且可能会在将来的版本中更改.

I recommend using explicit localization, as implicit localization requires some hoops to get working and is likely to change in a future version.

可本地化的字段为:

  • 标题
  • 说明
  • ImageUrl
  • 属性(字符串数据类型)

这是 MvcMusicStore演示,在某些节​​点上使用了本地化.

Here is an explicit localization example from the MvcMusicStore demo, which has localization used on certain nodes.

<mvcSiteMapNode title="$resources:SiteMapLocalizations,BrowseGenresTitle" controller="Store" action="Index"/>

它指的是App_GlobalResources文件夹中名为SiteMapLocalizations.resx的文件(以及名为BrowseGenresTitle的项).

It is referring to a file named SiteMapLocalizations.resx (and an item named BrowseGenresTitle) in the App_GlobalResources folder.

或者,您可以在同一应用程序中使用多个站点地图(针对每个语言环境),这样可以使每个语言环境具有不同的网站结构(和不同的URL).

Alternatively, you can use multiple sitemaps in the same application for each locale which enables a way to have a different site structure (and different URLs) per locale.

这篇关于如何本地化MvcSiteMapProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆