如何本地化 ASP.NET MVC 应用程序?

发布于 2024-07-06 08:20:11 字数 264 浏览 8 评论 0原文

本地化 ASP.NET MVC 应用程序的最佳实践是什么?

我想介绍两种情况:

  • 一种应用程序部署在 IIS 中,它可以处理多种语言
  • 一种语言/应用程序部署。

在第一种情况下,您应该使用某种基于视图的东西,例如 ~/View/EN、~/View/FI、~/View/SWE 还是其他东西?

第二种情况怎么样,只是通过 Web.config 基于应用程序的配置并将这些不同的语言指向不同的 URL?

What would be best practice to localize your ASP.NET MVC application?

I would like to cover two situations:

  • one application deployment in IIS which would handle multiple languages
  • one language/application deployment.

In first situation should you go with some kind of view based thing like, ~/View/EN, ~/View/FI, ~/View/SWE or something different?

What about second case, just application based config via Web.config and point these different languages to different URLs?

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

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

发布评论

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

评论(9

心意如水 2024-07-13 08:20:11

您还可以在这里查看 ASP.NET MVC 2 本地化完整指南ASP .NET MVC 2 模型验证与本地化如果您使用 ASP.NET MVC 2,这些全部内容将为您提供帮助。

You can also take a look here ASP.NET MVC 2 Localization complete guide and ASP.NET MVC 2 Model Validation With Localization these entires will help you if you working with ASP.NET MVC 2.

音栖息无 2024-07-13 08:20:11

您可以像本地化经典 ASP.NET Web 窗体应用程序一样本地化 ASP.NET MVC 应用程序。

您不会为每种语言使用不同的页面/视图,但每个页面都可以使用附属程序集支持多种语言。

您可以查看 Matt Hawley 的博客文章更多解释和例子。

You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.

You wouldn't use different pages/views for each language, but each page would support multiple languages using satellite assemblies.

You can look at Matt Hawley's blog entry for more explanation and examples.

葬シ愛 2024-07-13 08:20:11

不幸的是,Matt Hawley 的原始代码无法在 ASP.NET MVC 的发行版中运行。 查看更新的帖子:http:// /blog.eworldui.net/post/2008/10/ASPNET-MVC-Localization-via-View-Engines.aspx

一般来说,VS 2008 / ASP.NET MVC 中的本地化过程并不顺利世界就像传统的网络形式一样。 http://www.guysmithferrier.com/post/2009/05 /本地化-ASPNET-MVC.aspx

Unfortunately, Matt Hawley's original code doesn't work in the release version of ASP.NET MVC. Check out an updated post: http://blog.eworldui.net/post/2008/10/ASPNET-MVC-Localization-via-View-Engines.aspx

In general, the localization process isn't as smooth in the VS 2008 / ASP.NET MVC world as it is with traditional web forms. http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx

为你拒绝所有暧昧 2024-07-13 08:20:11

看一下 Rob Connery 的 MvcStore 项目。 他制作了一个截屏视频,展示了解决全球化问题的一种方法。

http://wekeroad.com/2008/04/24/mvcstore-part- 5

Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.

http://wekeroad.com/2008/04/24/mvcstore-part-5

懵少女 2024-07-13 08:20:11

我从来不相信像 Elijah 所建议的那样在表单中处理本地化 - 不同的长度和方向可能会导致非常复杂或变化多端的看起来很糟糕的表单。

我才刚刚开始使用 MVC,但采用解耦方法,无论语言如何,您都希望使用相同的控制器(将语言视为视图) - 这将为您提供 /Controller/Action/language/form

I've never been convinced of handling localization within a form as Elijah suggests - the different lengths and directions can lead to very complex or vary naff looking forms.

I'm only just starting with MVC but taking the decoupling method you would wan to use the same controller regardless of the language (treating language just as a view) - this would then give you /Controller/Action/language/form

最美的太阳 2024-07-13 08:20:11

有一个很好的教程,最近更新了如何本地化 ASP.NET MVC 应用程序,涵盖了所有方面,包括 DisplayName 本地化、验证、使用路由(在 URL 中存储区域性名称)、输出缓存问题等等... Alex Adamyan 博客 - 当我的键盘轻轻哭泣时

There is good tutorial with recent update on How to localize asp.net mvc application covering all aspects including DisplayName localization, Validation, using Routing (storing culture name in URL), issues with output cache and so on... Alex Adamyan Blog - While my keyboard gently weeps

野心澎湃 2024-07-13 08:20:11

我们实际上采取了完全不同的方式来覆盖
DataAnnotationsMetadaDataProvider
在那里,您可以确保 DisplayNameAttribute 值已解析为正确的语言。
实际上,您甚至可以删除该属性并仅在有帮助的情况下通过字段名称进行解析。

We actually went a complete different with overriding the
DataAnnotationsMetadaDataProvider.
In there you can make sure that the DisplayNameAttribute values are resolved into the correct language.
Actually you could even get rid of that attribute and resolve by field names only if that would be any help.

永言不败 2024-07-13 08:20:11

我不久前写了这篇文章。 它使用自定义视图引擎。
http://blog.oimae.com/2011/ 02/20/cultured-view-engine-for-mvc/

I wrote this article a while ago. It uses a custom view engine.
http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/

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