msdn样式地址URL本地化可能的实现

发布于 2024-11-28 09:57:26 字数 669 浏览 0 评论 0原文

我试图想出如何基于地址字符串实现类似于 msdn 的本地化的想法

http://msdn.microsoft.com/en-us/library/system.string.aspx
http://msdn.microsoft.com/ru-ru/library/system.string.aspx

我试图找到有关 ASP.NET 本地化的各种信息,但未能找到可用于获得上述结果的策略描述。

我对 ASP.NET 的经验不是很丰富,并且想获得一些关于如何实现一些建议,从而在我的网站上产生类似的路径(例如,使用最少代码重复的最佳方式)。

我知道我可以将这两个文件复制到两个文件夹中。或者如果我有 10 种文化,则 10 个文件夹中的 10 个文件。但这听起来并不是最好的策略。是否有一些重写& or 后面进行参数传递?

更新:我最终通过以下方式实现它: 对于我的可本地化页面,我注册了所有当前文化的路线(以通用方法), 例如,对于 help.aspx 我在 help.aspx 内注册 ru-ru/help/en-us/help/ 路由(并且其他可本地化页面,oop 方式)我分析地址字符串并检索所需的语言。之后,我设置与 url 中提供的相关区域性相匹配的 html 内容。

I am trying to come up with idea how to implement msdn like localization based on address string

http://msdn.microsoft.com/en-us/library/system.string.aspx
http://msdn.microsoft.com/ru-ru/library/system.string.aspx

I tried to find various information about ASP.NET localization, but failed to find a description of strategy that can be used to get above result.

I am not very experienced with ASP.NET and would like to get some advice on how to implement something that will result in similar paths on my website(using best possible way with least code duplication for example).

I understand that I could duplicate both files in 2 folders. or 10 files in 10 folders if i got 10 cultures. But that sounds like not the best strategy. Is there some rewrite & parameter pass going on behind or ?

Update: I ended up implementing it the following way:
for my localizable pages I register routes to all current cultures ( in a generic method),
for example for help.aspx I register ru-ru/help/ and en-us/help/ routes, inside help.aspx (and other localizable pages, oop way) I analyze address string and retrieve desired language. After that I setup html contents matching the related culture provided in url.

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

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

发布评论

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

评论(2

夜司空 2024-12-05 09:57:26

微软似乎要么重写URL,要么利用ASP.NET 中的自定义路由。他们使用 URL 来确定选择哪种文化。他们可以使用查询字符串,但 URL 看起来不太好。

我建议您首先研究 ASP.NET MVC,因为它使用开箱即用的路由。然后修改路由以匹配上面 MS 使用的路由,然后再使用它们应用区域性。

您将在哪里托管应用程序可能会影响您是否可以执行类似的操作。如果您管理整个服务器并且不使用共享托管,那么实现这些事情会更容易,尤其是 URL 重写。如果您因为处于某些老化的企业环境中而必须使用 ASP.NET 2.0,那么您的日子可能会更加困难。

Microsoft appear to be either rewriting the URLs, or taking advantage of custom routing in ASP.NET. They are using using the URL to determine which culture to select. They could have used a query string but the URLs would not look as good.

I'd suggest that you start by looking into ASP.NET MVC as it uses routing out of the box. Then modify the routes to match those used by MS above, before using them to apply a culture.

Where you will be hosting your application could have an impact on whether you can do similar things. If you are managing the whole server and not using shared hosting it will be easier to implement these things, especially URL rewriting. If you have to use ASP.NET 2.0 because you are in some aging corporate environment you will probably have an even more difficult time.

清音悠歌 2024-12-05 09:57:26

Valentin,尝试使用 url 路由:

1 - 将路由信息添加到 global.asax

void Application_Start(object sender, EventArgs e)
{
  RouteTable.Routes.MapPageRoute("cultureCrossroad", "{culture}/Library/{article}", "~/library/ArticleHost.aspx");
}

2 - 在 ~/Library/ArticleHost.aspx 创建主机页面

public partial class ArticleHost : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    // ! Here we have access to url's parts and can redirect user for desired page via Server.Transfer method.

    var response = string.Format("culture: {0}<br/> article: {1}", Page.RouteData.Values["culture"], Page.RouteData.Values["article"]);
    Response.Write(response);
  }
}

Valentin, try to use url routing:

1 - Add routing info to global.asax

void Application_Start(object sender, EventArgs e)
{
  RouteTable.Routes.MapPageRoute("cultureCrossroad", "{culture}/Library/{article}", "~/library/ArticleHost.aspx");
}

2 - Create host page at ~/Library/ArticleHost.aspx

public partial class ArticleHost : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    // ! Here we have access to url's parts and can redirect user for desired page via Server.Transfer method.

    var response = string.Format("culture: {0}<br/> article: {1}", Page.RouteData.Values["culture"], Page.RouteData.Values["article"]);
    Response.Write(response);
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文