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?

Venemo
  • 18,515
  • 13
  • 84
  • 125

4 Answers4

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

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

Community
  • 1
  • 1
Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
3

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.

Brad Wilson
  • 67,914
  • 9
  • 74
  • 83
  • 12
    Well URLs are definitely not locale-invariant. For English speakers theey may seem so but in regions in which speaking English is not so common, localizing URLs can be relevant. – Venemo Nov 24 '10 at 23:14
  • Just because you can do something, doesn't mean you should do something. Canonicalization and invariance in URLs are important principles not to be thrown away lightly. – Brad Wilson Nov 26 '10 at 04:55
  • 12
    Sorry Brad but I disagree, URLs are supposed to be resource locators, so If resource is in spanish you need one url and if the resource is in english you need another, those are invariant but in different languages. – Eugenio Miró May 24 '11 at 12:29
  • 1
    Adding another dimension to this problem, having the locale within a URL structure is important for SEO. – Andrew Craswell Jul 27 '16 at 18:35
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.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
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.

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

Venemo
  • 18,515
  • 13
  • 84
  • 125
Mathias F
  • 15,906
  • 22
  • 89
  • 159