开发者

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

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 lo开发者_运维知识库oking for a way to do this. Any help would be welcome.

Is there any framework or lib implementing this already?


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?


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜