What would be best practice to localize your ASP.NET MVC application?
本地化您的ASP的最佳实践是什么?净MVC应用程序?
I would like to cover two situations:
我想介绍两种情况:
- one application deployment in IIS which would handle multiple languages
- IIS中的一个应用程序部署,可以处理多种语言
- 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?
在第一种情况下,你应该使用一些基于视图的东西,比如~/ view /EN、~/ view /FI、~/ view /SWE还是其他什么?
What about second case, just application based config via Web.config and point these different languages to different URLs?
第二种情况呢,通过Web基于应用程序的配置。配置并将这些不同的语言指向不同的url ?
9 个解决方案
#1
71
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 MVC 2本地化完成指南和ASP。NET MVC 2模型的本地化验证如果您使用ASP,这些实体将会帮助您。净MVC 2。
#2
22
You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.
您将本地化您的ASP。NET MVC应用程序与经典的ASP非常相似。净Web表单应用程序。
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的博客中找到更多的解释和例子。
#3
9
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
不幸的是,Matt Hawley的原始代码在ASP版本中不能工作。净MVC。查看更新的帖子:http://blog.eworldui.net/post/2008/10/aspnet - mvc - localiz-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
一般来说,本地化过程在VS 2008 / ASP中没有那么顺利。NET MVC世界就像传统的web表单一样。http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
#4
3
Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.
看看Rob Connery的MvcStore项目。他做了一个屏幕展示了解决全球化问题的一种方法。
http://wekeroad.com/2008/04/24/mvcstore-part-5
http://wekeroad.com/2008/04/24/mvcstore-part-5
#5
2
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.
我从来没有像以利亚说的那样相信在一个形式中处理本地化——不同的长度和方向会导致非常复杂的或不同的naff形式。
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
我只是从MVC开始,但是使用去耦方法,您希望使用相同的控制器,而不考虑语言(将语言当作视图)——这将给您/ controller /Action/语言/表单
#6
2
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
关于如何本地化asp.net mvc应用程序,包括DisplayName本地化、验证、使用路由(在URL中存储文化名称)、输出缓存等问题,有很好的教程。Alex Adamyan博客-当我的键盘轻轻哭泣
#7
1
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.
实际上,我们完全不同于覆盖DataAnnotationsMetadaDataProvider。在这里,您可以确保DisplayNameAttribute值解析为正确的语言。实际上,您甚至可以删除该属性并通过字段名解析,只要这对您有帮助。
#8
0
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/
我不久前写了这篇文章。它使用自定义视图引擎。http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/
#9
-1
And another tutorial for different solution
还有另一个不同解决方案的教程
Tutorial: Create ASP.NET MVC localization with language detection
教程:创建ASP。NET MVC本地化与语言检测
#1
71
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 MVC 2本地化完成指南和ASP。NET MVC 2模型的本地化验证如果您使用ASP,这些实体将会帮助您。净MVC 2。
#2
22
You would localize your ASP.NET MVC application very much in the same way you would a classic ASP.NET Web Form application.
您将本地化您的ASP。NET MVC应用程序与经典的ASP非常相似。净Web表单应用程序。
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的博客中找到更多的解释和例子。
#3
9
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
不幸的是,Matt Hawley的原始代码在ASP版本中不能工作。净MVC。查看更新的帖子:http://blog.eworldui.net/post/2008/10/aspnet - mvc - localiz-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
一般来说,本地化过程在VS 2008 / ASP中没有那么顺利。NET MVC世界就像传统的web表单一样。http://www.guysmithferrier.com/post/2009/05/Localizing-ASPNET-MVC.aspx
#4
3
Have a look at Rob Connery's MvcStore project. He does a screencast showing one way to solve the globalization problem.
看看Rob Connery的MvcStore项目。他做了一个屏幕展示了解决全球化问题的一种方法。
http://wekeroad.com/2008/04/24/mvcstore-part-5
http://wekeroad.com/2008/04/24/mvcstore-part-5
#5
2
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.
我从来没有像以利亚说的那样相信在一个形式中处理本地化——不同的长度和方向会导致非常复杂的或不同的naff形式。
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
我只是从MVC开始,但是使用去耦方法,您希望使用相同的控制器,而不考虑语言(将语言当作视图)——这将给您/ controller /Action/语言/表单
#6
2
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
关于如何本地化asp.net mvc应用程序,包括DisplayName本地化、验证、使用路由(在URL中存储文化名称)、输出缓存等问题,有很好的教程。Alex Adamyan博客-当我的键盘轻轻哭泣
#7
1
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.
实际上,我们完全不同于覆盖DataAnnotationsMetadaDataProvider。在这里,您可以确保DisplayNameAttribute值解析为正确的语言。实际上,您甚至可以删除该属性并通过字段名解析,只要这对您有帮助。
#8
0
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/
我不久前写了这篇文章。它使用自定义视图引擎。http://blog.oimae.com/2011/02/20/cultured-view-engine-for-mvc/
#9
-1
And another tutorial for different solution
还有另一个不同解决方案的教程
Tutorial: Create ASP.NET MVC localization with language detection
教程:创建ASP。NET MVC本地化与语言检测