How to localize the Controller names and actions in an ASP.NET MVC application?

风流意气都作罢 提交于 2019-12-30 06:15:12

问题


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.

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.

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?


回答1:


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

How should I implement localization with ASP.NET MVC routes?




回答2:


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.




回答3:


Take a look at this simple solution:

Translating routes (ASP.NET MVC and Webforms)

You can also try the awesome AttributeRouting project that I just found! You can get it through NuGet.




回答4:


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.

I would say: It's possible but not doable.



来源:https://stackoverflow.com/questions/4271769/how-to-localize-the-controller-names-and-actions-in-an-asp-net-mvc-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!