如何本地化 ASP.NET MVC 应用程序?
本地化 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
您还可以在这里查看 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.
您可以像本地化经典 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.
不幸的是,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
看一下 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
我从来不相信像 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
有一个很好的教程,最近更新了如何本地化 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
我们实际上采取了完全不同的方式来覆盖
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.
我不久前写了这篇文章。 它使用自定义视图引擎。
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/
以及不同解决方案的另一个教程
教程:创建 ASP.NET带语言检测的 MVC 本地化
And another tutorial for different solution
Tutorial: Create ASP.NET MVC localization with language detection