I'd like to fully localize my ASP.NET MVC application, and while there are many articles that deal with the various pitfalls of ASP.NET MVC localization, none of them deals with an aspect that I want to deal with, and that is the localization of URLs, including the controller names and actions.
我想完全本地化我的ASP.NET MVC应用程序,虽然有很多文章处理ASP.NET MVC本地化的各种缺陷,但它们都没有处理我想要处理的方面,那就是URL的本地化,包括控制器名称和操作。
I would like a way to specify the strings that should appear instead of the controller name and action name in the URL, for example in a resource file.
我想要一种方法来指定应该出现的字符串,而不是URL中的控制器名称和操作名称,例如在资源文件中。
How is this doable in a sane way? Thanks in advance for your help!
这样做是如何以理智的方式进行的?在此先感谢您的帮助!
EDIT:
I'm still looking for a way to do this. Any help would be welcome.
Is there any framework or lib implementing this already?
编辑:我仍在寻找一种方法来做到这一点。欢迎任何帮助。是否有任何框架或库实现这一点?
4 个解决方案
#1
7
I've never done this before, but couldn't you add an entry to the routes table for every language you want to support? All of the localized routes could redirect to the route in the language of your choice. Check out these related questions:
我以前从未这样做过,但是你不能为你想要支持的每种语言在路由表中添加一个条目吗?所有本地化路线都可以使用您选择的语言重定向到路线。看看这些相关问题:
Multi-lingual websites with ASP.NET MVC
使用ASP.NET MVC的多语言网站
How should I implement localization with ASP.NET MVC routes?
我应该如何使用ASP.NET MVC路由实现本地化?
#2
4
Short answer: don't.
简答:不要。
URLs are supposed to be universal and thus locale-invariant. This is why we don't support localizing controllers, actions, or query string values during model binding.
URL应该是通用的,因此是区域不变的。这就是我们在模型绑定期间不支持本地化控制器,操作或查询字符串值的原因。
#3
3
Take a look at this simple solution:
看看这个简单的解决方案:
Translating routes (ASP.NET MVC and Webforms)
转换路由(ASP.NET MVC和Webforms)
You can also try the awesome AttributeRouting project that I just found! You can get it through NuGet.
您还可以尝试我刚刚找到的令人敬畏的AttributeRouting项目!你可以通过NuGet获得它。
#4
0
Take into account that you are not finished when you localized action and controller names. You would still need to localize any routing parameters. That's especially painfull for enums.
考虑到在本地化操作和控制器名称时未完成。您仍然需要本地化任何路由参数。这对于枚举来说尤其痛苦。
Ie www.seller.com/catalogue/list/winterclothing www.seller.com/catalogue/list/summerclothing where winterclothing
and summerclothing
would be enums.
即www.seller.com/catalogue/list/winterclothing www.seller.com/catalogue/list/summerclothing其中winterclothing和summerclothing将是枚举。
I would say: It's possible but not doable.
我会说:这可能但不可行。
#1
7
I've never done this before, but couldn't you add an entry to the routes table for every language you want to support? All of the localized routes could redirect to the route in the language of your choice. Check out these related questions:
我以前从未这样做过,但是你不能为你想要支持的每种语言在路由表中添加一个条目吗?所有本地化路线都可以使用您选择的语言重定向到路线。看看这些相关问题:
Multi-lingual websites with ASP.NET MVC
使用ASP.NET MVC的多语言网站
How should I implement localization with ASP.NET MVC routes?
我应该如何使用ASP.NET MVC路由实现本地化?
#2
4
Short answer: don't.
简答:不要。
URLs are supposed to be universal and thus locale-invariant. This is why we don't support localizing controllers, actions, or query string values during model binding.
URL应该是通用的,因此是区域不变的。这就是我们在模型绑定期间不支持本地化控制器,操作或查询字符串值的原因。
#3
3
Take a look at this simple solution:
看看这个简单的解决方案:
Translating routes (ASP.NET MVC and Webforms)
转换路由(ASP.NET MVC和Webforms)
You can also try the awesome AttributeRouting project that I just found! You can get it through NuGet.
您还可以尝试我刚刚找到的令人敬畏的AttributeRouting项目!你可以通过NuGet获得它。
#4
0
Take into account that you are not finished when you localized action and controller names. You would still need to localize any routing parameters. That's especially painfull for enums.
考虑到在本地化操作和控制器名称时未完成。您仍然需要本地化任何路由参数。这对于枚举来说尤其痛苦。
Ie www.seller.com/catalogue/list/winterclothing www.seller.com/catalogue/list/summerclothing where winterclothing
and summerclothing
would be enums.
即www.seller.com/catalogue/list/winterclothing www.seller.com/catalogue/list/summerclothing其中winterclothing和summerclothing将是枚举。
I would say: It's possible but not doable.
我会说:这可能但不可行。