Simon_Weaver
Simon_Weaver

Reputation: 146198

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

I'm trying to plan for future (months away) localization of a new ASP.NET MVC site.

Trying to decide what makes most sense to do, as far as constructing the URLs and routing.

For instance should I start off immediately with this :

 http://www.example.com/en/Products/1001
 http://www.example.com/es/Products/1001

or just

 http://www.example.com/Products/1001

and then add other languages later

 http://www.example.com/en/Products/1001

Thats my basic main issue right now, trying to get the routing correct. I want my URLs to be indexable by a search engine correctly. I'm not even sure if I want language in the URL but I dont think there is a good alternative that wouldn't confuse a search engine.

It leads to all kinds of other questions like 'shouldnt I localize the word products' but for right now I just want to get the routing in place before I launch the english site.

Upvotes: 3

Views: 3687

Answers (2)

Andrei Rînea
Andrei Rînea

Reputation: 20800

I would use a different URL scheme like so :

en.mysite.com (English)
mysite.com (default language)
ro.mysite.com (Romanian)

etc.

Then I would create a custom route like in this answer.

Upvotes: 1

Mathias F
Mathias F

Reputation: 15931

I have exactly the same URL_mapping like you. My route also uses a constraint. Works for me.

   routes.MapRoute(
            // Route name
            "LocalizedController", 
            // URL with parameters                                             
            "{language}/{controller}/{action}",
            // Parameter defaults
            new {
                controller = "Home", action = "Index", 
                language = "de"
            },
              //Parameter constraints
            new { language = @"de|en" }

Upvotes: 2

Related Questions