0

How can the URLs in an MVC application be localized.

So for example, I would have different URLs depending on the languate

  • EN: .../user/...
  • DE: .../Benutzer/...

I not only want this for nice URLs, but also generate my Breadcrumbs from this URLs, so this will genereate me something like:

  • EN: Home -> User -> ..
  • DE: Überischt -> Benutzer -> ....

I looked into the Routconfig, but didn't find any options for internationalization. Do I have to define a spezifice route for each internationalized URL?

Stefan
  • 14,826
  • 17
  • 80
  • 143

1 Answers1

1

As far as I know, there is no way to make localized URL that are convention-based beyond adding a localized variation for each route. Instead, you have to build a custom RouteBase that maps the URLs to route combinations based on the current culture. You can also make the reverse routes by overriding GetVirtualPath so that your ActionLink calls will build the correct URL according to the culture.

It works best to add the culture to the beginning of the URL, and use an initializer in the Application_BeginRequest event to set the culture based on the URL.

As for building breadcrumbs you could use MvcSiteMapProvider, which supports localization.

Full Disclosure: I am a major contributor of MvcSiteMapProvider.

NightOwl888
  • 55,572
  • 24
  • 139
  • 212